Netdev List
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, llvm@lists.linux.dev
Subject: [PATCH net-next v23 07/15] net: sfp: support deferred module insertion
Date: Mon, 30 Nov 2026 00:05:37 +0100	[thread overview]
Message-ID: <20261129230558.612526-8-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com>

Add support for deferring SFP module insertion when the upstream
device needs a dependency that is not yet available. If module_insert()
returns -EAGAIN, keep the module in SFP_MOD_WAITDEV with its transmitter
disabled. Other insertion errors still move the module to SFP_MOD_ERROR.

Add sfp_upstream_retry_module() to let the upstream retry insertion
once the dependency becomes available. A successful retry continues
through the normal module power and link startup sequence.

This is needed by phylink when an optical SFP is inserted before the
PCS provider for its host interface registers.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/sfp-bus.c | 16 ++++++++++++++++
 drivers/net/phy/sfp.c     | 17 +++++++++++++++++
 drivers/net/phy/sfp.h     |  1 +
 include/linux/sfp.h       | 10 ++++++++--
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/sfp-bus.c b/drivers/net/phy/sfp-bus.c
index 8679d27bf1ba..66ac02f91bc0 100644
--- a/drivers/net/phy/sfp-bus.c
+++ b/drivers/net/phy/sfp-bus.c
@@ -563,6 +563,22 @@ void sfp_upstream_stop(struct sfp_bus *bus)
 }
 EXPORT_SYMBOL_GPL(sfp_upstream_stop);
 
