From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 B9AC33A1A56 for ; Fri, 7 Aug 2026 13:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786108422; cv=none; b=mHF+9Ah4DbGlteyFHjwi1w+RX3CmgbPR9jlIB4OE6O20cYp35faBMhqhdfa1iDoGLsuraFm0Tm/3D4HImdLdMCgyRuD/fIe9k3I3+fvfiZsDgtSP6f1p1odhdmnE5JMDnD8vao7KkGygrjruk+8ry6i84hFHVF4edf0pYa/Ls1U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786108422; c=relaxed/simple; bh=ba4srmJjbKaGqj6HGorI8a8yb+ln3b0tpz+lu7FE4xI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o3IpPTK0OVIkAq5GSy4LmjEVl5K9tpmnesYa64Yq/8MvKEXb5TfQjiK31VazGC8Lgq7wpgwcciVT24NjcfdaCglaHVUqEYOc6wQeQgH0nelvuKcUphnKqvUFJz3I/iy3QUERc7u9HniysDaXWrSWlQ2Rh+vLYbEOiF36xVVAuzY= 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=cDAxEe8o; arc=none smtp.client-ip=209.85.128.42 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="cDAxEe8o" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-49553515a8bso50276335e9.1 for ; Fri, 07 Aug 2026 06:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786108403; x=1786713203; 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=blS9NW+z3RT1qmTbb7noUDEOOGBTlMXIPyRXJKnltKc=; b=cDAxEe8oC84XjxBHboNwMfEgxR9GMBIETTjBkeiWM5rY/pvmbfu/v4IgTInEFoXpIu ykNwSrrAlnkKNOoKQR30LYrTRg36BOneN1mNG0EJVRoCkG/fJ3vevFdhkyoU9OHspARg kdymGv2kRr9DX/szoqcIYMkpi2QbJnhLf3lUiS0ybDS+ZUGc04jWGf7MeBezA1rj7fMt BrgFpdGhLbaH/LJBPf29z6FLg6DQTt6Jt89vzXGl0Qb0Fl6amIXA1XMYquL8lqH+ynfq V2ODLeY/R5rqJAshFIs+U7/LNb2ATJPrgZZ/Xy9xKZHKKKNU40wJiC2NaeOqSPY/MaHR 1BBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786108403; x=1786713203; 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=blS9NW+z3RT1qmTbb7noUDEOOGBTlMXIPyRXJKnltKc=; b=AAKh7ZsVoCm+xjr6DDTjMPMjQFtN1AQbla7VQYNX1cYrc0vwn6YtPlV7O7FNW6i06x H3t1oO1wsXUFYFxuOrVlERWLBJOORNsM0y1RR8HpG5+eycz3fdZW2ytGTX5fKUkRyEso zvUI2PXMSE5Hjp+pBVfOyvRa9kS19fRyo0kiG5ZFjPvHs8W6xdYrzuISdVPY+028eurI 0pQshYCfUbjHFaA2kzuYXiMJb0KDS77VIdHG28ejqFkQut8qlDfLffLNceTMh2p8CD18 i1Dnj6mM2U4u/43BWGqUs7uSG3P7tWN2tE6XcA7MUWAjpO7Sw62iddGSyslxvhMUbUKv JI6w== X-Forwarded-Encrypted: i=1; AHgh+Rp7fvUWLbjE4C21oBwoy90xafKfip5szLTWzqxnBZYYktFjB+EMZgDv8J18tAkoqgiF4Ues7l8HQ0E+@vger.kernel.org X-Gm-Message-State: AOJu0YwH5o8cS76YhZD0IH1sNWAceo2kdznWyOrjFrPUipvP9OBSimiQ g1ha7FC5vj4VrDdeSli9Od9r5JywfBGFQBnGkgxPrFe9x3MiYYkv2eWB X-Gm-Gg: AR+sD10GTcwiwe4DG8GRwMxJW8d+vSwdmQwxfCC1TYbqUHEZI60b0WOkweOQQhfMVpI ZIakY9Pq5S23fL/o12wLFnqVlDfhMdIdHzLWVbkBpwwt8V1R1uLDaLzOu8aqD9fiiSuNyV+h4Bj lgAy/3NCTIIAumk2Ly65Fi+Cs6yT5eXbx5IrTjIpcdjDkm49ok9l9qdtuY017vXGuH9izQfHRes 0G0tOBHD0w8v3zeVm4ErwpsWW7StaKpwP5qZvWRA83y6ZM9K0R3Ain6qk0w9c93tSZ0DwcGMsKC K3EdPCHqk/Td76NS9dxEvfA+j6MjCvHIf+A7NAzSTxicR8EQbYUH2YZaq+pLJ+UCmyR0JmBkZdC dzrFmCXSjMsMRi0wDOn3X+zmX72BWPcObXRPHno9a6Z90OcP1QO15ocC9gFR1q87Swcs9dR+Hkf HiQV34V76xvTh4T4sH69En6fNQAUVWEJlJ+ZD5ADL+s2ZL26nc5roqfJa2La3uzqs19FwVep31m t/7JpPH/93EaLgruFrpsPijDU8HR2oOdsDIcJ2nCZGu1WqKbYjUNg== X-Received: by 2002:a05:600c:35c8:b0:498:28b:1025 with SMTP id 5b1f17b1804b1-49959e08745mr106956245e9.5.1786108402637; Fri, 07 Aug 2026 06:13:22 -0700 (PDT) Received: from Ansuel-XPS24.localdomain (host-87-19-255-168.retail.telecomitalia.it. [87.19.255.168]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4995c7b2b68sm58827665e9.4.2026.08.07.06.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2026 06:13:22 -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 , 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 v11 05/12] net: phylink: support PCS provider release Date: Fri, 7 Aug 2026 15:12:47 +0200 Message-ID: <20260807131301.192060-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260807131301.192060-1-ansuelsmth@gmail.com> References: <20260807131301.192060-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_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 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. Signed-off-by: Christian Marangi --- drivers/net/pcs/pcs.c | 50 ++++++++++++++++++++++++ drivers/net/phy/phylink.c | 82 ++++++++++++++++++++++++++++++++++++++- include/linux/pcs/pcs.h | 65 +++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c index 7f6d9941c1e3..f575fbed896d 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_get(struct fwnode_reference_args *pcsspec, void *data) @@ -67,6 +80,11 @@ void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp) mutex_lock(&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); + list_del(&pp->link); fwnode_dev_initialized(pp->fwnode, false); fwnode_handle_put(pp->fwnode); @@ -178,6 +196,38 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned } EXPORT_SYMBOL_GPL(fwnode_pcs_get); +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(const 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) { + fwnode_handle_put(pcsspec.fwnode); + break; + } + + /* Check the next PCS reference */ + fwnode_handle_put(pcsspec.fwnode); + index++; + } + + return fwnode_pcs_get(fwnode, index); +} +EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_get_from_fwnode); + 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 041405ce6bf0..548e783ae2aa 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. @@ -1929,6 +1931,8 @@ static int phylink_fill_available_pcs(struct phylink *pl, if (ret < 0) goto out; + mutex_lock(&pl->state_mutex); + for (i = 0; i < config->num_possible_pcs; i++) { struct phylink_pcs *pcs = pcss[i]; @@ -1938,12 +1942,72 @@ static int phylink_fill_available_pcs(struct phylink *pl, list_add_tail(&pcs->list, &pl->pcs_list); } + mutex_unlock(&pl->state_mutex); + out: kfree(pcss); return ret; } +static void phylink_del_pcs(struct phylink *pl, struct phylink_pcs *pcs) +{ + 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); + const struct fwnode_handle *pl_fwnode = pl->fwnode; + struct fwnode_handle *pcs_fwnode = data; + struct phylink_pcs *pcs; + + /* Check if the PCS provider is relevant for this phylink instance */ + pcs = fwnode_phylink_pcs_get_from_fwnode(pl_fwnode, pcs_fwnode); + if (IS_ERR(pcs)) + return NOTIFY_DONE; + + mutex_lock(&pl->state_mutex); + + phylink_del_pcs(pl, pcs); + + /* 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); + + phylink_run_resolve(pl); + + return NOTIFY_OK; +} + /** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config @@ -2000,10 +2064,18 @@ struct phylink *phylink_create(struct phylink_config *config, goto free_pl; } + /* 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) @@ -2018,6 +2090,8 @@ struct phylink *phylink_create(struct phylink_config *config, pl->supported_interfaces, pcs->supported_interfaces); + mutex_unlock(&pl->state_mutex); + pl->mac_supports_eee_ops = phylink_mac_implements_lpi(mac_ops); pl->mac_supports_eee = pl->mac_supports_eee_ops && pl->config->lpi_capabilities && @@ -2073,6 +2147,8 @@ struct phylink *phylink_create(struct phylink_config *config, list_del(&pcs->list); pcs->phylink = NULL; } +unregister_pcs_notify: + unregister_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); free_pl: kfree(pl); return ERR_PTR(ret); @@ -2096,6 +2172,10 @@ 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); diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h index 08132f3f70f4..f9dcbf58d053 100644 --- a/include/linux/pcs/pcs.h +++ b/include/linux/pcs/pcs.h @@ -4,7 +4,36 @@ #include +enum fwnode_pcs_notify_event { + FWNODE_PCS_PROVIDER_DEL, +}; + #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 @@ -20,6 +49,25 @@ struct phylink_pcs *fwnode_pcs_get(const struct fwnode_handle *fwnode, unsigned 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(const struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode); + /** * fwnode_phylink_pcs_count - count PCS entries described in firmware node * @fwnode: firmware node @@ -53,12 +101,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 struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(const struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode) +{ + return ERR_PTR(-ENOENT); +} + static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode) { return 0; -- 2.53.0