From nobody Sat Oct 4 17:31:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 EF96D3093D4; Thu, 14 Aug 2025 13:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755179943; cv=none; b=gsYbJf4ZFKN6U/wm5OY6dKcUtLXfpGFnYezum9mhf34ZdKuq0Q+wnqIg9Jg1jUi26KULDCilF6Dpg/EW0t46xmMv6OXt3MtTl7zB+qiywvfpkovUnOD7GIeMYPNtFyWpkzMjjz+xUxGg6IVoLWSJbkNBwpET/EPEox7L5Ti15ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755179943; c=relaxed/simple; bh=gmBMqH/qvbidJqQlBVjo3664Qd2TG8ZpzCPO3ncXiko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ldRCNtrmofzXgK++qwgWxH3nfDIc5Q/1PTqljepuBBYD9HcKQLYm1TVaguqKKutKnTrAk9L9Z/J0XnIev6lMRPZS33dYApRC83ttMF8OIOqKWC//im49EbbF6VX/7q8RUgI33bt7+ou0XRCrzzndUaEH0FNpbP3oJdmSXzLEyoA= 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=DFw3qyKt; arc=none smtp.client-ip=217.70.183.201 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="DFw3qyKt" Received: by mail.gandi.net (Postfix) with ESMTPSA id E642644423; Thu, 14 Aug 2025 13:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1755179938; 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=K+ZmXlBrudUSUTNrxOkKLMkUswzGiwkxUVkolz4rWV4=; b=DFw3qyKtE94GtmEFOqvL7rCgdcTSjjxlVQcEPie7vBC4jiXbNWMp1t1ZiZOflSQNP0Jx5S yF97XOkyI7YkQ917GvIvfOGN2g/gFQyahXij05qw6bQanq0ybwCIwchQJm8/MMNxrxCGSe eoVwOPuvQkjkI8wLnL3X44a5nIxGnztax+QrQD0xu3ouX61D8nSzVq8gHrPsD2i8iuV/Wq svRHngqiBR/3i/nDNmOraT0YpX69N3oVqj0q/AywJKstlDh+7likVd0F4OGTaZq5b5ZZqS fCro4PNqHX9JIIMySkzwSlVwjTczPuWG3dMQnpw5fc0vbdEsBp3GnVMzAPMeIg== 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 Subject: [PATCH net-next v11 11/16] net: phy: marvell10g: Support SFP through phy_port Date: Thu, 14 Aug 2025 15:58:26 +0200 Message-ID: <20250814135832.174911-12-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250814135832.174911-1-maxime.chevallier@bootlin.com> References: <20250814135832.174911-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-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddugeduvdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhmvgcuvehhvghvrghllhhivghruceomhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepveegtdffleffleevueellefgjeefvedvjefhheegfefgffdvfeetgeevudetffdtnecukfhppedvrgdtudemtggsudelmeekugegheemgeeltddtmeeiheeikeemvdelsgdumeelvghfheemvgektgejnecuvehluhhsthgvrhfuihiivgepjeenucfrrghrrghmpehinhgvthepvdgrtddumegtsgduleemkegugeehmeegledttdemieehieekmedvlegsudemlegvfhehmegvkegtjedphhgvlhhopehfvgguohhrrgdrhhhomhgvpdhmrghilhhfrhhomhepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepfedupdhrtghpthhtohepuggrvhgvmhesuggrvhgvmhhlohhfthdrnhgvthdprhgtphhtthhopehmrgigihhmvgdrtghhvghvrghllhhivghrsegsohhothhlihhnrdgtohhmpdhrtghpthhtohepnhgvthguvghvsehvghgvrhdrk hgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrghrmhdqmhhsmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomhdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhg X-GND-Sasl: maxime.chevallier@bootlin.com 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. 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 697721a6239f..6a69ec7c7f7c 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -91,6 +91,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