From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D55F248C400 for ; Tue, 9 Jun 2026 15:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781018005; cv=none; b=ky+OOPL+MbczTUNmrVmV+fNHZhmSNTZSKVVAc5oEeXhIRLH2zaTO8A9plbPSDWLTv0YmUIxtY5uWY4jOjXK/7K9eZ8rFHnKNtQCRv9OTXPS3qbM5KGkr7kFyLXEhCDkUN7dGwYzfsXPkPpaP3bkezTwcpDKc+6nms5nDQUY4aIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781018005; c=relaxed/simple; bh=Voe/pefI1KFM2x+c4luWiQDx2dS7vAkitqmSq+A9chw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M6UkJdbHFH7fFDIQ5ewmBDgVS5Hl2P12/H8ScBaOB+FR2uOiz1Z1WGm+HypMHSFqruaIVTprC9PKve37NrM48m54mqg+52kLCtzhFnrEps02bXvwzaTQKgpGSvmroQrjSZ4rGie8V6L6XPxEbOzDjhuXmBUOwVdrqfDKyZ+gatA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DIOHzJFJ; arc=none smtp.client-ip=209.85.218.47 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.b="DIOHzJFJ" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-bec49f7e35eso797692266b.2 for ; Tue, 09 Jun 2026 08:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781017996; x=1781622796; 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; bh=l0LE7NoxIbAtNkQIfgRXFPiPvGYIbbXScFz3Ib6pKBI=; b=DIOHzJFJxs8P8deuVlil4dotI1aCUgheP+m0vYgNC6/Yiiwn3zR01tgWCyAE+2rwsi z4t+8X3fNqGXrX+8xgplfb80OPHIdLdvRERcGo4zqEznf6yUI8kKcVXr1Ls8fDdLkXON M+Ph13yBs4I7fa0XgAoPNOfu7U0HvsoAmBxAqW2hD58fw7h0ABxlSZWIR9Q8FOe7Dmq/ lNcsTI1GxsC3Sm1YG1BiqSfw/jhMhE7L6Z1/WQjEDp6d4SMOUkJOpYraoRk4wFfBcNq1 5z6+VbAtfCr80gkBwXNCR3B5nGC9HZDqr8e58SKJ1eN150OPTu/zz36WHIsk3yDSLpte KNyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781017996; x=1781622796; 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; bh=l0LE7NoxIbAtNkQIfgRXFPiPvGYIbbXScFz3Ib6pKBI=; b=IBcGnpvpjgSX1DapmDOmL8Gu0aEoeiXEqjggLffxv/i5/7JMIQNSNRwZOpPBxjGXjp j30vl5/gd7xpLCAhQpjI0kYmtcmPXyjG6AlzmRW1S2rGDULGf+fEQT4ix5j+aH0EXK1g Y7ECJ/ROpo0goCX9xUqCb6Cn/yEb4+xphCp6gzQ5TXjVhsGtvNmXSgAQwhXJ+08xCEwE Qidh9qV4DIM+uOY6Fph6vm0+2AMLiCyFvA9IKRHfmFTNSB3yFZ7VglXz1ws9LlReKo9o lzAJNDFI1ty9lksJRNWieuXyYxn0qkAUlmwPoq/hVxT6PP2/edweE/uVLZTxJYfI9pd0 gJIA== X-Forwarded-Encrypted: i=1; AFNElJ/P+93rmRMDYTgxbf/8ExzbtL3pKQBbGEdM4urNmlPkQlr/uxHjtKxZz5eIfy58ReljAC3ZBoqVBhQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxuOk7XK17ScHpOpoZFpzNz/hJV3GzQnT65XHQEAcQg97tHT4zM A0BZFrPNvVDde9nvxXEh91tFZ98iNyaqF7OzAxoujkuxeJTXHt6PjCqC X-Gm-Gg: Acq92OHcK/tDou7GT0j03Joy0cP0u5HpxvV049wBwJGnWK6mxULWDYuXaoXG1oZxBMk PL4XWCVmS14RCGKju0s4BNE6Ta8R5bRr8kRFXH/qJyqX32sN71S1yDDWmeV0S4f9qgEmHDhD6xz kihdgT+E1Am2echO9CMPkO/TF8J0idQBFPggDApT5s174zO+Cn28LIjcBEqdERUia5zHog7WgLp TMhfBysflNNDd4z9OnXWrTKAuf//lv1KgevcguRSya31uwjv7nyX0KaC033xLzToGt8/7cU+2Dh o0dyG4gDEB+lp1TknhdZKTEpBrGmd8GkTq8a8Ahbooj7L+PgHvG74rl0h75FSZpbH5ltNozW1+f GHa0PEH+x/15NSvZEiZ9ixyxJ/0KO+2BmK7HcXTE3oCJNLWyXw0LzHwLCPt6MZ5E1PUKeFbfAvw RHwhZ8vLZxgg9tEEv9LFsAu6jp1P2Iirj3 X-Received: by 2002:a17:907:2d0d:b0:bce:a1fc:6877 with SMTP id a640c23a62f3a-bf37234ac00mr1075024666b.24.1781017995639; Tue, 09 Jun 2026 08:13:15 -0700 (PDT) Received: from Ansuel-XPS24 ([2.195.136.12]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-bf0517721e5sm1073637866b.9.2026.06.09.08.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 08:13:15 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Jonathan Corbet , Shuah Khan , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , Saravana Kannan , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev Subject: [PATCH net-next v6 05/12] net: phylink: support late PCS provider attach Date: Tue, 9 Jun 2026 17:12:01 +0200 Message-ID: <20260609151212.29469-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260609151212.29469-1-ansuelsmth@gmail.com> References: <20260609151212.29469-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add support for late PCS provider attachment to a phylink instance. This works by creating a global notifier for the PCS provider and making each phylink instance that makes use of fwnode subscribe to this notifier. The PCS notifier will emit the event FWNODE_PCS_PROVIDER_ADD every time a new PCS provider is added. phylink will then react to this event and will call the new function fwnode_phylink_pcs_get_from_fwnode() that will check if the PCS fwnode provided by the event is present in the pcs-handle property of the phylink instance. If a related PCS is found, then such PCS is added to the phylink instance PCS list. Then we link the PCS to the phylink instance if it's not disabled and we refresh the supported interfaces of the phylink instance. Finally we check if we are in a major_config_failed scenario and trigger an interface reconfiguration in the next phylink resolve. In the example scenario where the link was previously torn down due to removal of PCS, the link will be established again as the PCS came back and is now available to phylink. Signed-off-by: Christian Marangi --- drivers/net/pcs/pcs.c | 40 ++++++++++++++++++++++++++++++ drivers/net/phy/phylink.c | 52 +++++++++++++++++++++++++++++++++++++++ include/linux/pcs/pcs.h | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c index 72f56f55d198..911d95cf1b09 100644 --- a/drivers/net/pcs/pcs.c +++ b/drivers/net/pcs/pcs.c @@ -22,6 +22,13 @@ struct fwnode_pcs_provider { static LIST_HEAD(fwnode_pcs_providers); static DEFINE_MUTEX(fwnode_pcs_mutex); +static BLOCKING_NOTIFIER_HEAD(fwnode_pcs_notify_list); + +int register_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&fwnode_pcs_notify_list, nb); +} +EXPORT_SYMBOL_GPL(register_fwnode_pcs_notifier); struct phylink_pcs *fwnode_pcs_simple_get(struct fwnode_reference_args *pcsspec, void *data) @@ -55,6 +62,10 @@ int fwnode_pcs_add_provider(struct fwnode_handle *fwnode, fwnode_dev_initialized(fwnode, true); + blocking_notifier_call_chain(&fwnode_pcs_notify_list, + FWNODE_PCS_PROVIDER_ADD, + fwnode); + return 0; } EXPORT_SYMBOL_GPL(fwnode_pcs_add_provider); @@ -147,6 +158,35 @@ struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) } EXPORT_SYMBOL_GPL(fwnode_pcs_get); +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode) +{ + struct fwnode_reference_args pcsspec; + int index = 0; + int ret; + + /* Loop until we find a matching PCS node or + * fwnode_parse_pcsspec() returns error + * if we don't have any other PCS reference to check. + */ + while (true) { + ret = fwnode_parse_pcsspec(fwnode, index, NULL, &pcsspec); + if (ret) + return ERR_PTR(ret); + + /* Exit loop if we found the matching PCS node */ + if (pcsspec.fwnode == pcs_fwnode) + break; + + /* Check the next PCS reference */ + index++; + } + + return fwnode_pcs_get(fwnode, index); +} +EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_get_from_fwnode); + static int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode, unsigned int *num_pcs) { diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index b45bee927300..65b67c33e12f 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ struct phylink { /* List of available PCS */ struct list_head pcs_list; + struct notifier_block fwnode_pcs_nb; /* What interface are supported by the current link. * Can change on removal or addition of new PCS. @@ -1998,6 +2000,51 @@ static int phylink_fill_available_pcs(struct phylink *pl, return ret; } +static int pcs_provider_notify(struct notifier_block *self, + unsigned long val, void *data) +{ + struct phylink *pl = container_of(self, struct phylink, fwnode_pcs_nb); + struct fwnode_handle *pcs_fwnode = data; + struct phylink_pcs *pcs; + + /* Check if the just added PCS provider is + * in the phylink instance pcs-handle property. + */ + pcs = fwnode_phylink_pcs_get_from_fwnode(dev_fwnode(pl->config->dev), + pcs_fwnode); + if (IS_ERR(pcs)) + return NOTIFY_DONE; + + /* Add the PCS */ + rtnl_lock(); + + list_add(&pcs->list, &pl->pcs_list); + + /* Link phylink if we are started */ + if (!pl->phylink_disable_state) + pcs->phylink = pl; + + /* Refresh supported interfaces */ + phy_interface_copy(pl->supported_interfaces, + pl->config->supported_interfaces); + list_for_each_entry(pcs, &pl->pcs_list, list) + phy_interface_or(pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); + + mutex_lock(&pl->state_mutex); + /* Force an interface reconfig if major config fail */ + if (pl->major_config_failed) + pl->force_major_config = true; + mutex_unlock(&pl->state_mutex); + + rtnl_unlock(); + + phylink_run_resolve(pl); + + return NOTIFY_OK; +} + /** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config @@ -2053,6 +2100,11 @@ struct phylink *phylink_create(struct phylink_config *config, pl->supported_interfaces, pcs->supported_interfaces); + if (!phy_interface_empty(config->pcs_interfaces)) { + pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify; + register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); + } + pl->config = config; if (config->type == PHYLINK_NETDEV) { pl->netdev = to_net_dev(config->dev); diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h index 33244e3a442b..dfd3dc0f86f6 100644 --- a/include/linux/pcs/pcs.h +++ b/include/linux/pcs/pcs.h @@ -4,7 +4,24 @@ #include +enum fwnode_pcs_notify_event { + FWNODE_PCS_PROVIDER_ADD, +}; + #if IS_ENABLED(CONFIG_FWNODE_PCS) +/** + * register_fwnode_pcs_notifier - Register a notifier block for fwnode + * PCS events + * @nb: pointer to the notifier block + * + * Registers a notifier block to the fwnode_pcs_notify_list blocking + * notifier chain. This allows phylink instance to subscribe for + * PCS provider events. + * + * Returns: 0 or a negative error. + */ +int register_fwnode_pcs_notifier(struct notifier_block *nb); + /** * fwnode_pcs_get - Retrieves a PCS from a firmware node * @fwnode: firmware node @@ -20,6 +37,25 @@ struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index); +/** + * fwnode_phylink_pcs_get_from_fwnode - Retrieves the PCS provided + * by the firmware node from a + * firmware node + * @fwnode: firmware node + * @pcs_fwnode: PCS firmware node + * + * Parse 'pcs-handle' in 'fwnode' and get the PCS that match + * 'pcs_fwnode' firmware node. + * + * Returns: a pointer to the phylink_pcs or a negative + * error pointer. Can return -EPROBE_DEFER if the PCS is not + * present in global providers list (either due to driver + * still needs to be probed or it failed to probe/removed) + */ +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode); + /** * fwnode_phylink_pcs_parse - generic PCS parse for fwnode PCS provider * @fwnode: firmware node @@ -39,12 +75,24 @@ int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, struct phylink_pcs **available_pcs, unsigned int *num_pcs); #else +static inline int register_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return -EOPNOTSUPP; +} + static inline struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) { return ERR_PTR(-ENOENT); } +static inline struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode) +{ + return ERR_PTR(-ENOENT); +} + static inline int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, struct phylink_pcs **available_pcs, unsigned int *num_pcs) -- 2.53.0