From nobody Thu Oct 2 07:46:36 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 345412F2D; Sun, 21 Sep 2025 16:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758470847; cv=none; b=RWlfwdnBYzf6zUK4WUNRWQvi1PhsKTXt/fUY1K6DFPf3vkmBaHLbV1Bovq/LghObzjX0GJmlICl53GsxZ7Mg3JRD2XbJ0WhUR83Ke5VfAvBst3+GpaKXI7PQG4mRIOPMdq3/OK9EFG2hUjZrRpwfuuLqgP7SjC1t6wePvdhY2sk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758470847; c=relaxed/simple; bh=MXW1Jb7KzPWgLzv+HJ/LHROoDbabD5y2QGy62iIirPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tyuzuaw0w42e4nnFowzGhjRbCf32g3SPpBjTGb/rTeNCEaoDBsEGUtmoP7Gp6IfVDgn2S0k5zGyC38ahjgnmAJLCHbXp9fgbfUVWAMPNiitmJWFBAJYxV1vufN6v+AuOZLUwam9djLd1JdW43OPAUCAPloXYKJYM1Us16AQZH4I= 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=in47hA/s; arc=none smtp.client-ip=185.246.84.56 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="in47hA/s" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id D5DF71A0DEA; Sun, 21 Sep 2025 16:07:23 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AAFDA60634; Sun, 21 Sep 2025 16:07:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2CA5B102F17CA; Sun, 21 Sep 2025 18:07:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1758470842; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=IKa8/tKq7d87/55EpDARyVd2xV5xELnvm1ATIaxUCdQ=; b=in47hA/sYLG7e0ycTimnSPFo0YUU/YuCf2QBwns6qSNmOU6P5aVeyFIP8QpkWi4g8hGc9p 4udx5l5dakaC3s4Vl+v6dSW+ix8az2POdeEtjj3IQ7KP4OTvgo4ehJ7R69gcIRx6Urnp4e blYQWbmfXPOuVxAIQ7+nx54ZW4+7WXJtCWubEROpaMUFHsdpFJWEjxw8myYW3UhayH3zpr C6/W4M9+IAPbf1tardJfTgUftjPBE43RGIax2hFUr/liXZep3iIwSRGPD27lrg7OL672nz 0YGLEg2h6zbWGNrO9ennFVwYziJ7CkIWgGnNLful8xma2rS09KE8O9SNVVYYyQ== 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 11/18] net: phy: marvell-88x2222: Support SFP through phy_port interface Date: Sun, 21 Sep 2025 21:34:09 +0530 Message-ID: <20250921160419.333427-12-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" The 88x2222 PHY from Marvell only supports serialised modes as its line-facing interfaces. Convert that driver to the generic phylib SFP handling. Reviewed-by: Christophe Leroy Tested-by: Oleksij Rempel Tested-by: Florian Fainelli Tested-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell-88x2222.c | 95 +++++++++++++------------------ 1 file changed, 38 insertions(+), 57 deletions(-) diff --git a/drivers/net/phy/marvell-88x2222.c b/drivers/net/phy/marvell-88= x2222.c index fad2f54c1eac..ba1bbb6c63d6 100644 --- a/drivers/net/phy/marvell-88x2222.c +++ b/drivers/net/phy/marvell-88x2222.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include =20 /* Port PCS Configuration */ @@ -473,90 +473,70 @@ static int mv2222_config_init(struct phy_device *phyd= ev) return 0; } =20 -static int mv2222_sfp_insert(void *upstream, const struct sfp_eeprom_id *i= d) +static int mv2222_configure_serdes(struct phy_port *port, bool enable, + phy_interface_t interface) { - DECLARE_PHY_INTERFACE_MASK(interfaces); - struct phy_device *phydev =3D upstream; - phy_interface_t sfp_interface; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; - struct device *dev; - int ret; - - __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_supported) =3D { 0, }; + int ret =3D 0; =20 priv =3D phydev->priv; - dev =3D &phydev->mdio.dev; - - sfp_parse_support(phydev->sfp_bus, id, sfp_supported, interfaces); - phydev->port =3D sfp_parse_port(phydev->sfp_bus, id, sfp_supported); - sfp_interface =3D sfp_select_interface(phydev->sfp_bus, sfp_supported); - - dev_info(dev, "%s SFP module inserted\n", phy_modes(sfp_interface)); + priv->line_interface =3D interface; =20 - if (sfp_interface !=3D PHY_INTERFACE_MODE_10GBASER && - sfp_interface !=3D PHY_INTERFACE_MODE_1000BASEX && - sfp_interface !=3D PHY_INTERFACE_MODE_SGMII) { - dev_err(dev, "Incompatible SFP module inserted\n"); + if (enable) { + linkmode_and(priv->supported, phydev->supported, port->supported); =20 - return -EINVAL; - } - - priv->line_interface =3D sfp_interface; - linkmode_and(priv->supported, phydev->supported, sfp_supported); + ret =3D mv2222_config_line(phydev); + if (ret < 0) + return ret; =20 - ret =3D mv2222_config_line(phydev); - if (ret < 0) - return ret; + if (mutex_trylock(&phydev->lock)) { + ret =3D mv2222_config_aneg(phydev); + mutex_unlock(&phydev->lock); + } =20 - if (mutex_trylock(&phydev->lock)) { - ret =3D mv2222_config_aneg(phydev); - mutex_unlock(&phydev->lock); + } else { + linkmode_zero(priv->supported); } =20 return ret; } =20 -static void mv2222_sfp_remove(void *upstream) +static void mv2222_port_link_up(struct phy_port *port) { - struct phy_device *phydev =3D upstream; - struct mv2222_data *priv; - - priv =3D phydev->priv; - - priv->line_interface =3D PHY_INTERFACE_MODE_NA; - linkmode_zero(priv->supported); - phydev->port =3D PORT_NONE; -} - -static void mv2222_sfp_link_up(void *upstream) -{ - struct phy_device *phydev =3D upstream; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; =20 priv =3D phydev->priv; priv->sfp_link =3D true; } =20 -static void mv2222_sfp_link_down(void *upstream) +static void mv2222_port_link_down(struct phy_port *port) { - struct phy_device *phydev =3D upstream; + struct phy_device *phydev =3D port_phydev(port); struct mv2222_data *priv; =20 priv =3D phydev->priv; priv->sfp_link =3D false; } =20 -static const struct sfp_upstream_ops sfp_phy_ops =3D { - .module_insert =3D mv2222_sfp_insert, - .module_remove =3D mv2222_sfp_remove, - .link_up =3D mv2222_sfp_link_up, - .link_down =3D mv2222_sfp_link_down, - .attach =3D phy_sfp_attach, - .detach =3D phy_sfp_detach, - .connect_phy =3D phy_sfp_connect_phy, - .disconnect_phy =3D phy_sfp_disconnect_phy, +static const struct phy_port_ops mv2222_port_ops =3D { + .link_up =3D mv2222_port_link_up, + .link_down =3D mv2222_port_link_down, + .configure_mii =3D mv2222_configure_serdes, }; =20 +static int mv2222_attach_mii_port(struct phy_device *phydev, struct phy_po= rt *port) +{ + port->ops =3D &mv2222_port_ops; + + __set_bit(PHY_INTERFACE_MODE_10GBASER, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces); + __set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces); + + return 0; +} + static int mv2222_probe(struct phy_device *phydev) { struct device *dev =3D &phydev->mdio.dev; @@ -592,7 +572,7 @@ static int mv2222_probe(struct phy_device *phydev) priv->line_interface =3D PHY_INTERFACE_MODE_NA; phydev->priv =3D priv; =20 - return phy_sfp_probe(phydev, &sfp_phy_ops); + return 0; } =20 static struct phy_driver mv2222_drivers[] =3D { @@ -609,6 +589,7 @@ static struct phy_driver mv2222_drivers[] =3D { .suspend =3D mv2222_suspend, .resume =3D mv2222_resume, .read_status =3D mv2222_read_status, + .attach_mii_port =3D mv2222_attach_mii_port, }, }; module_phy_driver(mv2222_drivers); --=20 2.49.0