From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795993596; b=5kt9AzCM7wZB4F2HukDGM1+GaJmSfdjA9EBCRCSJgZCS4hq0fzLoz5wPOHAK29qfQ2Wl 33YqDomrorAIqJ8so8PXuhnPps6NkEkVb0ZzUGMRbvBNntOqwMbdZhi+Z1C2XGxIlUOBQ Vq93kV29ElRqs/cuLU2Vh0QTJEc/q3fY2XU6ckYbVE+qvsdJoEaQrWCgoZEZf5j+qA0Cw D+Udj0W15SljbB5uw7P78lntQCGSm0eJoxGirTwise32LdbQ7rltML+dnReysMfJX0q5f 5GGZVIYWV3NRpn80ydWJZd+bMpDtOuVh+YEk4U1p4RT4Jhy1HbkOHUgSB4iiZ/aHwuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795993596; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=xZwQbKiYPINFt10McNO5HjjRcEvxZdy05a8WHc+F73Q=; b=PtjsvLLtl3cSbM2D3lPEATamBXU4UP7leO+DblomZ421TfpSsqXMj2OlKBSXZqB/RD06 4zk6qjwfz8YpxdQaVzF7ohib1MeErjy6Xd9M8pKDs6wBuK1JduH/Akuq4Q6D7uNqUF/KQ kUFD1u45VLvi1hC04jfxk8Ww7w7GXFmTq+OuMIm4DhW2da5lpY3MbYmvNv1OrWGkU8SAu rhzefQ5fWiaSAkc7CSLkravJZrb3AciiK1tM7lVqq5sDaNyxHOPjgHAh9Kxgr4GDUX3xA vIaMEm2zJO6IbzIEUntRK0zJH6yXUuOb8V6V/GTRl/L3l34xEsA7pQtPnxRPvP4sPhA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Jl4dpNyH; arc=none smtp.remote-ip=209.85.221.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82CCD606A692 for ; Sun, 29 Nov 2026 23:06:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82CCD606A692 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Jl4dpNyH Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4aa5833c263so9541214f8f.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=vger.kernel.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=Jl4dpNyHB1jYzR7oRVNNJp6WirzciNgndLF+38qBAvYv8XkqyoNtDbmwqhWpr7KD34 arbzJuPUfh8717AfiLny6s8uXAQgqnP1H+9WZes6al4XrM8F9VD5azcChqhSyY2dZe0a g0fuBH5bgIea/+VAIAkWA+IZZ8E0lnECYkGWrJGTZ8AQjmxnOQsFLpBB9aCilIZSCNCF NjnANdTGXx9YtySOBqrV5FSmGM52rRUPTAjQdt+RcL5qKlEfhryHScS1m/UvC9+zx/QG C5w7dFoQygrOfPtbkxsYmnwSCMh2w6yTAHmwGjAzxpLnLr0sAKnfGWCdcaSMnO2PfjbZ /cYQ== 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=rmIiuW8c2puzsiD4gnI6reHxGpkIGH2twNtYduv9rY1hYg3MIq01S4s4TlJtzj0L6R XmO6VJBjt8D/nS/ZswnErQIT+/1KRzcdv76Phj/8uqHAWsOfZoHumV9jwgbTO7mYwk+9 74C680NWSEf8Zj1keUT781lD8Y9U367EhHfwJDXEfASF/YNAXyXYaCik808ImY8NP/4D u5sgYC5dPxQmkvHqkDG1tEBxp4Zu1Itv4zUk2YlAlTKCytKv/oCtjkoYsrhQGQdlVPTt oPlBWjr1DfRK6GtLwMUq2eEMM+uzaLutmd/IdV7Q6HfofJNR3keXG/3J+UPpMIRuwAyB dmMA== X-Forwarded-Encrypted: i=1; AL+hErGOO7rzQjO4Pv9A9UHvBRpHrwqFsjgKE5HvLpdnRRCZE1ZkfCTlM+dToTXdME6xDn3UEkjyBBMmhXE=@vger.kernel.org X-Gm-Message-State: APuU4Z/yxYHx4RIObc3uwZaWH45mvUSZBH8Z6KiGjM6hykcDX7m29bCC lPiVQYo9zAwrb+O++jJLUvMO3Eq+6BVFyq8DO37D6u9TDGoEg8NS6Rok X-Gm-Gg: AZFdTZdJXMOZP6TUpiZhrMEOk4ul+v3qNnWMhKnwlzFP26b2c8Q/UoZ3uNmwWM7tl2U K5GPu6dVedJ1zpsNW3VnP2bFupOUG3J0k2CwXaNPNf8dqNxeZevLkcebYSgdJAu8hiBgIxC/KCS FqseqnJ6+nMKkiZ9F8QQgNxvB+FbwyhMj6VOvQPUPtCjde1+Eq0qZK8Llykzofokygc/NXkyOuh kfD2ZdQLcUsTl9XAy2KG9wiyqPLznKJX5YThWXOb9V+oM6tgIH0ds/DgnBQR+JupP2h3EqGrL/S nc0VzC9lnytVQiA4Tm6xVXHuig8/IX0Y9DnygHthU2KBR+zIUMOVUtam8FIzUdYjSMZiBDpE6mK rTGoF58eN2CDz2+jhoDaIKLsnvpoRcVj+BT8ZVDKA3RozOuzGaKa1uPoy/8/oAV6amNioHbhBtw RPkGinuppwjT5k1rOSMGxrw50MJzZsg9NDUWurjMV2AuSWg/kpTxeX9M1RO5kTZl7qKbKiljJpt 7XQ1UX0MlNKWotd63lhwLf8nW6QDyk8aiIvN5ZvcdkuJxSna0rB+BbC0LJCQt/iw14UYoSUnpP5 8tH2+Ic4K8QINlX9TEGqi7xOWTFr345oK/bLatEDXEMKq4PbdhSZ+L65YHIFQdglmyw9qfpVKRb TVCTuHmMfxRsm7lkkVA== 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-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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