From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=66.163.186.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793748831; b=MDrzRuxrKoyQqK/DqIsN/c0z/v7vqKVwvo1XqKIW9N4p15IC7ni/NxpCCOfYygZMKy+Z bhFzz/cui6M57QUuWhg87PTCi5l08xvYHKQKodr3bcaIZ1h5+4A6MM9y3GeZ7BoMm6Mj5 2Vgt2CVUVS3zvjyv/bOWZ/Z0ZcdCC5aeZNoSIUHnHL65RsXY/ek+O5YzEN1u6jHhGuV8b TD8OT3+Bki/+GtnWnxujc0dH4Cs++uOF0aXz8KWZ36SB262gNW7a5y0sXYhgAqLpv9WbB 7qPdVeqktt1fAcNWTYW4/7JZvu/pgUcx2ANuR/S+7hLmnWdVNTNQlBj8LlN1VlsIXpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793748831; h=DMARC-Filter:DKIM-Signature:X-SONIC-DKIM-SIGN:X-YMail-OSG:X-Sonic-MF: X-Sonic-ID:Received:Received:Message-ID:Date:MIME-Version:User-Agent: Subject:From:To:References:Content-Language:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Mailer; bh=EZn6P0VEy9SzD8iEtL6y/0ZFMpPirpp/1IXBWVJmZ4s=; b=g2uiXADXWx83z9UmeaDl//FzGGxrm2I5HLiRN5vItiVLE0rEN+CHDwvsDn1bW+vHhETM HzneL/DFddrt0lWM4+4L0vvPeEqnsfvv5qwfTbuxkCW5+1r1GcUWLG/5/fCGFTDOpHEeK b28gyZg3nuJDxlKq3+82Kxx4/zTI/5IP8IrdJiUNAJNtBUo68Qo9n/kK4AHFgNeO8jpdd izmquHLGMqplaKcTglBZGggVQqtiyflP/Gsw2MEEUP1s+J2FclwDZIcwOCShOLZY15qeN Hwuuga6M8CNNOT+v6YkKgUANvPANwZzei3cDgYa+K30NTdL0FXKm7sZaqIJwaF/5qOQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=yahoo.com; spf=pass smtp.mailfrom=yahoo.com; dkim=pass header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=k3xmIy5N; arc=none smtp.remote-ip=66.163.186.148 Received: from sonic302-22.consmr.mail.ne1.yahoo.com (sonic302-22.consmr.mail.ne1.yahoo.com [66.163.186.148]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9DC0606A329 for ; Tue, 3 Nov 2026 23:33:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9DC0606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=k3xmIy5N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1793748830; bh=EZn6P0VEy9SzD8iEtL6y/0ZFMpPirpp/1IXBWVJmZ4s=; h=Date:Subject:From:To:References:In-Reply-To:From:Subject:Reply-To; b=k3xmIy5NffuDXIT++OiDoxej4okMjK4/AGExG3c90xvYA0C8vovg5HFjtKMj3FmO7lfBJCxarWfi5fsAO5sJZh/gmOmT6K+2mjA1U31q5/LlGsh71cyMPR8NgHnZyvdQGfKDsy71ytbXXttUakNRCYhB0PWX64hBIh9XP4XluSe7t3x5nw79L+yxTRO+JtpxBUTKWVPPAZLMPEZNKwDGLtAThHiewignadldoUGoAMNON2C3weFclC92lKaMKXJj+61ao6nTGFGG1YKRHZr0JX9q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FPBZNP.s.2CfD1d7 TO4ZC8FM7j6MI48L4CU85IKbDGCgVYfl8.UqNEwy9Gpf083wExU_uokw.KRI_D2aoSqdGuQzE2Ws gz3atc9SNmEs5x32WTsa5RQz7X9e6oSVvGooyOrMNsr7_xO3iBSEYB2oWJ3JjD4rXkXgacSACf80 NjPLxDgjOzwaaalgTUK6NL_vQbVzGLVFqZ7JU8s6lrUUqj3VjSQJb0wzH3KIt_ONOy0QlQsd_gDP tb4H3UHY7j67oht1StpXGTbysIEmgy5STPukxVuzQjqwrdqSaoY5H_KlI9yqb__00ZD8_g3TpG7H kZXhJY7e_byITZQ2vH7mz.VZH9X4zbmb6MIjoBcMedrEXzPpECdTqIlyFAeHacMMYsQj3LOCKEk3 X3baevHklGZwnnierLFdGCeqF1ntfvMPtgH2IXy9WtXrHPE8ix3r.6K5F1i25xcs6J9P10D8u8up Fn3IVL_LEq5EHEd3Ks6.5Fl4tslSaeTDMJmRFZ8O1.OhukIZnQ0ta4Nl.ECZ7qFpRLQLwZCOZ76q RS5uYMycsC0jim4jPfJqmUUQo4bqgL73ZI.rzoXuPUZ6NuOxmZwn3QJZoCROAk1VNRkLdryRaZMj _aNYaKYhhH5tf5iwesfp53isQJ3yCmFr.obP1.u0EMOeg6vqB92qCg2lbUFiXu3TEDqejhnEculD I36SdxEA9r4LkJ9Kyo9cq4rs8ECAN0HWB0mPj2yG0V8kB7ehcP0VQ0PHpTbG8IYLLX.xHnpZanbd rqNk_wZnoFwFWaJ3tj.E5Nvgxp4JhB27mkR6IxVWDHw-- X-Sonic-MF: X-Sonic-ID: 0742afe6-c5ec-44dd-b872-f045df127601 Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Tue, 3 Nov 2026 23:33:50 +0000 Received: by hermes--production-ir2-5dd9bf4598-bgsl4 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 3aaa438d0e0f20b020c29d94e43df68c; Tue, 03 Nov 2026 23:33:46 +0000 (UTC) Message-ID: <4f9b8e50-49ef-4f2f-b15e-099b2fdca082@yahoo.com> Date: Wed, 4 Nov 2026 00:33:43 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH net-next v8 07/11] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support From: Mieczyslaw Nalewaj To: linusw@kernel.org, andrew@lunn.ch, olteanv@gmail.com, kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, linux@armlinux.org.uk, luizluca@gmail.com, maxime.chevallier@bootlin.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <08611959-c555-46d9-8e7e-20b85d0c4056@yahoo.com> Content-Language: pl In-Reply-To: <08611959-c555-46d9-8e7e-20b85d0c4056@yahoo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.26871 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Extend the existing RTL8367S SGMII/HSGMII PCS implementation in this driver for family D switches, whose CPU SerDes is reached through the indexed SDS13 window and whose SDS_MISC fields differ from family C. The register sequence and tuning tables are derived from the GPL-licensed Realtek RTL8367D port API distributed in the Mercusys MR80X GPL release. Keep the existing family C path unchanged and select the new behavior from the driver's chip-family metadata, making the implementation reusable by other family D boards. This patch only prepares the family D paths; they become reachable when the RTL8367S-VB chip entry is added in the last patch. Co-developed-by: Fabiano Tassotti Signed-off-by: Fabiano Tassotti Signed-off-by: Mieczyslaw Nalewaj Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl8365mb_main.c | 242 +++++++++++++++++------ 1 file changed, 187 insertions(+), 55 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index de8f5a0..50a3a92 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -262,7 +262,8 @@ * interface, indexed by the external port number with port 5 (the first * external port) as the base. Other RTL8367 families index this register * differently (e.g. the RTL8367R uses (id + 1) % 2), so this mapping only - * holds for the RTL8367C-style parts this driver supports. + * holds for the RTL8367C-style parts and for family D, where it is the same + * (one bit per external port, base port 5), as in the vendor RTL8367D API. */ #define RTL8365MB_BYPASS_LINE_RATE_REG 0x03F7 #define RTL8365MB_BYPASS_LINE_RATE_MASK(_port) BIT((_port) - 5) @@ -284,6 +285,7 @@ #define RTL8365MB_SDS_INDACS_CMD_BUSY_MASK BIT(8) #define RTL8365MB_SDS_INDACS_CMD_RUN_MASK BIT(7) #define RTL8365MB_SDS_INDACS_CMD_WR_MASK BIT(6) +#define RTL8365MB_SDS_INDACS_CMD_INDEX_MASK GENMASK(5, 0) #define RTL8365MB_SDS_INDACS_ADR_REG 0x6601 #define RTL8365MB_SDS_INDACS_DATA_REG 0x6602 @@ -313,8 +315,10 @@ #define RTL8365MB_SDS_REG_LINK_STATUS 0x003d #define RTL8365MB_SDS_LINK_STATUS_LINK_MASK BIT(4) -/* The embedded SerDes can only be muxed to external interface 1 (MAC8), - * which is port 6. +/* On family C the embedded SerDes can only be muxed to external interface + * 1 (MAC8), which is port 6. Family D has it on external interface 0 + * (MAC6), see RTL8365MB_D_SDS_EXT0_INDEX. RTL8365MB_SDS_EXT_INTERFACE_ID + * below is the family C id; the SerDes port is 6 on both families. */ #define RTL8365MB_SDS_EXT_INTERFACE_ID 1 #define RTL8365MB_SDS_EXT_INTERFACE_PORT 6 @@ -332,7 +336,22 @@ #define RTL8365MB_SDS_OPTION_ARM_KEY 0x0249 #define RTL8365MB_SDS_OPTION_REG 0x13C1 +/* Family D uses the SDS13 indirect window for its MAC6 SerDes. */ +#define RTL8365MB_D_SDS_EXT0_INDEX 13 +#define RTL8365MB_D_FIBER_CFG2_REG 0x13E8 +#define RTL8365MB_D_FIBER_CFG2_RX_DISABLE_MASK GENMASK(7, 6) +#define RTL8365MB_D_FIBER_CFG2_RX_DISABLE_SDS0 BIT(6) +#define RTL8365MB_D_SDS_MISC_PA33PC_EN BIT(11) +#define RTL8365MB_D_SDS_MISC_PA12PC_EN BIT(10) +#define RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0 BIT(9) #define RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK GENMASK(4, 0) +#define RTL8365MB_D_SDS_MISC_MODE_SGMII 0x02 +#define RTL8365MB_D_SDS_MISC_MODE_HSGMII 0x12 +#define RTL8365MB_D_SDS_MISC_CFG_MASK \ + (RTL8365MB_D_SDS_MISC_PA33PC_EN | \ + RTL8365MB_D_SDS_MISC_PA12PC_EN | \ + RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0 | \ + RTL8365MB_D_SDS_MISC_MODE_FIELD_MASK) /* Shared "disable" encoding for both SDS_MISC's and SDS1_MISC0's * 5-bit mode fields. */ @@ -720,6 +739,21 @@ static const struct rtl8365mb_jam_tbl_entry rtl8365mb_sds_jam_hsgmii[] = { { 0x0424, 0xD810 }, { 0x0001, 0x0F80 }, { 0x002E, 0x83F2 }, }; +/* Family D tuning tables from the Realtek vendor port API. */ +static const struct rtl8365mb_jam_tbl_entry rtl8365mb_d_sds_jam_sgmii[] = { + { 0x0427, 0x4E0C }, { 0x0428, 0xAA00 }, { 0x0425, 0x5189 }, + { 0x0424, 0x8414 }, { 0x0423, 0x1020 }, { 0x0410, 0x0002 }, + { 0x0484, 0x011B }, { 0x0421, 0x8E13 }, { 0x0422, 0x1140 }, + { 0x0004, 0x074F }, +}; + +static const struct rtl8365mb_jam_tbl_entry rtl8365mb_d_sds_jam_hsgmii[] = { + { 0x0427, 0x4E0C }, { 0x0428, 0xAA00 }, { 0x0425, 0x5189 }, + { 0x0424, 0x8414 }, { 0x0423, 0x1020 }, { 0x0410, 0x0002 }, + { 0x0504, 0x051B }, { 0x0421, 0x8E13 }, { 0x0422, 0x1140 }, + { 0x0004, 0x074F }, +}; + enum rtl8365mb_phy_interface_mode { RTL8365MB_PHY_INTERFACE_MODE_INVAL = 0, RTL8365MB_PHY_INTERFACE_MODE_INTERNAL = BIT(0), @@ -1319,7 +1353,8 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port, return 0; } -static int rtl8365mb_sds_write(struct realtek_priv *priv, u16 addr, u16 data) +static int rtl8365mb_sds_write(struct realtek_priv *priv, u8 index, + u16 addr, u16 data) { int ret; @@ -1337,10 +1372,13 @@ static int rtl8365mb_sds_write(struct realtek_priv *priv, u16 addr, u16 data) */ return regmap_write(priv->map, RTL8365MB_SDS_INDACS_CMD_REG, RTL8365MB_SDS_INDACS_CMD_RUN_MASK | - RTL8365MB_SDS_INDACS_CMD_WR_MASK); + RTL8365MB_SDS_INDACS_CMD_WR_MASK | + FIELD_PREP(RTL8365MB_SDS_INDACS_CMD_INDEX_MASK, + index)); } -static int rtl8365mb_sds_read(struct realtek_priv *priv, u16 addr, u16 *data) +static int rtl8365mb_sds_read(struct realtek_priv *priv, u8 index, + u16 addr, u16 *data) { u32 val; int ret; @@ -1350,7 +1388,9 @@ static int rtl8365mb_sds_read(struct realtek_priv *priv, u16 addr, u16 *data) return ret; ret = regmap_write(priv->map, RTL8365MB_SDS_INDACS_CMD_REG, - RTL8365MB_SDS_INDACS_CMD_RUN_MASK); + RTL8365MB_SDS_INDACS_CMD_RUN_MASK | + FIELD_PREP(RTL8365MB_SDS_INDACS_CMD_INDEX_MASK, + index)); if (ret) return ret; @@ -1390,6 +1430,14 @@ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv) int ret; int i; + /* Family D has a fixed SDS13 programming model and does not use the + * family C option register to select its tuning table. + */ + if (rtl8365mb_is_d(priv)) { + mb->sds_supported = true; + return 0; + } + /* Nothing to probe if no external interface is wired to the SerDes */ for (i = 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) { extint = &mb->chip_info->extints[i]; @@ -1471,25 +1519,44 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, const struct rtl8365mb_jam_tbl_entry *sds_jam; const int id = RTL8365MB_SDS_EXT_INTERFACE_ID; struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs); - struct realtek_priv *priv; + struct realtek_priv *priv = mb->priv; size_t sds_jam_size; - u32 mode; + u32 misc_mask; + u32 misc_val; + u32 sds_mode; + u8 sds_index; + bool is_d; u16 val; int ret; int i; - priv = mb->priv; + is_d = rtl8365mb_is_d(priv); + /* Select the appropriate tuning table and SDS mode */ if (interface == PHY_INTERFACE_MODE_2500BASEX) { - sds_jam = rtl8365mb_sds_jam_hsgmii; - sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_hsgmii); - mode = RTL8365MB_EXT_PORT_MODE_HSGMII; + if (is_d) { + sds_jam = rtl8365mb_d_sds_jam_hsgmii; + sds_jam_size = ARRAY_SIZE(rtl8365mb_d_sds_jam_hsgmii); + sds_mode = RTL8365MB_D_SDS_MISC_MODE_HSGMII; + } else { + sds_jam = rtl8365mb_sds_jam_hsgmii; + sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_hsgmii); + sds_mode = RTL8365MB_EXT_PORT_MODE_HSGMII; + } } else { - sds_jam = rtl8365mb_sds_jam_sgmii; - sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_sgmii); - mode = RTL8365MB_EXT_PORT_MODE_SGMII; + if (is_d) { + sds_jam = rtl8365mb_d_sds_jam_sgmii; + sds_jam_size = ARRAY_SIZE(rtl8365mb_d_sds_jam_sgmii); + sds_mode = RTL8365MB_D_SDS_MISC_MODE_SGMII; + } else { + sds_jam = rtl8365mb_sds_jam_sgmii; + sds_jam_size = ARRAY_SIZE(rtl8365mb_sds_jam_sgmii); + sds_mode = RTL8365MB_EXT_PORT_MODE_SGMII; + } } + sds_index = is_d ? RTL8365MB_D_SDS_EXT0_INDEX : 0; + /* Hold the embedded DW8051 microcontroller in reset and keep it * disabled. The vendor driver loads firmware into it to manage the * SerDes link, but the firmware only duplicates work that phylink @@ -1518,34 +1585,57 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, /* Tune the SerDes with vendor-prescribed parameters */ for (i = 0; i < sds_jam_size; i++) { - ret = rtl8365mb_sds_write(priv, sds_jam[i].reg, - sds_jam[i].val); + ret = rtl8365mb_sds_write(priv, sds_index, + sds_jam[i].reg, sds_jam[i].val); if (ret) return ret; } - /* Mux the SerDes to MAC8 in the requested mode */ + /* Family-specific post-tuning configuration */ + if (is_d) { + /* Bit 6 disables the RX of SDS0. As in the vendor RTL8367D + * sequence the whole 2-bit field (bits 7:6) is written, so + * bit 7 is cleared as well. + */ + ret = regmap_update_bits(priv->map, RTL8365MB_D_FIBER_CFG2_REG, + RTL8365MB_D_FIBER_CFG2_RX_DISABLE_MASK, + RTL8365MB_D_FIBER_CFG2_RX_DISABLE_SDS0); + if (ret) + return ret; + + misc_mask = RTL8365MB_D_SDS_MISC_CFG_MASK; + misc_val = RTL8365MB_D_SDS_MISC_PA33PC_EN | + RTL8365MB_D_SDS_MISC_PA12PC_EN | + RTL8365MB_D_SDS_MISC_MAC6_SEL_SDS0 | sds_mode; + } else { + /* Mux the SerDes to MAC8 in the requested mode */ + misc_mask = RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK | + RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK; + misc_val = (sds_mode == RTL8365MB_EXT_PORT_MODE_SGMII) ? + RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK : + RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK; + } + ret = regmap_update_bits(priv->map, RTL8365MB_SDS_MISC_REG, - RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK | - RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK, - mode == RTL8365MB_EXT_PORT_MODE_SGMII ? - RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK : - RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK); + misc_mask, misc_val); if (ret) return ret; - val = mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id); - ret = regmap_update_bits(priv->map, - RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id), - RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id), - val); - if (ret) - return ret; + if (!is_d) { + val = sds_mode << RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(id); + ret = regmap_update_bits(priv->map, + RTL8365MB_DIGITAL_INTERFACE_SELECT_REG(id), + RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(id), + val); + if (ret) + return ret; + } /* Take the SerDes out of reset. The vendor driver does this only * after the SerDes mux and the interface mode are configured. */ - ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_RESET, + ret = rtl8365mb_sds_write(priv, sds_index, + RTL8365MB_SDS_REG_RESET, RTL8365MB_SDS_RESET_DEASSERT); if (ret) return ret; @@ -1555,27 +1645,32 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, * This flushes the FIFOs and ensures a clean state for the link, * preventing silent drops and CRC errors. */ - ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_BMCR, + ret = rtl8365mb_sds_write(priv, sds_index, + RTL8365MB_SDS_REG_BMCR, RTL8365MB_SDS_BMCR_DPRST_PHASE1); if (ret) return ret; - ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_BMCR, + ret = rtl8365mb_sds_write(priv, sds_index, + RTL8365MB_SDS_REG_BMCR, RTL8365MB_SDS_BMCR_DPRST_PHASE2); if (ret) return ret; /* Keep SGMII in-band autonegotiation disabled: the link parameters are - * forced from rtl8365mb_pcs_link_up() instead. + * forced from rtl8365mb_pcs_link_up() instead (family C), or from + * mac_link_up() (family D). */ - ret = rtl8365mb_sds_read(priv, RTL8365MB_SDS_REG_NWAY, &val); + ret = rtl8365mb_sds_read(priv, sds_index, + RTL8365MB_SDS_REG_NWAY, &val); if (ret) return ret; val &= ~RTL8365MB_SDS_NWAY_EN_MASK; val |= RTL8365MB_SDS_NWAY_RESTART_MASK; - return rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_NWAY, val); + return rtl8365mb_sds_write(priv, sds_index, + RTL8365MB_SDS_REG_NWAY, val); } static bool rtl8365mb_interface_is_serdes(phy_interface_t interface) @@ -1600,18 +1695,27 @@ static void rtl8365mb_pcs_get_state(struct phylink_pcs *pcs, { struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs); struct realtek_priv *priv = mb->priv; + u8 sds_index = 0; u16 status; + bool is_d; u32 val; int ret; - /* In-band autonegotiation is not implemented, so the link parameters are - * forced from rtl8365mb_pcs_link_up(). The real link state must still be - * read from the SerDes itself: the embedded DW8051 microcontroller that + is_d = rtl8365mb_is_d(priv); + + /* In-band autonegotiation is not implemented, so the link parameters + * are forced from rtl8365mb_pcs_link_up() on family C, and from + * mac_link_up() on family D. The real link state must still be read + * from the SerDes itself: the embedded DW8051 microcontroller that * the vendor firmware uses to poll the SerDes is kept disabled (see * rtl8365mb_pcs_config()), so the link status register can be read * directly through the SDS_INDACS window without racing the auto-poll. */ - ret = rtl8365mb_sds_read(priv, RTL8365MB_SDS_REG_LINK_STATUS, &status); + if (is_d) + sds_index = RTL8365MB_D_SDS_EXT0_INDEX; + + ret = rtl8365mb_sds_read(priv, sds_index, + RTL8365MB_SDS_REG_LINK_STATUS, &status); if (ret) { state->link = false; return; @@ -1622,6 +1726,23 @@ static void rtl8365mb_pcs_get_state(struct phylink_pcs *pcs, if (!state->link) return; + if (is_d) { + if (state->interface == PHY_INTERFACE_MODE_2500BASEX) { + state->duplex = DUPLEX_FULL; + state->speed = SPEED_2500; + } else { + /* Keep what phylink passed in, but never report the + * link up with an unknown speed: mac_link_up() cannot + * force the port with it. + */ + if (state->speed == SPEED_UNKNOWN) + state->speed = SPEED_1000; + if (state->duplex == DUPLEX_UNKNOWN) + state->duplex = DUPLEX_FULL; + } + return; + } + /* The speed and duplex are forced; read them back from the values * programmed into the SerDes MISC register. */ @@ -1663,6 +1784,12 @@ static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs, u32 r_speed; int ret; + /* Family D forces the external MAC ability from mac_link_up(); its + * SDS_MISC fields do not share the family C link-force layout. + */ + if (rtl8365mb_is_d(priv)) + return; + /* The speed field has no value for 2.5 Gbps: the rate is determined by * the HSGMII SerDes configuration, and the vendor driver programs the * 1 Gbps value here. @@ -1952,7 +2079,7 @@ static void rtl8365mb_phylink_mac_link_down(struct phylink_config *config, /* phylink has no pcs_link_down callback, so on the SerDes path only the * MAC external interface force is reset here. Clearing the MAC force is * enough to bring the link down; the SerDes keeps presenting its last - * forced state until the next pcs_link_up() reprograms it. + * forced state (family C) until the next pcs_link_up() reprograms it. */ if (phy_interface_mode_is_rgmii(interface) || rtl8365mb_interface_is_serdes(interface)) { @@ -1985,9 +2112,11 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config, p = &mb->ports[port]; schedule_delayed_work(&p->mib_work, 0); - /* The SerDes forced link state is programmed by the PCS in + /* On family C the SerDes forced link state is programmed by the PCS in * rtl8365mb_pcs_link_up(); here only the MAC external interface force - * is configured, for both RGMII and SerDes. + * is configured. On family D pcs_link_up() does nothing, and the MAC + * external interface force is the only forced link state, for both + * RGMII and SerDes. */ if (phy_interface_mode_is_rgmii(interface) || rtl8365mb_interface_is_serdes(interface)) { @@ -2001,18 +2130,21 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config, return; } - /* The SerDes has its own pause enables; program them from - * the resolved pause modes, as the vendor driver does when - * forcing the link on a SerDes external interface. These - * bits, not the MAC force pause bits, gate pause on the - * SerDes external interface: flow control testing shows - * that pause frames are only emitted with the SerDes TXFC - * bit set, while the MAC force pause bits alone have no - * effect on this port. This is done here rather than in - * rtl8365mb_pcs_link_up() because pcs_link_up() carries no - * pause information. + /* Family C: the SerDes has its own pause enables; program + * them from the resolved pause modes, as the vendor driver + * does when forcing the link on a SerDes external + * interface. These bits, not the MAC force pause bits, gate + * pause on the SerDes external interface: flow control + * testing shows that pause frames are only emitted with the + * SerDes TXFC bit set, while the MAC force pause bits alone + * have no effect on this port. This is done here rather + * than in rtl8365mb_pcs_link_up() because pcs_link_up() + * carries no pause information. Family D does not use this + * path: its pause bits are set in the forced-mode register + * by rtl8365mb_ext_config_forcemode(). */ - if (rtl8365mb_interface_is_serdes(interface)) { + if (rtl8365mb_interface_is_serdes(interface) && + !rtl8365mb_is_d(priv)) { u32 val = 0; if (tx_pause) -- 2.53.0