From nobody Thu Apr 2 00:13:51 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 E553B39D6D2 for ; Wed, 25 Mar 2026 08:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774426819; cv=none; b=RuXGmXOirwaOAhLtNVYnkawUeuzsCTTPB81Z65HMo8aKExkdMWS3NvJooFiSshjyscvSwt6oNfNvm6YMmrGCugZDlCiJ622ai/gHlXtiAcPRfXoWO7Lqq6jPvfOd8ULg0FG+HntNkJcaGgbSVEU8kXCaBT+XEGvg7w4nZt1UcWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774426819; c=relaxed/simple; bh=iDiJ/hD9RyZ/VBe/8q2iwHgY1byzT7ehQ7dGfaxCVmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OQp2amEgHlJcI4gayk/LhjGbM/DneXbhg4eGDRHHjP53BlCyhhVMHmw3DuNXz3jlLL/zYFUGQHAVeSz3+qHUOpf6EvZQb4wTxopyPfkVqakC+5M2EtN1w1L44RiSbTBkUgLivQ3hueKXSMNvptEM/KfNvrL9WCf4/7Td9smgVQI= 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=wcgAwGmh; arc=none smtp.client-ip=185.171.202.116 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="wcgAwGmh" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 4A08DC580AC; Wed, 25 Mar 2026 08:20:43 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9F848601A1; Wed, 25 Mar 2026 08:20:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 853B61045136B; Wed, 25 Mar 2026 09:20:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1774426814; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=mHopyKwGp0vXHDq7EzOxlyO9Kyr64b+XQr9pdlp672E=; b=wcgAwGmh2xKyx7ZJ2WDoTUnsYjHB+uH9/6nVscC7ATgjqYOwe/po30qEHwzU7hVPQ1PvRW pDKB4ow37ovJYTfyrZMWRyWleVywlMF89zwA6WNmSUAROwhGZsa4XUJEDiftf+/YdTbCeo x8vv6wSHA/iqxhhJNyR1FrYUl38ExzQzrow1fu2f6YKuJweB+AnuWr+EB95Ymy52SrDTzg M+Bn7H/BlJqXrJNpwVJPfpvyUH28URXD4wuOc7kZaprztv8aVN8rVm6aBXesDeg39s5IpI EkObrj0bnLqNe1dj3id75g/VjxEIcLRFR0MjKuaADCxbGuTF827j6sIDRJ6tew== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Christophe Leroy , Herve Codina , Florian Fainelli , 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, Romain Gantois , Daniel Golle , Dimitri Fedrau Subject: [PATCH net-next v8 07/10] net: phy: phy_port: Store information about a MII port's vacant state Date: Wed, 25 Mar 2026 09:19:32 +0100 Message-ID: <20260325081937.571115-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260325081937.571115-1-maxime.chevallier@bootlin.com> References: <20260325081937.571115-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" MII phy_ports are not meant to be connected directly to a link partner. They are meant to feed into some media converter devices, so far we only support SFP modules for that. We have information about what MII they can handle, however we don't store anything about whether they are currently connected to an SFP module or not. As phy_port aims at listing the front-facing ports, let's store an "vacant" bit to know whether or not a MII port is currently vacant (i.e. there's no module in the SFP cage), or not (i.e. there's an SFP module). Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 17 +++++++++++++---- drivers/net/phy/phylink.c | 14 +++++++++++++- include/linux/phy_port.h | 4 ++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2c0b0d275809..855db4431611 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1556,6 +1556,7 @@ static int phy_sfp_module_insert(void *upstream, cons= t struct sfp_eeprom_id *id) struct phy_device *phydev =3D upstream; const struct sfp_module_caps *caps; struct phy_port *port; + int ret =3D 0; =20 phy_interface_t iface; =20 @@ -1584,9 +1585,12 @@ static int phy_sfp_module_insert(void *upstream, con= st struct sfp_eeprom_id *id) phydev->port =3D caps->port; =20 if (port->ops && port->ops->configure_mii) - return port->ops->configure_mii(port, true, iface); + ret =3D port->ops->configure_mii(port, true, iface); =20 - return 0; + if (!ret) + port->vacant =3D false; + + return ret; } =20 static void phy_sfp_module_remove(void *upstream) @@ -1594,8 +1598,12 @@ static void phy_sfp_module_remove(void *upstream) struct phy_device *phydev =3D upstream; struct phy_port *port =3D phy_get_sfp_port(phydev); =20 - if (port && port->ops && port->ops->configure_mii) - port->ops->configure_mii(port, false, PHY_INTERFACE_MODE_NA); + if (port) { + if (port->ops && port->ops->configure_mii) + port->ops->configure_mii(port, false, + PHY_INTERFACE_MODE_NA); + port->vacant =3D true; + } =20 if (phydev->n_ports =3D=3D 1) phydev->port =3D PORT_NONE; @@ -1762,6 +1770,7 @@ static struct phy_port *phy_setup_sfp_port(struct phy= _device *phydev) */ port->is_mii =3D true; port->is_sfp =3D true; + port->vacant =3D true; =20 /* The port->supported and port->interfaces list will be populated * when attaching the port to the phydev. diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 73d838b918d1..8bf0e2f143df 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1784,6 +1784,7 @@ static int phylink_create_sfp_port(struct phylink *pl) port->is_sfp =3D true; port->is_mii =3D true; port->active =3D true; + port->vacant =3D true; =20 phy_interface_and(port->interfaces, pl->config->supported_interfaces, phylink_sfp_interfaces); @@ -3915,6 +3916,7 @@ static int phylink_sfp_module_insert(void *upstream, { const struct sfp_module_caps *caps; struct phylink *pl =3D upstream; + int ret; =20 ASSERT_RTNL(); =20 @@ -3924,17 +3926,27 @@ static int phylink_sfp_module_insert(void *upstream, pl->sfp_may_have_phy =3D caps->may_have_phy; pl->sfp_port =3D caps->port; =20 + if (pl->sfp_bus_port) + pl->sfp_bus_port->vacant =3D false; + /* If this module may have a PHY connecting later, defer until later */ if (pl->sfp_may_have_phy) return 0; =20 - return phylink_sfp_config_optical(pl); + ret =3D phylink_sfp_config_optical(pl); + if (ret && pl->sfp_bus_port) + pl->sfp_bus_port->vacant =3D true; + + return ret; } =20 static void phylink_sfp_module_remove(void *upstream) { struct phylink *pl =3D upstream; =20 + if (pl->sfp_bus_port) + pl->sfp_bus_port->vacant =3D true; + phy_interface_zero(pl->sfp_interfaces); } =20 diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h index 4e2a3fdd2f2e..b0b1fa6a67a9 100644 --- a/include/linux/phy_port.h +++ b/include/linux/phy_port.h @@ -51,6 +51,9 @@ struct phy_port_ops { * @is_mii: Indicates if this port is MII (Media Independent Interface), * or MDI (Media Dependent Interface). * @is_sfp: Indicates if this port drives an SFP cage. + * @vacant: For MII ports, indicates whether or not the port has a connect= ion to + * another device (e.g. for SFP ports, indicates the absence or presen= ce + * of an SFP module) */ struct phy_port { u32 id; @@ -71,6 +74,7 @@ struct phy_port { unsigned int active:1; unsigned int is_mii:1; unsigned int is_sfp:1; + unsigned int vacant:1; }; =20 struct phy_port *phy_port_alloc(void); --=20 2.49.0