+/**
+ * sfp_upstream_retry_module() - Retry deferred module insertion
+ * @bus: a pointer to the &struct sfp_bus for the module
+ *
+ * Ask the socket to retry insertion of a module whose upstream
+ * module_insert() callback returned -EAGAIN. Call with RTNL held.
+ */
+void sfp_upstream_retry_module(struct sfp_bus *bus)
+{
+	ASSERT_RTNL();
+
+	if (bus->registered && bus->socket_ops->retry_module)
+		bus->socket_ops->retry_module(bus->sfp);
+}
+EXPORT_SYMBOL_GPL(sfp_upstream_retry_module);
+
 static void sfp_upstream_clear(struct sfp_bus *bus)
 {
 	bus->upstream_ops = NULL;
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 915156743701..e5ddd62318bf 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -43,6 +43,7 @@ enum {
 	SFP_E_DEV_DETACH,
 	SFP_E_DEV_DOWN,
 	SFP_E_DEV_UP,
+	SFP_E_UPSTREAM_RETRY,
 	SFP_E_TX_FAULT,
 	SFP_E_TX_CLEAR,
 	SFP_E_LOS_HIGH,
@@ -111,6 +112,7 @@ static const char * const event_strings[] = {
 	[SFP_E_DEV_DETACH] = "dev_detach",
 	[SFP_E_DEV_DOWN] = "dev_down",
 	[SFP_E_DEV_UP] = "dev_up",
+	[SFP_E_UPSTREAM_RETRY] = "upstream_retry",
 	[SFP_E_TX_FAULT] = "tx_fault",
 	[SFP_E_TX_CLEAR] = "tx_clear",
 	[SFP_E_LOS_HIGH] = "los_high",
@@ -2823,6 +2825,10 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
 		sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
 		fallthrough;
 	case SFP_MOD_WAITDEV:
+		if (event != SFP_E_TIMEOUT && event != SFP_E_DEV_ATTACH &&
+		    event != SFP_E_UPSTREAM_RETRY)
+			break;
+
 		/* Ensure that the device is attached before proceeding */
 		if (sfp->sm_dev_state < SFP_DEV_DOWN)
 			break;
@@ -2830,6 +2836,8 @@ static void sfp_sm_module(struct sfp *sfp, unsigned int event)
 		/* Report the module insertion to the upstream device */
 		err = sfp_module_insert(sfp->sfp_bus, &sfp->id,
 					sfp->quirk);
+		if (err == -EAGAIN)
+			break;
 		if (err < 0) {
 			sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
 			break;
@@ -3091,6 +3099,14 @@ static void sfp_stop(struct sfp *sfp)
 	sfp_sm_event(sfp, SFP_E_DEV_DOWN);
 }
 
+static void sfp_retry_module(struct sfp *sfp)
+{
+	mutex_lock(&sfp->sm_mutex);
+	if (sfp->sm_mod_state == SFP_MOD_WAITDEV)
+		__sfp_sm_event(sfp, SFP_E_UPSTREAM_RETRY);
+	mutex_unlock(&sfp->sm_mutex);
+}
+
 static void sfp_set_signal_rate(struct sfp *sfp, unsigned int rate_kbd)
 {
 	unsigned int set;
@@ -3189,6 +3205,7 @@ static const struct sfp_socket_ops sfp_module_ops = {
 	.detach = sfp_detach,
 	.start = sfp_start,
 	.stop = sfp_stop,
+	.retry_module = sfp_retry_module,
 	.set_signal_rate = sfp_set_signal_rate,
 	.module_info = sfp_module_info,
 	.module_eeprom = sfp_module_eeprom,
diff --git a/drivers/net/phy/sfp.h b/drivers/net/phy/sfp.h
index 19fe29d844a1..de0b89f6fbca 100644
--- a/drivers/net/phy/sfp.h
+++ b/drivers/net/phy/sfp.h
@@ -20,6 +20,7 @@ struct sfp_socket_ops {
 	void (*detach)(struct sfp *sfp);
 	void (*start)(struct sfp *sfp);
 	void (*stop)(struct sfp *sfp);
+	void (*retry_module)(struct sfp *sfp);
 	void (*set_signal_rate)(struct sfp *sfp, unsigned int rate_kbd);
 	int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);
 	int (*module_eeprom)(struct sfp *sfp, struct ethtool_eeprom *ee,
diff --git a/include/linux/sfp.h b/include/linux/sfp.h
index 5c71945a5e4d..7fd4ebf1c74f 100644
--- a/include/linux/sfp.h
+++ b/include/linux/sfp.h
@@ -550,8 +550,9 @@ struct sfp_module_caps {
  * @detach: called when the sfp socket driver is unbound from the upstream
  *   (mandatory).
  * @module_insert: called after a module has been detected to determine
- *   whether the module is supported for the upstream device.
- * @module_remove: called after the module has been removed.
+ *   whether the module is supported for the upstream device. Return
+ *   -EAGAIN to defer insertion until sfp_upstream_retry_module() is called.
+ * @module_remove: called after a successfully inserted module is removed.
  * @module_start: called after the PHY probe step
  * @module_stop: called before the PHY is removed
  * @link_down: called when the link is non-operational for whatever
@@ -588,6 +589,7 @@ int sfp_get_module_eeprom_by_page(struct sfp_bus *bus,
 				  struct netlink_ext_ack *extack);
 void sfp_upstream_start(struct sfp_bus *bus);
 void sfp_upstream_stop(struct sfp_bus *bus);
+void sfp_upstream_retry_module(struct sfp_bus *bus);
 void sfp_upstream_set_signal_rate(struct sfp_bus *bus, unsigned int rate_kbd);
 void sfp_bus_put(struct sfp_bus *bus);
 struct sfp_bus *sfp_bus_find_fwnode(const struct fwnode_handle *fwnode);
@@ -635,6 +637,10 @@ static inline void sfp_upstream_stop(struct sfp_bus *bus)
 {
 }
 
+static inline void sfp_upstream_retry_module(struct sfp_bus *bus)
+{
+}
+
 static inline void sfp_upstream_set_signal_rate(struct sfp_bus *bus,
 						unsigned int rate_kbd)
 {
-- 
2.55.0


  parent reply	other threads:[~2026-11-29 23:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 23:05 [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-29 23:05 ` Christian Marangi [this message]
2026-11-29 23:05 ` [PATCH net-next v23 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 15/15] net: airoha: add phylink support Christian Marangi
2026-11-29 23:09 ` [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129230558.612526-8-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=justinstitt@google.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=llvm@lists.linux.dev \
    --cc=lorenzo@kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox