From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=66.163.190.32 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795965088; b=2qFVDaU5gXdygmL3ZGq449ha2FUoZqfn8lXxhWLoA6bZZgMU9L8aSTFZGJxPqEgBr16+ tlltNOwg4+GoXo4O3+p/Ior/px/+zzTzdzavWjqe/hpJQltQew8jXH7XGl9y/iYMG6pUr wPmK2aOFi4o1p2D2F0JGuD5j9Lte5nrUgUidaqwwNbWwbryV7IknlOiqcGRSc6H981OJ6 O+6lRk80rQPmQN/dB3C3Ikv+Q6VaGtiZDeLML1+boBPQXBmebHsIAm/mw1jAYKOrE3w4h BFrqd2wiXAMdk/45mgIe9skazvZdQTrxxdseJbq8MgCepDamH/rTTMxEeuGHwsDrTkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795965088; 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:To:References:Content-Language:In-Reply-To:From:Content-Type: Content-Transfer-Encoding:X-Mailer; bh=sUVPesAUE/0eiueLXsN2A7h+Wddm/W+aq0cdoGz7ERU=; b=MDp/vjD4eCbEkWaAVKN6fU8yfZjQ6Z5NLWzl5/Hk7Y25+TE+oDBsHg7niLiew5H21HqN RH9ZDcGIu4N+eu1tvvscHR7rDhfngde10gSMKHB5aZfKFx+eJVyYlYyaAHHyVX1bG2jg/ /D1yqy64L0qjExR1vjJn/0LvWgt+DkN4AOTBvoFXSFd0lkiphgiXS4ZvRsklnk6xk8A0L QY7B6+n279b9uOo4ZtYIrTso4nbZffUDYCYssqMNmHrNvcZh5prZvCGqiefe8n6J5pCkA 3Wjfc9UC5cDVGefigMWuY1ULKRvX5u17kQea59lTYJKmYqvdT7ZzPnK6W+IqpdGBkFA== 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=T3aS8or6; arc=none smtp.remote-ip=66.163.190.32 Received: from sonic307-9.consmr.mail.ne1.yahoo.com (sonic307-9.consmr.mail.ne1.yahoo.com [66.163.190.32]) (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 3E86F606A329 for ; Sun, 29 Nov 2026 15:11:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3E86F606A329 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) header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=T3aS8or6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1795965085; bh=sUVPesAUE/0eiueLXsN2A7h+Wddm/W+aq0cdoGz7ERU=; h=Date:Subject:To:References:In-Reply-To:From:Content-Type:From:Subject:Reply-To:Content-Type; b=T3aS8or6vYQZU9mKoBGCeCi7IjZTK57dhzPoctXtd/5eB0rEz65XZE/ORhqUNxA6aUWfrhH7GDJL+yE/rjLPwqhPYO1LrET5Hit1EynehBXdqHLUd4hyIvXdokvrgP8mWok1zLtyrd6QBKTFEWgos1/is8CaPdD8viYWZwu25OevCyM6tgYq4T4qMUd7vFkeOTUQey3STNNGO3mSgzHZVaHBZpIc1r9XuSA91LaA9YHFvM+MeSzC/8+L7k36ACrfkHfkkl+OgiRWdfCdl6Ty1+3H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EzyfwTV8 .rTFlLlJdOEHOaUd_7pEbyHrj4LUEcvJK7QwNsH1ZRajSW1Pf2zh.EJcZdAyH5bFxCYfQYdMzwEV oZtYfcnPJGyxz3f1RjtpwNi4Zy8exT5jfcRlTtDLEgi5O2U6aozucm0J9kD1GvWMiBS1.PF4eayU KBqZy3xI4cJ9LWLPz1_rYqN4XholfDoBBzFLLDRdftfJ4TOJOp1IUyCXhlUH94.ynwHSHOu.dDSa XIz3mniAfUpknjiq8mr3nArCi8VEqUCxQnCptFphH_fagbgpwjmuB0xtP5T0R5CpD6u4SxdYRf7y OyXNJI_SbHNBf7onDwBlIPguaiEB6L2E.UB5aNjYkBcuiLGARvMhfuwfiAAgULFLF56j_C260BRG dOQY2l5NG7XW_.9mO35eoJgh0aWhmbuj2f_CFFCzwVwqxShpBdgeEQGgaUSH2bzhx.3SiX5SaVMl mC0DIxQC8k_9pgLIxZvE7pSrNxpp7GObXlYflhdkPd8Jv8VeBMCgY8JOPD8zOU4r.r7t0uIvR3r_ AbEFJgI3JHmZxJIgUU_Ey0TElHFAylt1.y_YTlCZlimIPxl8O_DyiUmmcpeHo2v7Qdk8TfZtlOJO bJJF2BnPPseAiL6WR6Xb_HjbX3.Cbti.MsYIYZN0kAGgjStkFhpr9T.iuPlk2Lqr3LV7QeQllvtZ Nd9LuQ6GuCnHuJ7VyLPzqH0KPBwTO_ygpEyLNDsv1Z3qwyA04EbK3AINq19qQj43mqVPes4YJ4Ah FsWK15lyw9pwXiWp8.17G_EjyRonGI1Xv76AfDGEg2nsMeVjY X-Sonic-MF: X-Sonic-ID: 8457704f-1365-4ea1-8e25-1c4daab1c338 Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Sun, 29 Nov 2026 15:11:25 +0000 Received: by hermes--production-ir2-7c4859dc89-hgxcv (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID a928ef0114c5ae412fc7a2d492df5ad6; Sun, 29 Nov 2026 15:11:23 +0000 (UTC) Message-ID: Date: Sun, 29 Nov 2026 16:11:20 +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 v16 10/15] net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support 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, alvin.sipraga@analog.com, gusfmora@gmail.com, kuncy7@gmail.com, fabianotassotti@gmail.com, gabonpivovich@gmail.com, contact@c127.dev, o.rempel@pengutronix.de References: Content-Language: pl In-Reply-To: From: Mieczyslaw Nalewaj Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.27100 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. The SerDes line rate bypass register (RTL8365MB_BYPASS_LINE_RATE_REG, 0x03f7) is laid out the same way in the RTL8367D port API as for family C: one bit per port, with bit 0 being port 5 (the RTL8367D_BYPASS_PORTn_CONSTRAINT_* definitions cover ports 5 to 7). The existing mask for port 6 therefore applies to family D as well. This patch only prepares the family D paths; they become reachable when the RTL8367S-VB chip entry is added in the last patch. On family D rtl8365mb_sds_probe_option() does not read the family C option register. It sets sds_supported only when the chip metadata describes an SGMII or HSGMII external interface, so family D chips without a SerDes do not get the port 6 rate-limit setup. The only family D chip in this series, the RTL8367S-VB, has a SerDes interface on port 6. Its port 6 rate-limiter register addresses and field masks have been verified against the vendor RTL8367D API and match family C. Nothing on family D programs a SerDes rate for 10 and 100 Mbit/s: pcs_link_up() does nothing and the MAC force register only sets the MAC side. It is not known whether the SerDes follows that register, and only 1G SGMII and 2500base-x were tested, so do not advertise 10 and 100 Mbit/s on the SerDes port of family D. On family D only the MAC force register carries the pause bits; on family C the SerDes TXFC bit is what gates pause frames. Flow control on the family D SerDes port has not been tested. Tested-by: Gustavo Foletto Mora Co-developed-by: Fabiano Tassotti Signed-off-by: Fabiano Tassotti Signed-off-by: Mieczyslaw Nalewaj --- drivers/net/dsa/realtek/rtl8365mb_main.c | 295 ++++++++++++++++++----- 1 file changed, 228 insertions(+), 67 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c index 7500ea9..59901e6 100644 --- a/drivers/net/dsa/realtek/rtl8365mb_main.c +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c @@ -264,7 +264,10 @@ * 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 port, bit 0 being port 5), as in the vendor RTL8367D API. + * Port 5 is not an external port on the RTL8367S-VB, whose external ports + * are 6 and 7. */ #define RTL8365MB_BYPASS_LINE_RATE_REG 0x03F7 #define RTL8365MB_BYPASS_LINE_RATE_MASK(_port) BIT((_port) - 5) @@ -286,6 +289,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 @@ -315,8 +319,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 @@ -334,7 +340,25 @@ #define RTL8365MB_SDS_OPTION_ARM_KEY 0x0249 #define RTL8365MB_SDS_OPTION_REG 0x13C1 +/* Family D uses the SDS13 indirect window for its MAC6 SerDes. + * RTL8365MB_SDS_MISC_REG is at the same register address as on family C + * in the vendor RTL8367D API, with the bit layout below. + */ +#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. */ @@ -728,6 +752,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), @@ -940,8 +979,10 @@ struct rtl8365mb_port { * @mib_lock: prevent concurrent reads of MIB counters * @ports: per-port data * @pcs: PCS for the SerDes external interface - * @sds_supported: SerDes tuning parameters match the chip option, so the - * SerDes interface modes can be advertised + * @sds_supported: SerDes interface modes can be advertised: the tuning + * parameters match the chip option (family C), or the chip + * is family D, which does not use the option but must + * describe an SGMII or HSGMII external interface * * Private data for this driver. */ @@ -1376,7 +1417,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; @@ -1394,10 +1436,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; @@ -1407,7 +1452,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; @@ -1430,14 +1477,17 @@ static int rtl8365mb_sds_read(struct realtek_priv *priv, u16 addr, u16 *data) return 0; } -/* The vendor driver selects between two sets of SerDes tuning parameters based - * on the chip option register. Only the variant for a non-zero option has been - * tested on real hardware - the RTL8367S parts seen so far all report 1. The - * variant for option 0 uses different tuning values that cannot be verified, - * so probe the option once at setup and only advertise the SerDes interface - * modes when the tuning parameters are known to match, so that an unsupported - * variant fails at phylink validation time rather than when configuring the - * link. +/* Determine whether the SerDes interface modes can be safely advertised. + * Family D chips use a fixed SDS13 programming model and unconditionally + * support SerDes modes whenever an external SerDes interface is present in + * the chip metadata. For family C chips, the vendor driver selects between two + * sets of SerDes tuning parameters based on the chip option register. Only the + * variant for a non-zero option has been tested on real hardware - the + * RTL8367S parts seen so far all report 1. The variant for option 0 uses + * different tuning values that cannot be verified, so probe the option once at + * setup and only advertise the SerDes interface modes when the tuning parameters + * are known to match, so that an unsupported variant fails at phylink + * validation time rather than when configuring the link. */ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv) { @@ -1447,6 +1497,20 @@ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv) int ret; int i; + /* Family D uses a fixed SDS13 model; check metadata only */ + if (rtl8365mb_is_d(priv)) { + for (i = 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) { + extint = &mb->chip_info->extints[i]; + if (extint->supported_interfaces & + (RTL8365MB_PHY_INTERFACE_MODE_SGMII | + RTL8365MB_PHY_INTERFACE_MODE_HSGMII)) { + mb->sds_supported = true; + break; + } + } + 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]; @@ -1492,7 +1556,8 @@ static int rtl8365mb_sds_probe_option(struct realtek_priv *priv) * the cap has been observed on hardware. Raise them likewise, to 0x7FFFF * (~4.19 Gbps, above the HSGMII line rate). The related HSGMII scheduler * line rate register (LINE_RATE_HSG_H, 0x03FA) is already set to its - * maximum by the family C init jam table. + * maximum by the family C init jam table; family D has no init jam table + * and leaves 0x03FA at its reset default, matching the vendor RTL8367D API. */ static int rtl8365mb_sds_raise_rate_limits(struct realtek_priv *priv) { @@ -1528,31 +1593,54 @@ 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 * already does: it polls the port status and forces the external * interface configuration in the very registers this driver manages. * Letting it run would race with phylink. + * + * The CHIP_RESET (bit 4) and MISC_CFG0 (bit 5) bit definitions + * for the DW8051 reset and enable controls are identical on both + * family C and family D switches in the vendor SDK. */ ret = regmap_update_bits(priv->map, RTL8365MB_CHIP_RESET_REG, RTL8365MB_CHIP_RESET_DW8051_MASK, @@ -1575,34 +1663,58 @@ 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; + } + + /* Family-specific post-tuning configuration */ + if (is_d) { + /* The register and field names follow the vendor RTL8367D API, + * whose SDS numbering differs from the SDS13 window used + * here. As in the vendor 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; } - /* Mux the SerDes to MAC8 in the requested mode */ 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; @@ -1612,27 +1724,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) @@ -1657,18 +1774,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; @@ -1679,6 +1805,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. */ @@ -1720,6 +1863,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. @@ -1982,10 +2131,17 @@ static void rtl8365mb_phylink_get_caps(struct dsa_switch *ds, int port, } if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_SGMII && - mb->sds_supported) + mb->sds_supported) { __set_bit(PHY_INTERFACE_MODE_SGMII, config->supported_interfaces); + /* The SerDes rate is not programmed for 10 and 100 Mbit/s on + * family D, see rtl8365mb_pcs_link_up(). + */ + if (rtl8365mb_is_d(priv)) + config->mac_capabilities &= ~(MAC_10 | MAC_100); + } + if (extint->supported_interfaces & RTL8365MB_PHY_INTERFACE_MODE_HSGMII && mb->sds_supported) { __set_bit(PHY_INTERFACE_MODE_2500BASEX, @@ -2064,7 +2220,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)) { @@ -2099,9 +2255,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)) { @@ -2114,18 +2272,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_d_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