From nobody Tue Apr 7 02:35:29 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 51F8F38D684 for ; Fri, 3 Apr 2026 12:38:31 +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=1775219916; cv=none; b=D8QaAbzGWvJTrwifmp/8Y9NYoIIY3BC40N5MYRA9UTJKt6wZ1WLB2vtmYyDhkFadzn6tBdP7rPN8V9EWJm5nUGsxwqiSFdfKiOcEC9RPHvaeIZRF/wr0QsQkkNIk0BcKeF8REmikE56rdwxTxB6cLrusXkhUTZ1qKuXji8W8hMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775219916; c=relaxed/simple; bh=N1CBS8BqgZzKSJmozCttV6AgCb4lgNdrmXSqUo/dmCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q/KiM/4cwYKa7w2hI5RzYNbcb5v0ZlHVQas4WIrc9wlLQxLQgx5P0ImzQv8/d0Sgy8BoeXO8n7KX9+3jtjJ0xn9pnOoOaGns/Y1l1zaclXZc5vW7liGF84tuVCpypTCMWZvHvWq4+qeixjeLpxb5Dz6BHd5UC70xMeBOtpOLz8I= 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=GLLXdEqz; 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="GLLXdEqz" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 891C5C59F5E; Fri, 3 Apr 2026 12:39:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9D792603C1; Fri, 3 Apr 2026 12:38:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B6509104500CD; Fri, 3 Apr 2026 14:38:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775219909; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=18HUN901YZHpvRkDKZOw6wPpGq/fFyOvevjMYcQwQ2U=; b=GLLXdEqz4Mwz61KtbvvnQp489UyUK6F2MK5+p0m3A+mop12lSkWUS9tzK3wua9ZHGFp6EN 9wXQPkPiFAVmDmNuKB5kTfYeaVKZoYg4jN+H61PU8A0D/5+bPvow+H0nz+b9w+MUYp1/X8 mdHSt/H2tyqc3odXdT+X0wxeD+9VxqqysyyOl3jLSIDueT0FJph6g9aho0y5/xplRc47Q9 xaAmtqF1arCLP9m1ySalksPSncO/gPGm8cHdZsynOMNuFQaAdCp8ID76CCSbQcvKAYPhPp Vflx4AgNitNlWGgNWDFhTdefxMG7cw2ReCl5Gx3aYiPa4dqgAU4SnPxW4n9Jdg== 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 v9 07/10] net: phy: phy_port: Store information about a MII port's vacant state Date: Fri, 3 Apr 2026 14:37:51 +0200 Message-ID: <20260403123755.175742-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260403123755.175742-1-maxime.chevallier@bootlin.com> References: <20260403123755.175742-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 c32d1b8a8e40..894aa797e5f8 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1558,6 +1558,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 @@ -1586,9 +1587,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) @@ -1596,8 +1600,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; @@ -1764,6 +1772,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 8d57c95f877a..ff7940736183 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); @@ -3907,6 +3908,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 @@ -3916,17 +3918,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