From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82661C61DD3 for ; Tue, 1 Sep 2026 08:31:20 +0000 (UTC) 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-Owner; bh=tUE+/AHcRUnA8SePV2VdX4HXvQGh2hBEeQpD97QfJfY=; b=skbbfCaVzOReFRka/Q6dyXseDf cednxkyex23BTZScIRCVKY5a2sBa3ZA2e75a1zidKffZDlqFWABdZeZr7RT+4fSEXJe0FsXuZbvnE nvxdbl90lAzJXWbeGnQZ4DQTcscGr3aOrqMxCwuIZHfZ0d5FyztLKBEzcOCjZ+iG72z5AEmGUQ8Q6 I/Kol6vJdO6PYT9NQI7z6vJXdabjRvl79m/lSJtjzIFhcyrnFYNZh5Mbzr2Cx/GtYHmRhKdoECTzV i6zeGJfQtCcSb6Rh2O0tI1XlNehrxzg7ne/3O9z5+yJ3Ur+kmblIqqHATk7XbobG9Mh/ujVfn6Di7 OiP1/b8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1Jtb-0000000BHd0-1jIw; Tue, 01 Sep 2026 08:31:07 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1JtX-0000000BHYA-3jty for linux-arm-kernel@lists.infradead.org; Tue, 01 Sep 2026 08:31:05 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-6a668ce86abso270946a12.2 for ; Tue, 01 Sep 2026 01:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788251462; x=1788856262; 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=tUE+/AHcRUnA8SePV2VdX4HXvQGh2hBEeQpD97QfJfY=; b=fznR95HmmJ1VyICDhi5m6qkSIdtKcTDTutLd+WTEipEv6Ce85ZOZTvE52fdiHDjkdJ rrTN1F2zHyDkBQZ3cMzx0/4MihHIZ5vCH7JMu5EwMTp4UkfJkYlLb81YkXuDRWYD4Q9K Sn2JHtaUv+R/sMwTXY+s2M8peax5uEz325phIqZRs+gjx2dbUjAwztoeh3o8mlElMMe2 T7IjQns35ZwSxiHfA+uPUH2r+bmhmcoWf914HEugVSGJgc1g8ecAHbDmz0+RPO+cgfRt 99k0czSPn+9zoeTyK712T5CQoFWY9fe1RS159Ni1vQVcNECYR4//nXc1H9bPChry5euf 5Z1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788251462; x=1788856262; 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=tUE+/AHcRUnA8SePV2VdX4HXvQGh2hBEeQpD97QfJfY=; b=cfZbfRD8hIFENq1kACGLdBzJA4LZNXP4QEInCUeBHYxWAI2YSHsKe0k5gu3fYWC6xT 3U6gUNvrRGsHUjDdxGz4/B3jPvik9/PVneX8p8Kn9StxmZ3kkc7Lf1NsqvdB+qeuf3J/ lZxHQ4MpKzej5T/u9trRdb9yF1plGIeGKCpaG+fBG+njS3GG4n+cmIdctuUMn64ENQJp /yqGhgcLeyXBd2MuymkYvTTAbpX5y/xnR5uWw7AC/ySZUitWwBt2xSnbKIe4I+AVFMAM iyCNIdCWPceWkQnX4Vb6pfkcKz7i5dvvswUMZ4rlb6VWD9nabgsfXqt3UfJoUW2dZqqM OR3A== X-Forwarded-Encrypted: i=1; AHgh+Rojm9oaY+2phRgVXHZkM94swZFetbStOITX4THYBm4gr4HZ6oBqmYKga7ZQIxJoS98yCKkGPF9NMuK8ZFRZrzhG@lists.infradead.org X-Gm-Message-State: AFuF++k+NyZh48S5m1LysgW+nuHfR/oUmAMyyJf1gy7z3AvZELlI/tCq Nh3rssu6bC/MxM+24X53asgdgExt6Ui2oFYB4+XOK1hMs7ugxoKw6sQM X-Gm-Gg: AR+sD12lKKDZwub99PTiZ8qyDJ5DthYVOSMtEyCJaPLfO0PDeFB/mHO7cFR1eLLvK6W /3DZGep93LfsBw2pSmccmM74PpmM74bc9Jt70qlCBiQfFmHF3dSsFbI3ag1e/fgDeIYdHAYZI7i X/KwhQ32OgwkD2moGcFi8NHTusHv4IU4DRWdQ3OXGCRYibTJJ7t/Ej8H/2ibwbDejCHs6nG/E62 Xw7KSVUNQ2J8cEKQpo2ueQu82oQKrdceoetYwSl8VSPTeZ0+ODvCB9dSrKpDXpKy5zt4/dtoXd8 8vfXesG4mSIgZojx5egqCWDnxEyiMbt8PDQWjcWRPbELK+56mVRXsf7zYw3ATA0fXIrtheQKR+2 BXuq78RB9LSWKg2W1gAXuvA9AQ54HSJcymJ3SF7dOqpvrHM0r9XuIRZfkKQSmeGe1gmSgZH1fAY zSPCW++0BTqDri83AXyN6GjW+qvxuQd0BLpK9FF3u/KCHNzi0WRU8VQ0NEXZYsJJqTn2JnbR8KN AbPbZ+LEbvbeR5InyCZlOXwfqMB0lcerBH8vxrg7pWX4gz222ZAz8+CRcmd3cM= X-Received: by 2002:a05:600c:4705:b0:499:dbae:43d3 with SMTP id 5b1f17b1804b1-49cdc452433mr99372965e9.9.1788251426480; Tue, 01 Sep 2026 01:30:26 -0700 (PDT) Received: from Ansuel-XPS24.localdomain (host-79-26-252-140.retail.telecomitalia.it. [79.26.252.140]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49cdce08862sm51459635e9.1.2026.09.01.01.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 01:30:25 -0700 (PDT) From: Christian Marangi To: Maxime Chevallier , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Jonathan Corbet , Shuah Khan , Randy Dunlap , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , 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 v15 05/12] net: phylink: support PCS provider release Date: Tue, 1 Sep 2026 10:29:20 +0200 Message-ID: <20260901083001.8044-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260901083001.8044-1-ansuelsmth@gmail.com> References: <20260901083001.8044-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260901_013104_098584_B8172E58 X-CRM114-Status: GOOD ( 35.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for release of fwnode PCS from a PCS provider. 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_DEL every time a new PCS provider is released. phylink will then react to this event and will call the new function fwnode_pcs_matches_provider() on each PCS of the phylink instance and will check if the PCS is provided by the PCS provider that is getting released. If a related PCS is found, then such PCS is removed from the phylink instance PCS list and the supported_interfaces value is updated. The flag force_major_config is set to make phylink resolve reconfigure the interface (even if it didn't change). This is needed to handle the special case when the current PCS used by phylink is removed and a major_config is needed to propagae the configuration change. With this option enabled we also force mac_config even if the PHY link is not up for the in-band case. Finally a phylink resolve is triggered to handle the PCS removal. Protect every access of phylink pcs_list with state_mutex to handle async PCS provider release. Signed-off-by: Christian Marangi --- drivers/net/pcs/pcs.c | 47 +++++++++++++ drivers/net/phy/phylink.c | 141 ++++++++++++++++++++++++++++++++++++-- include/linux/pcs/pcs.h | 69 +++++++++++++++++++ 3 files changed, 250 insertions(+), 7 deletions(-) diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c index 39550d9a12a2..25b3248e8b93 100644 --- a/drivers/net/pcs/pcs.c +++ b/drivers/net/pcs/pcs.c @@ -22,6 +22,19 @@ 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); + +int unregister_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&fwnode_pcs_notify_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_fwnode_pcs_notifier); struct phylink_pcs *fwnode_pcs_simple_xlate(struct fwnode_reference_args *pcsspec, void *data) @@ -74,6 +87,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp) mutex_unlock(&fwnode_pcs_mutex); + /* Signal phylink to release any PCS from this provider */ + blocking_notifier_call_chain(&fwnode_pcs_notify_list, + FWNODE_PCS_PROVIDER_DEL, + pp); + fwnode_handle_put(pp->fwnode); kfree(pp); } @@ -183,6 +201,35 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned } EXPORT_SYMBOL_GPL(fwnode_pcs_get); +bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider, + const struct fwnode_handle *fwnode, + struct phylink_pcs *pl_pcs) +{ + struct fwnode_reference_args pcsspec; + int index = 0; + int ret; + + while (true) { + struct phylink_pcs *pcs; + + ret = fwnode_parse_pcsspec(fwnode, index, NULL, &pcsspec); + if (ret) + return false; + + pcs = __fwnode_pcs_get_from_pcsspec_provider(&pcsspec, provider); + if (!IS_ERR(pcs) && pcs == pl_pcs) { + fwnode_handle_put(pcsspec.fwnode); + return true; + } + + fwnode_handle_put(pcsspec.fwnode); + index++; + } + + return false; +} +EXPORT_SYMBOL_GPL(fwnode_pcs_matches_provider); + unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode) { struct fwnode_reference_args out_args; diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 96f72eb5a6fa..e88c1effe880 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,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. @@ -545,11 +547,15 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, unsigned long capabilities; int ret; + mutex_lock(&pl->state_mutex); + /* Get the PCS for this interface mode */ if (pl->mac_ops->mac_select_pcs) { pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); - if (IS_ERR(pcs)) + if (IS_ERR(pcs)) { + mutex_unlock(&pl->state_mutex); return PTR_ERR(pcs); + } /* * Find a PCS in available PCS list for the requested interface. * @@ -573,6 +579,7 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, * error and backtrace rather than oopsing the kernel. */ if (!pcs->ops) { + mutex_unlock(&pl->state_mutex); phylink_err(pl, "interface %s: uninitialised PCS\n", phy_modes(state->interface)); dump_stack(); @@ -582,6 +589,7 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, /* Recheck PCS to handle legacy way for .mac_select_pcs */ ret = phylink_validate_pcs_interface(pcs, state->interface); if (ret) { + mutex_unlock(&pl->state_mutex); phylink_err(pl, "selected PCS does not support %s\n", phy_modes(state->interface)); return -EINVAL; @@ -590,8 +598,10 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, /* Validate the link parameters with the PCS */ if (pcs->ops->pcs_validate) { ret = pcs->ops->pcs_validate(pcs, supported, state); - if (ret < 0 || phylink_is_empty_linkmode(supported)) + if (ret < 0 || phylink_is_empty_linkmode(supported)) { + mutex_unlock(&pl->state_mutex); return -EINVAL; + } /* Ensure the advertising mask is a subset of the * supported mask. @@ -601,6 +611,8 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, } } + mutex_unlock(&pl->state_mutex); + /* Then validate the link parameters with the MAC */ if (pl->mac_ops->mac_get_caps) capabilities = pl->mac_ops->mac_get_caps(pl->config, @@ -996,6 +1008,9 @@ static unsigned int phylink_inband_caps(struct phylink *pl, phy_interface_t interface) { struct phylink_pcs *pcs = NULL; + int ret = 0; + + mutex_lock(&pl->state_mutex); if (pl->mac_ops->mac_select_pcs) { pcs = pl->mac_ops->mac_select_pcs(pl->config, @@ -1012,9 +1027,14 @@ static unsigned int phylink_inband_caps(struct phylink *pl, } if (IS_ERR_OR_NULL(pcs)) - return 0; + goto exit; + + ret = phylink_pcs_inband_caps(pcs, interface); + +exit: + mutex_unlock(&pl->state_mutex); - return phylink_pcs_inband_caps(pcs, interface); + return ret; } static void phylink_pcs_poll_stop(struct phylink *pl) @@ -1555,7 +1575,9 @@ static void phylink_mac_initial_config(struct phylink *pl, bool force_restart) phylink_apply_manual_flow(pl, &link_state); if (phy) mutex_lock(&phy->lock); + mutex_lock(&pl->state_mutex); phylink_major_config(pl, force_restart, &link_state); + mutex_unlock(&pl->state_mutex); if (phy) mutex_unlock(&phy->lock); } @@ -1923,6 +1945,9 @@ static int phylink_fill_available_pcs(struct phylink *pl, if (!pcss) return -ENOMEM; + /* Lock state_mutex while filling to handle PCS notify */ + mutex_lock(&pl->state_mutex); + ret = config->fill_available_pcs(config, pcss, config->num_possible_pcs); if (ret < 0) goto out; @@ -1937,11 +1962,89 @@ static int phylink_fill_available_pcs(struct phylink *pl, } out: + mutex_unlock(&pl->state_mutex); + kfree(pcss); return ret; } +static void phylink_del_pcs(struct phylink *pl, struct phylink_pcs *pcs) +{ + lockdep_assert_held(&pl->state_mutex); + + list_del(&pcs->list); + pcs->phylink = NULL; + + /* + * Check if we are removing the PCS currently + * in use by this phylink instance. If this is the case, + * tear down the link, force phylink resolve to reconfigure the + * interface mode, disable the current PCS and set the + * phylink PCS to NULL. + */ + if (pl->pcs == pcs) { + if (pl->old_link_state) { + phylink_link_down(pl); + pl->old_link_state = false; + } + if (pl->cfg_link_an_mode == MLO_AN_INBAND) + timer_delete_sync(&pl->link_poll); + phylink_pcs_disable(pl->pcs); + + pl->force_major_config = true; + WRITE_ONCE(pl->pcs, NULL); + } +} + +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_pcs_provider *pp = data; + struct phylink_pcs *pcs, *tmp; + bool resolve = false; + + rtnl_lock(); + + mutex_lock(&pl->state_mutex); + + /* + * Loop all the PCS for phylink instance and check if + * this notification is relevant for some of them. + */ + list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) { + if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs)) + continue; + + phylink_del_pcs(pl, pcs); + resolve = true; + } + + /* Exit early if nothing has changed */ + if (!resolve) { + mutex_unlock(&pl->state_mutex); + rtnl_unlock(); + return NOTIFY_DONE; + } + + /* 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_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 @@ -2030,10 +2133,18 @@ struct phylink *phylink_create(struct phylink_config *config, __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); timer_setup(&pl->link_poll, phylink_fixed_poll, 0); + /* First register notifier for hotplug PCS events */ + if (!phy_interface_empty(config->pcs_interfaces)) { + pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify; + register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); + } + /* Fill the PCS list with available PCS from phylink config */ ret = phylink_fill_available_pcs(pl, config); if (ret < 0) - goto free_pl; + goto unregister_pcs_notify; + + mutex_lock(&pl->state_mutex); /* Link available PCS to phylink */ list_for_each_entry(pcs, &pl->pcs_list, list) @@ -2048,13 +2159,15 @@ struct phylink *phylink_create(struct phylink_config *config, pl->supported_interfaces, pcs->supported_interfaces); + mutex_unlock(&pl->state_mutex); + linkmode_fill(pl->supported); linkmode_copy(pl->link_config.advertising, pl->supported); phylink_validate(pl, pl->supported, &pl->link_config); ret = phylink_parse_mode(pl, fwnode); if (ret < 0) - goto unlink_pcs_list; + goto unregister_pcs_notify; if (pl->cfg_link_an_mode == MLO_AN_FIXED) { ret = phylink_parse_fixedlink(pl, fwnode); @@ -2073,11 +2186,17 @@ struct phylink *phylink_create(struct phylink_config *config, release_link_gpio: if (pl->link_gpio) gpiod_put(pl->link_gpio); -unlink_pcs_list: +unregister_pcs_notify: + if (pl->fwnode_pcs_nb.notifier_call) + unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); + /* PCS notifier might queue a resolve, cancel it */ + cancel_work_sync(&pl->resolve); + mutex_lock(&pl->state_mutex); list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) { list_del(&pcs->list); pcs->phylink = NULL; } + mutex_unlock(&pl->state_mutex); free_pl: fwnode_handle_put(pl->fwnode); kfree(pl); @@ -2102,14 +2221,22 @@ void phylink_destroy(struct phylink *pl) if (pl->link_gpio) gpiod_put(pl->link_gpio); + /* Unregister notifier for late PCS attach */ + if (pl->fwnode_pcs_nb.notifier_call) + unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); + cancel_work_sync(&pl->resolve); + mutex_lock(&pl->state_mutex); + /* Remove every PCS from phylink PCS list */ list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) { pcs->phylink = NULL; list_del(&pcs->list); } + mutex_unlock(&pl->state_mutex); + fwnode_handle_put(pl->fwnode); kfree(pl); diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h index ef2134c578c7..83e0a2ad4b09 100644 --- a/include/linux/pcs/pcs.h +++ b/include/linux/pcs/pcs.h @@ -4,7 +4,38 @@ #include +enum fwnode_pcs_notify_event { + FWNODE_PCS_PROVIDER_DEL, +}; + +struct fwnode_pcs_provider; + #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); + +/** + * unregister_fwnode_pcs_notifier - Unregister a notifier block for fwnode + * PCS events + * @nb: pointer to the notifier block + * + * Unregisters a notifier block to the fwnode_pcs_notify_list blocking + * notifier chain. + * + * Returns: 0 or a negative error. + */ +int unregister_fwnode_pcs_notifier(struct notifier_block *nb); + /** * fwnode_pcs_get - Retrieves a PCS from a firmware node * @fwnode: firmware node @@ -19,6 +50,27 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned int index); +/** + * fwnode_pcs_matches_provider() - Check whether a PCS belongs to a provider + * @provider: PCS provider to check + * @fwnode: firmware node containing the PCS references + * @pl_pcs: PCS to check + * + * Parse the PCS references from the "pcs-handle" property of a firmware node + * and use provider to determine whether pl_pcs is one of the PCS provided by + * provider. + * + * This function is intended to be used when handling provider removal + * notifications, where the provider is already known and its PCS need to be + * identified among the PCS associated with a phylink instance. + * + * Returns: true if pl_pcs is provided by provider and referenced by fwnode, + * false otherwise. + */ +bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider, + const struct fwnode_handle *fwnode, + struct phylink_pcs *pl_pcs); + /** * fwnode_phylink_pcs_count - Count PCS entries described in firmware node * @fwnode: firmware node @@ -52,12 +104,29 @@ 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 int unregister_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return -EOPNOTSUPP; +} + static inline struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned int index) { return ERR_PTR(-ENOENT); } +static inline bool fwnode_pcs_matches_provider(struct fwnode_pcs_provider *provider, + const struct fwnode_handle *fwnode, + struct phylink_pcs *pl_pcs) +{ + return false; +} + static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode) { return 0; -- 2.53.0