From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2059606A31C for ; Sun, 29 Nov 2026 23:09:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=I8Sl4irj; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ioI1Bh6C DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=xZwQbKiYPINFt10McNO5HjjRcEvxZdy05a8WHc+F73Q=; b=I8Sl4irjgGkH1J 2Se6XdlIEL2Nx6I1xBKLpZoK6vP2AmYJfsfdWtROqSVO3JGcoAPKkdKPkt8GTBF8epgyEJZaVtTEj 9ThIqznS4TdMk1NtmWJsrCIOG6/ZdbZdhZ0GjbTOQOs5H54x6cEP1mXzlSX2WVAiWCMvMGrFmhPFC SwYDxOOZZv/p2lNzS+3dVnAk/VDiCaY21gveDB1LlBQXdf1Y6aVtIITJyMi4qH/wNgOx3iXqX9GPR aRNKNtpGpxSu+ocxXxa94tR0wCUuqTiS1Z2NKyP/Lo4wC+clj08EkMBaAneqZkdxIrrZZNuddyi5a +/0zp6ShNCOWgdDwe7VQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXo1A-00000002amh-1TRv; Sun, 29 Nov 2026 23:09:12 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXnye-00000002ZV5-2GDc for linux-arm-kernel@lists.infradead.org; Sun, 29 Nov 2026 23:06:39 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-4aa5833c263so9541219f8f.2 for ; Sun, 29 Nov 2026 15:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795993595; x=1796598395; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=xZwQbKiYPINFt10McNO5HjjRcEvxZdy05a8WHc+F73Q=; b=ioI1Bh6C3RbVuIbVJw+5Wb1DaAEP0tk9h6ga5doYauYBh/yjA4Khw5dO1Wsoin47vN vXnzzyQiSNO3utq0HHni/6OiC59dkvho9MJFrh1oXRfqd2BogeRXIKx2e6CsVSPBXGu+ rjmPdkfARMyUUblHGwAgut5TFOFoY5izRq0QuxVMigkLMipMLseUQ3BrwvURRE66qBBh cAPygw8cWyvUJpbdrgs86/oRdjpWtLiv3N75FMylfViPaEcoFOF1VQsJwwPLGo9eotUW dpx8Ble+33lVsZk55Q8szpK85dub5d9fTGTtWlFZOvR2l/owGLzCK0APRmA2iP137vRR Z6nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795993595; x=1796598395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=xZwQbKiYPINFt10McNO5HjjRcEvxZdy05a8WHc+F73Q=; b=Ta6vL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uMZCHXjmEsRi5kkppngxn5joqb9mYKTa3vKygl0owGq9CKSqu mv010TrEQNd2PS6q2h/W5ADaRpfm/ZfwgKwLlmNwfiNryIun9yxlp2JEH7C6QoKvvdNsUhjQdWt koj3a7s5QINbbzLmmCTN6lk9qJjfFQsxogp3dJ533MFvJpkMmz4+uGN7a7dM1mJ/Gbv6qj/5+4B VgMXaaMPV/rJxTRj0dQ== X-Received: by 2002:a05:6000:4a15:b0:49f:eb4b:faa3 with SMTP id ffacd0b85a97d-4abb2168f46mr61384450f8f.9.1795993594850; Sun, 29 Nov 2026 15:06:34 -0800 (PST) Received: from Ansuel-XPS24 (93-34-92-103.ip49.fastwebnet.it. [93.34.92.103]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-4ab6c4353d6sm58448894f8f.56.2026.11.29.15.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 15:06:34 -0800 (PST) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Willem de Bruijn , Simon Horman , Jonathan Corbet , Shuah Khan , Randy Dunlap , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , Maxime Chevallier , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Russell King (Oracle)" , 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 Message-ID: <20261129230558.612526-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261129230558.612526-1-ansuelsmth@gmail.com> References: <20261129230558.612526-1-ansuelsmth@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_150636_779316_852AD1E4 X-CRM114-Status: GOOD ( 24.28 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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