From nobody Mon Dec 1 22:03:18 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4001B2FBE00; Thu, 27 Nov 2025 17:18:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764263941; cv=none; b=ov5W4VH/JrrQ2R5XirzfRrT+i7amuGFXT9SmzWj1aTMf5GGfx10b4MuMQyJ9yeMMDS5InNf+g9yDkTmmIEO/Z4SHwkNYi3tqd07xbFS/F5/xZerH7zxr5ofo4T1MMQjmYwySDTQ5ey+FcM+4RVZaKHLQIKi8W4JJ6SjFC4kxnxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764263941; c=relaxed/simple; bh=FPOPOiaHiMS1DGiB15UET9ZTvHI8/dOj06ra13vuyiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E1YD0/ctbJOOdqdYSWmNP+ZDdFEtwDFahAdHkkKZ+RLESkjZLTAL6NEeVzbKSMiRtJbRaUVWeXvTslRFNFSj7kXrRO6y6hrF366Q6XbdRCr+YZfxjE6vNXgjEoOJL1Ed2kNqUF3d90UJUDqhtjfhWlTmSqNjq3qz8zmGQMvMGfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Wc4CRNhs; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Wc4CRNhs" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id BFF104E41928; Thu, 27 Nov 2025 17:18:56 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 939A960722; Thu, 27 Nov 2025 17:18:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 6B515103C8C62; Thu, 27 Nov 2025 18:18:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764263935; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=246FoifQioiJlJKgK0l+PteqgHVK9qea+qwvqnjBY1s=; b=Wc4CRNhs1zrL9fO9ihV/ocVROYrlFooaTnRcFacBzzrYvF9z5/FLe4RM/8RJBK68jJA5fB xLU3XOgj1JsBefwhL7Z0Mo/04QRnqPxWV+A/4zGcjvvCc90JaSHNjY5zzxKauWaxuZ6qzZ IcRhaVFfFjLMqN7bOUe+7y7YTv7HQeB2554CiWLUVttORPTxTdTmhAJKNa4xAGY2wJnIbq y0/Eayx0xZs0kcwUgwzSSb3mr6TzXbW8Ifr8E3xy1WK9ckP1Hl+eAZWOgeT4HRcQzyTdj/ StGsAnMVgreHjx6GM8EN4zZpkfM6nBr+ndJ+4vMIM/x+iurvDeElHaahAeKTrw== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org, Antoine Tenart , devicetree@vger.kernel.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , Romain Gantois , Daniel Golle , Dimitri Fedrau , Tariq Toukan Subject: [PATCH net-next v20 11/14] net: phy: at803x: Support SFP through phy_port interface Date: Thu, 27 Nov 2025 18:17:54 +0100 Message-ID: <20251127171800.171330-12-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251127171800.171330-1-maxime.chevallier@bootlin.com> References: <20251127171800.171330-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" Convert the at803x driver to use the generic phylib SFP handling, via a dedicated .attach_port() callback, populating the supported interfaces. As these devices are limited to 1000BaseX, a workaround is used to also support, in a very limited way, copper modules. This is done by supporting SGMII but limiting it to 1G full duplex (in which case it's somewhat compatible with 1000BaseX). Reviewed-by: Christophe Leroy Reviewed-by: Andrew Lunn Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/qcom/at803x.c | 77 +++++++++++++++-------------------- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index 338acd11a9b6..2995b08bac96 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include =20 #include "qcom.h" @@ -769,57 +769,44 @@ static int at8031_register_regulators(struct phy_devi= ce *phydev) return 0; } =20 -static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int at803x_configure_mii(struct phy_port *port, bool enable, + phy_interface_t interface) { - __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support); - __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); - struct phy_device *phydev =3D upstream; - const struct sfp_module_caps *caps; - phy_interface_t iface; - - linkmode_zero(phy_support); - phylink_set(phy_support, 1000baseX_Full); - phylink_set(phy_support, 1000baseT_Full); - phylink_set(phy_support, Autoneg); - phylink_set(phy_support, Pause); - phylink_set(phy_support, Asym_Pause); - - caps =3D sfp_get_module_caps(phydev->sfp_bus); - /* Some modules support 10G modes as well as others we support. - * Mask out non-supported modes so the correct interface is picked. - */ - linkmode_and(sfp_support, phy_support, caps->link_modes); + struct phy_device *phydev =3D port_phydev(port); =20 - if (linkmode_empty(sfp_support)) { - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); - return -EINVAL; - } + if (interface =3D=3D PHY_INTERFACE_MODE_SGMII) + dev_warn(&phydev->mdio.dev, + "module may not function if 1000Base-X not supported\n"); + + return 0; +} =20 - iface =3D sfp_select_interface(phydev->sfp_bus, sfp_support); +static const struct phy_port_ops at803x_port_ops =3D { + .configure_mii =3D at803x_configure_mii, +}; =20 - /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes - * interface for use with SFP modules. - * However, some copper modules detected as having a preferred SGMII - * interface do default to and function in 1000Base-X mode, so just - * print a warning and allow such modules, as they may have some chance - * of working. +static int at8031_attach_mii_port(struct phy_device *phydev, + struct phy_port *port) +{ + linkmode_zero(port->supported); + phylink_set(port->supported, 1000baseX_Full); + phylink_set(port->supported, 1000baseT_Full); + phylink_set(port->supported, Autoneg); + phylink_set(port->supported, Pause); + phylink_set(port->supported, Asym_Pause); + + /* This device doesn't really support SGMII. However, do our best + * to be compatible with copper modules (that usually require SGMII), + * in a degraded mode as we only allow 1000BaseT Full */ - if (iface =3D=3D PHY_INTERFACE_MODE_SGMII) - dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not s= upported\n"); - else if (iface !=3D PHY_INTERFACE_MODE_1000BASEX) - return -EINVAL; + __set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + + port->ops =3D &at803x_port_ops; =20 return 0; } =20 -static const struct sfp_upstream_ops at8031_sfp_ops =3D { - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .module_insert =3D at8031_sfp_insert, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, -}; - static int at8031_parse_dt(struct phy_device *phydev) { struct device_node *node =3D phydev->mdio.dev.of_node; @@ -840,8 +827,7 @@ static int at8031_parse_dt(struct phy_device *phydev) return ret; } =20 - /* Only AR8031/8033 support 1000Base-X for SFP modules */ - return phy_sfp_probe(phydev, &at8031_sfp_ops); + return 0; } =20 static int at8031_probe(struct phy_device *phydev) @@ -1172,6 +1158,7 @@ static struct phy_driver at803x_driver[] =3D { .set_tunable =3D at803x_set_tunable, .cable_test_start =3D at8031_cable_test_start, .cable_test_get_status =3D at8031_cable_test_get_status, + .attach_mii_port =3D at8031_attach_mii_port, }, { /* Qualcomm Atheros AR8032 */ PHY_ID_MATCH_EXACT(ATH8032_PHY_ID), --=20 2.49.0