From nobody Thu Oct 2 07:46:34 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 4C11422F14C; Sun, 21 Sep 2025 16:07:52 +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=1758470874; cv=none; b=gkX8NkSPP2u54eqQLVRUefzq0auryZU09teLMKybcr/ySkebu/yHaPhMeXbJ7fgkVxLgOYCMGn7zc22MmQHwEdVktzAAKvvET/TJvLLVmFkGydFOYpOt3T2wvXrhwMJ+1Zik4Q+NIbsuf8O8EZgx/1BObOy2CyOp7d0ZliRGp2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758470874; c=relaxed/simple; bh=sEpSbQniW/s68Ht5AoCfGpJxcvs+8vZCpHrEW7NdNHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O/va9wpkvpeSlVtdhI14edOgwOvDxTa3QHagd4Sq8bs8nuqSPSm/1zjhlL7rIjz3Pb0vrsQdcTfi0j7IMbFFcY8VEzcBME/KbudaJ7UsCIHFqm9qVAfHg8TV5l6BDaxjpE99JTDhkNLhyNy4rOMgwERmVWnRRwXs+Y7MeqIJwfg= 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=KrWPYhIl; 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="KrWPYhIl" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 0DC944E40DA7; Sun, 21 Sep 2025 16:07:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D5E8F60634; Sun, 21 Sep 2025 16:07:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7718B102F17C4; Sun, 21 Sep 2025 18:07:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758470869; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=aCdaROwrKYW1ezIMIwki4DvnBp+nLnucaAuvytpMjJo=; b=KrWPYhIlXo92xySVTnFacEaKuMAa2W7qpkuNVOlo16oTr7E57DUqxeLtUKPAzrd9ULP4/B shGUGdhibdT+7imFuex/Mz1KBloXBNG+EdgbXPK93pZEsFXdK1yHXi6CwKgdyaa0fK/O8N jqAC7shm7vlxfCWDMJuSMeAl1hjCpMsqkLNexEb/Bmj5epB7IFtjWtkly7VZ/+NHZZDNlt XXCV5rUmeF8+GWut9lLin//UOtgdmX9yYF/oUu85zYzF/t6f8g98oSZGvJQfOVgKgjiiJU AlgeBCth+tRv0WzmjcUfAp6vApJSNGTzyDcDsM6V67pmiKiGv5Pg82C4+1he7Q== 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 , Florian Fainelli Subject: [PATCH net-next v13 13/18] net: phy: marvell10g: Support SFP through phy_port Date: Sun, 21 Sep 2025 21:34:11 +0530 Message-ID: <20250921160419.333427-14-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250921160419.333427-1-maxime.chevallier@bootlin.com> References: <20250921160419.333427-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 Marvell10G driver to use the generic SFP handling, through a dedicated .attach_port() handler to populate the port's supported interfaces. As the 88x3310 supports multiple MDI, the .attach_port() logic handles both SFP attach with 10GBaseR support, and support for the "regular" port that usually is a BaseT port. Reviewed-by: Christophe Leroy Tested-by: Oleksij Rempel Tested-by: Florian Fainelli Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell10g.c | 54 ++++++++++++++++++++++-------------- drivers/net/phy/phy_port.c | 44 +++++++++++++++++++++++++++++ include/linux/phy_port.h | 1 + 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 13e81dff42c1..833ea0c0dc22 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include =20 #define MV_PHY_ALASKA_NBT_QUIRK_MASK 0xfffffffe @@ -463,36 +463,36 @@ static int mv3310_set_edpd(struct phy_device *phydev,= u16 edpd) return err; } =20 -static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int mv3310_attach_mii_port(struct phy_device *phydev, + struct phy_port *port) { - struct phy_device *phydev =3D upstream; - __ETHTOOL_DECLARE_LINK_MODE_MASK(support) =3D { 0, }; - DECLARE_PHY_INTERFACE_MASK(interfaces); - phy_interface_t iface; - - sfp_parse_support(phydev->sfp_bus, id, support, interfaces); - iface =3D sfp_select_interface(phydev->sfp_bus, support); + __set_bit(PHY_INTERFACE_MODE_10GBASER, port->interfaces); =20 - if (iface !=3D PHY_INTERFACE_MODE_10GBASER) { - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n"); - return -EINVAL; - } return 0; } =20 -static const struct sfp_upstream_ops mv3310_sfp_ops =3D { - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, - .module_insert =3D mv3310_sfp_insert, -}; +static int mv3310_attach_mdi_port(struct phy_device *phydev, + struct phy_port *port) +{ + /* This PHY can do combo-ports, i.e. 2 MDI outputs, usually one + * of them going to an SFP and the other one to a RJ45 + * connector. If we don't have any representation for the port + * in DT, and we are dealing with a non-SFP port, then we + * mask the port's capabilities to report BaseT-only modes + */ + if (port->not_described) + return phy_port_restrict_mediums(port, + BIT(ETHTOOL_LINK_MEDIUM_BASET)); + + return 0; +} =20 static int mv3310_probe(struct phy_device *phydev) { const struct mv3310_chip *chip =3D to_mv3310_chip(phydev); struct mv3310_priv *priv; u32 mmd_mask =3D MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; + DECLARE_PHY_INTERFACE_MASK(interfaces); int ret; =20 if (!phydev->is_c45 || @@ -543,9 +543,13 @@ static int mv3310_probe(struct phy_device *phydev) if (ret) return ret; =20 + __set_bit(PHY_INTERFACE_MODE_10GBASER, interfaces); + chip->init_supported_interfaces(priv->supported_interfaces); =20 - return phy_sfp_probe(phydev, &mv3310_sfp_ops); + phydev->max_n_ports =3D 2; + + return 0; } =20 static void mv3310_remove(struct phy_device *phydev) @@ -1406,6 +1410,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_loopback =3D genphy_c45_loopback, .get_wol =3D mv3110_get_wol, .set_wol =3D mv3110_set_wol, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88X3310, @@ -1425,6 +1431,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_tunable =3D mv3310_set_tunable, .remove =3D mv3310_remove, .set_loopback =3D genphy_c45_loopback, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88E2110, @@ -1445,6 +1453,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_loopback =3D genphy_c45_loopback, .get_wol =3D mv3110_get_wol, .set_wol =3D mv3110_set_wol, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, { .phy_id =3D MARVELL_PHY_ID_88E2110, @@ -1463,6 +1473,8 @@ static struct phy_driver mv3310_drivers[] =3D { .set_tunable =3D mv3310_set_tunable, .remove =3D mv3310_remove, .set_loopback =3D genphy_c45_loopback, + .attach_mii_port =3D mv3310_attach_mii_port, + .attach_mdi_port =3D mv3310_attach_mdi_port, }, }; =20 diff --git a/drivers/net/phy/phy_port.c b/drivers/net/phy/phy_port.c index 6fecaa68350e..b1ba3e56c28d 100644 --- a/drivers/net/phy/phy_port.c +++ b/drivers/net/phy/phy_port.c @@ -131,6 +131,50 @@ void phy_port_update_supported(struct phy_port *port) } EXPORT_SYMBOL_GPL(phy_port_update_supported); =20 +/** + * phy_port_filter_supported() - Make sure that port->supported match port= ->mediums + * @port: The port to filter + * + * After updating a port's mediums to a more restricted subset, this helpe= r will + * make sure that port->supported only contains linkmodes that are compati= ble + * with port->mediums. + */ +static void phy_port_filter_supported(struct phy_port *port) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported) =3D { 0 }; + int i; + + for_each_set_bit(i, &port->mediums, __ETHTOOL_LINK_MEDIUM_LAST) + phy_caps_medium_get_supported(supported, i, port->lanes); + + linkmode_and(port->supported, port->supported, supported); +} + +/** + * phy_port_restrict_mediums - Mask away some of the port's supported medi= ums + * @port: The port to act upon + * @mediums: A mask of mediums to support on the port + * + * This helper allows removing some mediums from a port's list of supported + * mediums, which occurs once we have enough information about the port to + * know its nature. + * + * Returns 0 if the change was donne correctly, a negative value otherwise. + */ +int phy_port_restrict_mediums(struct phy_port *port, unsigned long mediums) +{ + /* We forbid ending-up with a port with empty mediums */ + if (!(port->mediums & mediums)) + return -EINVAL; + + port->mediums &=3D mediums; + + phy_port_filter_supported(port); + + return 0; +} +EXPORT_SYMBOL_GPL(phy_port_restrict_mediums); + /** * phy_port_get_type() - get the PORT_* attribute for that port. * @port: The port we want the information from diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index 053c35c70071..82f1992d2395 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -92,6 +92,7 @@ static inline bool phy_port_is_fiber(struct phy_port *por= t) } =20 void phy_port_update_supported(struct phy_port *port); +int phy_port_restrict_mediums(struct phy_port *port, unsigned long mediums= ); =20 int phy_port_get_type(struct phy_port *port); =20 --=20 2.49.0