From mboxrd@z Thu Jan 1 00:00:00 1970 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 E11613DA5C5; Mon, 9 Mar 2026 15:28:24 +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=1773070106; cv=none; b=Tp59nLd5vyvhmDM/8nxyoTED+Rb5LPpu44GXyEzIDsBqRFZ0UolFvjlq/U05+trLteKgqS1CtNh6dTtJw/1n+wmLThSdCvehsPbW976ergcD+i9+XWG20FmftH7dK1b+p3S3SQAZyyDjfEq+gia+Ctyc7zmQK8JCigyAP+caWC4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773070106; c=relaxed/simple; bh=uEQeN0vxoEyRCuImzjX9j4MpbTlEygqNCJASWtz4ElA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TC6XLP2zu9/pWDPG51vL6ZO/gQEI1n7UqDjCzi/s+32p1VmA8HIEbVrAUJS0Psk66WaiBiTI45gU28oNFoeLLZAt8MJpA5bJ4rChDNDXjXAIVjU0l//lREMUwRDph51QNnvFyJ/nIXwizahKTUNVE5pG1Lv5K47mQtVftxDWX/g= 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=Lf2+/NJE; 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="Lf2+/NJE" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 074EFC4287A; Mon, 9 Mar 2026 15:28:44 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9790F5FFB8; Mon, 9 Mar 2026 15:28:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 739A210369BEB; Mon, 9 Mar 2026 16:28:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1773070102; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=qK4qLN2x9n9zFHPA2chwl6R1hVAJ8MmQnQOGnYcll5c=; b=Lf2+/NJEnhZ8OATAxKdBdLwELfLTak0iN0RuP+gwgRBtJXuafwrHAHwksPbZUuebNwitWp 9bwxCfLJfYayOztv3Mx2sbQbQQcJ/FC//kwvRGz4VkI2FggQoNmhhKNFdO350BVaMd/B3f s+xe1G7XiR3ilT2CP+RXLzwNUi+yRNes0FPFduij03zG7sITMoe9Qe0r1MS3pDO9BMKGzQ s1aW4AXqydcOQ9W4M7UG1x0mdPmW/UsHONPdH8e04BgHYrRyQl8J/kZfl3Jr4z7IWBdWLn xF0YCX+joPjeSIcwshGYZ26ZOnCZJ5HvgjNsSBoJuHAr9X375/C3XFsxQGCxcQ== 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 , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH net-next v7 07/10] net: phy: phy_port: Store information about a MII port's vacant state Date: Mon, 9 Mar 2026 16:27:43 +0100 Message-ID: <20260309152747.702373-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260309152747.702373-1-maxime.chevallier@bootlin.com> References: <20260309152747.702373-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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 8bff64040540..5d26d75b5f6b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1550,6 +1550,7 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id) struct phy_device *phydev = upstream; const struct sfp_module_caps *caps; struct phy_port *port; + int ret = 0; phy_interface_t iface; @@ -1578,9 +1579,12 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id) phydev->port = caps->port; if (port->ops && port->ops->configure_mii) - return port->ops->configure_mii(port, true, iface); + ret = port->ops->configure_mii(port, true, iface); - return 0; + if (!ret) + port->vacant = false; + + return ret; } static void phy_sfp_module_remove(void *upstream) @@ -1588,8 +1592,12 @@ static void phy_sfp_module_remove(void *upstream) struct phy_device *phydev = upstream; struct phy_port *port = phy_get_sfp_port(phydev); - 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 = true; + } if (phydev->n_ports == 1) phydev->port = PORT_NONE; @@ -1756,6 +1764,7 @@ static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev) */ port->is_mii = true; port->is_sfp = true; + port->vacant = true; /* 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 79f7811dec22..dcf06b9670a2 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1777,6 +1777,7 @@ static int phylink_create_sfp_port(struct phylink *pl) port->is_sfp = true; port->is_mii = true; port->active = true; + port->vacant = true; phy_interface_and(port->interfaces, pl->config->supported_interfaces, phylink_sfp_interfaces); @@ -3908,6 +3909,7 @@ static int phylink_sfp_module_insert(void *upstream, { const struct sfp_module_caps *caps; struct phylink *pl = upstream; + int ret; ASSERT_RTNL(); @@ -3917,17 +3919,27 @@ static int phylink_sfp_module_insert(void *upstream, pl->sfp_may_have_phy = caps->may_have_phy; pl->sfp_port = caps->port; + if (pl->sfp_bus_port) + pl->sfp_bus_port->vacant = false; + /* If this module may have a PHY connecting later, defer until later */ if (pl->sfp_may_have_phy) return 0; - return phylink_sfp_config_optical(pl); + ret = phylink_sfp_config_optical(pl); + if (ret && pl->sfp_bus_port) + pl->sfp_bus_port->vacant = true; + + return ret; } static void phylink_sfp_module_remove(void *upstream) { struct phylink *pl = upstream; + if (pl->sfp_bus_port) + pl->sfp_bus_port->vacant = true; + phy_interface_zero(pl->sfp_interfaces); } 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 connection to + * another device (e.g. for SFP ports, indicates the absence or presence + * 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; }; struct phy_port *phy_port_alloc(void); -- 2.49.0