From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=85.214.127.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477894; b=Hxr98yCnoiZ5SEEvHPruiEQiGjwHtUWCWgOcQmc5igjPohP5qtTXQb8yxrRg4grZW4U+ m+BoQdVn5zkDUqKc8lhmpapfVjhxY6QTAhXwZMF4mMzTUeGg9uMPEFo62dO81n4rQmy8Y YdodHeO3oKkXEmP0gTD43INFNp2sIZ5vsAr3hbHSBmsDY9eGjgktf5QCaGJbPc/xBpvrS siEf++cm8SvaU45cBZZzrlXW7kD8hNW06aKq3xceB4M2UfkR0Vz5JFGG97sVGQDjcacUM ktAK7XGVrx7/4T51E4gU+yws1W7ss1XCUu6x2h7/XjZT+i4Jr2XDUmd7+z8FVWQXiXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477894; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=AvwacEqGUX9OBkrlCvhZ0wQizHgEc5wqOmr1RHDpLr8=; b=BDjjPuDfiNN9X/NSfWeao6EWza0QzKJK/rdlwSmzjYKi9N2gC4eI6sHF883j8/uZmqMB KgftNXV9NP7vRse1A2NsAzT4lU92v5uK5LGZixl2cf3iS0Zbd0ip1TlaZ/gUSbTtzvzol cO8lknYGr9oKZ4VYI7aNLSFhr2RLtmbbL1v6bhuhD+5XZBXCkoqOBIpIPItk/I6snGZjJ dRl/Q2t50KBLSgPc7b86mIoOkU8EUHEbSGryZFXwciQkere0GJwzBNBxH1ouQgCXE0lQp Hgq54oiQF4acPtZAdaAzFxlTcJZTtDN9wBab//6F8XtOF19T/cnq4wODqyDCFbcCegA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=szelinsky.de; spf=pass smtp.mailfrom=szelinsky.de; dkim=temperror header.d=szelinsky.de header.i=@szelinsky.de header.a=rsa-sha256 header.s=mail header.b=kFkzWNoF; arc=none smtp.remote-ip=85.214.127.56 Received: from szelinsky.de (szelinsky.de [85.214.127.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7E99606A322; Sat, 5 Dec 2026 13:38:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7E99606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=szelinsky.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=szelinsky.de Authentication-Results: smtp.subspace.kernel.org; dkim=temperror header.d=szelinsky.de header.i=@szelinsky.de header.a=rsa-sha256 header.s=mail header.b=kFkzWNoF Received: from localhost (localhost [127.0.0.1]) by szelinsky.de (Postfix) with ESMTP id 04C07E83148; Sat, 05 Dec 2026 14:38:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szelinsky.de; s=mail; t=1796477886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AvwacEqGUX9OBkrlCvhZ0wQizHgEc5wqOmr1RHDpLr8=; b=kFkzWNoFJfQqoduj25ysoVKjgX/WccyMSAKAbdEe26PQKZa27m5E0Avw8GjWcXIOnrzdEw vumfQ4gdvwkobeKmPyTqfcdAPLrI1EhMDKo6+l/ae1/Y2WjqQPru1GShseF82o5DR0ZrwM KTib8gFjlWc3uKyLd9USv5ONRMuGykyRa3/zNI9tejxATIPacsSdZcXSgm6PUr73o9kDKE 9ynXUse8jMjzMcKn0LpovUtvoZ6FSQNqSYyuQi5/Um6mOcdtiWNuTayKZYda08LZ0MNxz7 NCbZdg+yWRktA05fYrlAY15nX4YiV817SKRPbMl5LafaRNDj0dQN4dpN9Zv+Tg== X-Virus-Scanned: Debian amavis at szelinsky.de Received: from szelinsky.de ([127.0.0.1]) by localhost (szelinsky.de [127.0.0.1]) (amavis, port 10025) with ESMTP id 62Xttl205rK4; Sat, 5 Dec 2026 14:38:05 +0100 (CET) Received: from p14sgen5.netbird.selfhosted (dslb-088-070-183-026.088.070.pools.vodafone-ip.de [88.70.183.26]) by szelinsky.de (Postfix) with ESMTPSA; Sat, 05 Dec 2026 14:38:05 +0100 (CET) From: Carlo Szelinsky To: Oleksij Rempel , Kory Maincent Cc: Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lee Jones , Pavel Machek , Jonas Jelonek , Ross Cawston , netdev@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v7 1/2] net: pse-pd: add devm_pse_poll_helper() Date: Sat, 5 Dec 2026 14:37:41 +0100 Message-ID: <20261205133742.905114-2-github@szelinsky.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205133742.905114-1-github@szelinsky.de> References: <20261205133742.905114-1-github@szelinsky.de> X-Mailing-List: linux-leds@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 Some PSE controllers have no interrupt line, or the board does not wire it. The PSE core then never learns when a PD is plugged in or removed. Userspace gets no ethtool notifications, and the static budget strategy does not work: it only powers a port after the IRQ handler has reported a PD. Let these controllers report the same events by polling. The driver passes the same pse_irq_desc as for devm_pse_irq_helper(). The core calls its map_event() about every 500 ms and handles the events like the IRQ handler does. The interval is fixed, as no driver needs another one yet. With the "disabled" budget strategy, a polled controller keeps the power control in hardware, like a controller without events does today. The core only takes it over for an IRQ controller, which it expects to report a PD while the port is off. Update the comments that say events need an IRQ. Signed-off-by: Carlo Szelinsky --- drivers/net/pse-pd/pse_core.c | 209 ++++++++++++++++++++++++++++------ include/linux/pse-pd/pse.h | 18 ++- 2 files changed, 185 insertions(+), 42 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 0477cf6787bd..07cbc585a898 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -14,10 +14,33 @@ #include #include #include +#include #include #define PSE_PW_D_LIMIT INT_MAX +/* Fast enough for PD events, low load on the I2C bus */ +#define PSE_POLL_INTERVAL_MS 500 + +/** + * struct pse_poll - poll state of a PSE controller + * @pcdev: the polled PSE controller + * @work: delayed work that polls the controller + * @desc: copy of the driver's event description + * @notifs: per-PI events of the current poll + * @notifs_mask: PIs with events in the current poll + * @err: 0 if the last poll worked, else the first error since then, to + * log only changes + */ +struct pse_poll { + struct pse_controller_dev *pcdev; + struct delayed_work work; + struct pse_irq_desc desc; + unsigned long *notifs; + unsigned long *notifs_mask; + int err; +}; + static DEFINE_MUTEX(pse_list_mutex); static LIST_HEAD(pse_controller_list); static DEFINE_XARRAY_ALLOC(pse_pw_d_map); @@ -392,8 +415,8 @@ static void pse_pw_d_retry_power_delivery(struct pse_controller_dev *pcdev, * @pw_d: a pointer to the PSE power domain * * This function determines whether the power control for a specific power - * domain is managed by software in the interrupt handler rather than directly - * by hardware. + * domain is managed by software in the event handler (IRQ or poll) rather + * than directly by hardware. * * Software power control is active in the following cases: * - When the budget evaluation strategy is set to static @@ -623,9 +646,9 @@ static int _pse_pi_delivery_power_sw_pw_ctrl(struct pse_controller_dev *pcdev, struct pse_pi *pi = &pcdev->pi[id]; int ret, pw_req; - /* pse_isr(), a priority change and the retry after a disable all - * power a PI through here, so stop them here once unregistering - * has started. + /* The event handler, a priority change and the retry after a + * disable all power a PI through here, so stop them here once + * unregistering has started. */ if (pcdev->unregistering) return -ENODEV; @@ -907,7 +930,7 @@ static void pse_pw_d_release(struct kref *kref) } /* Clear pi[id].pw_d before the domain's reference is dropped. The PI - * regulator ops and pse_isr() hold pcdev->lock while they use it. + * regulator ops and the event handler hold pcdev->lock while they use it. */ static struct pse_power_domain * pse_pi_take_pw_d(struct pse_controller_dev *pcdev, int id) @@ -1119,6 +1142,20 @@ int pse_controller_register(struct pse_controller_dev *pcdev) goto free_kfifo; } + if (pcdev->poll) { + struct pse_poll *poll = pcdev->poll; + + poll->notifs = devm_kzalloc_objs(pcdev->dev, *poll->notifs, + pcdev->nr_lines); + poll->notifs_mask = devm_bitmap_zalloc(pcdev->dev, + pcdev->nr_lines, + GFP_KERNEL); + if (!poll->notifs || !poll->notifs_mask) { + ret = -ENOMEM; + goto free_kfifo; + } + } + ret = of_load_pse_pis(pcdev); if (ret) goto free_kfifo; @@ -1171,6 +1208,11 @@ int pse_controller_register(struct pse_controller_dev *pcdev) list_add(&pcdev->list, &pse_controller_list); mutex_unlock(&pse_list_mutex); + if (pcdev->poll) + queue_delayed_work(system_freezable_power_efficient_wq, + &pcdev->poll->work, + msecs_to_jiffies(PSE_POLL_INTERVAL_MS)); + return 0; free_kfifo: @@ -1193,12 +1235,11 @@ void pse_controller_unregister(struct pse_controller_dev *pcdev) pcdev->unregistering = true; mutex_unlock(&pcdev->lock); - /* Stop the IRQ and the notification worker first: pse_isr() uses - * pcdev->pi and the power domains that pse_flush_pw_ds() drops, - * and the worker reads the kfifo that is freed below. - */ + /* Stop all event handling first, it uses what is freed below */ if (pcdev->irq) disable_irq(pcdev->irq); + if (pcdev->poll) + cancel_delayed_work_sync(&pcdev->poll->work); /* Unlink before the PI array is freed: of_pse_control_get() walks * the list and reads pcdev->pi[]. */ @@ -1326,48 +1367,38 @@ static int pse_set_config_isr(struct pse_controller_dev *pcdev, int id, } /** - * pse_isr - IRQ handler for PSE - * @irq: irq number - * @data: pointer to user interrupt structure + * pse_handle_events - Handle the events of the PIs in @notifs_mask + * @pcdev: a pointer to the PSE controller device + * @pi_notifs: per-PI notification array + * @notifs_mask: bitmap of PIs with events (sized for pcdev->nr_lines) * - * Return: irqreturn_t - status of IRQ + * Shared by the IRQ and the poll path. Caller must hold pcdev->lock. */ -static irqreturn_t pse_isr(int irq, void *data) +static void pse_handle_events(struct pse_controller_dev *pcdev, + unsigned long *pi_notifs, + unsigned long *notifs_mask) { - struct pse_controller_dev *pcdev; - struct pse_irq_desc *desc; - struct pse_irq *h = data; - int ret, i; + int i; - desc = &h->desc; - pcdev = h->pcdev; + lockdep_assert_held(&pcdev->lock); - /* Clear notifs mask */ - memset(h->notifs, 0, pcdev->nr_lines * sizeof(*h->notifs)); - bitmap_zero(h->notifs_mask, pcdev->nr_lines); - mutex_lock(&pcdev->lock); - ret = desc->map_event(irq, pcdev, h->notifs, h->notifs_mask); - if (ret || bitmap_empty(h->notifs_mask, pcdev->nr_lines)) { - mutex_unlock(&pcdev->lock); - return IRQ_NONE; - } - - for_each_set_bit(i, h->notifs_mask, pcdev->nr_lines) { + for_each_set_bit(i, notifs_mask, pcdev->nr_lines) { unsigned long notifs, rnotifs; struct pse_ntf ntf = {}; + int ret; /* Do nothing PI not described */ if (!pcdev->pi[i].rdev) continue; - notifs = h->notifs[i]; + notifs = pi_notifs[i]; if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[i].pw_d)) { ret = pse_set_config_isr(pcdev, i, notifs); if (ret) notifs |= ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR; } - dev_dbg(h->pcdev->dev, + dev_dbg(pcdev->dev, "Sending PSE notification EVT 0x%lx\n", notifs); ntf.notifs = notifs; @@ -1380,12 +1411,67 @@ static irqreturn_t pse_isr(int irq, void *data) regulator_notifier_call_chain(pcdev->pi[i].rdev, rnotifs, NULL); } +} + +/** + * pse_isr - IRQ handler for PSE + * @irq: irq number + * @data: pointer to user interrupt structure + * + * Return: irqreturn_t - status of IRQ + */ +static irqreturn_t pse_isr(int irq, void *data) +{ + struct pse_controller_dev *pcdev; + struct pse_irq *h = data; + int ret; + + pcdev = h->pcdev; + + /* Clear notifs mask */ + memset(h->notifs, 0, pcdev->nr_lines * sizeof(*h->notifs)); + bitmap_zero(h->notifs_mask, pcdev->nr_lines); + mutex_lock(&pcdev->lock); + ret = h->desc.map_event(irq, pcdev, h->notifs, h->notifs_mask); + if (ret || bitmap_empty(h->notifs_mask, pcdev->nr_lines)) { + mutex_unlock(&pcdev->lock); + return IRQ_NONE; + } + pse_handle_events(pcdev, h->notifs, h->notifs_mask); mutex_unlock(&pcdev->lock); return IRQ_HANDLED; } +static void pse_poll_worker(struct work_struct *work) +{ + struct pse_poll *poll = container_of(work, struct pse_poll, + work.work); + struct pse_controller_dev *pcdev = poll->pcdev; + int ret; + + memset(poll->notifs, 0, pcdev->nr_lines * sizeof(*poll->notifs)); + bitmap_zero(poll->notifs_mask, pcdev->nr_lines); + mutex_lock(&pcdev->lock); + ret = poll->desc.map_event(0, pcdev, poll->notifs, poll->notifs_mask); + /* Log only changes, not an error at every poll */ + if (!ret != !poll->err) { + if (ret) + dev_err(pcdev->dev, "Failed to poll events: %pe\n", + ERR_PTR(ret)); + else + dev_info(pcdev->dev, "Event polling works again\n"); + poll->err = ret; + } + if (!ret && !bitmap_empty(poll->notifs_mask, pcdev->nr_lines)) + pse_handle_events(pcdev, poll->notifs, poll->notifs_mask); + mutex_unlock(&pcdev->lock); + + queue_delayed_work(system_freezable_power_efficient_wq, &poll->work, + msecs_to_jiffies(PSE_POLL_INTERVAL_MS)); +} + /** * devm_pse_irq_helper - Register IRQ based PSE event notifier * @pcdev: a pointer to the PSE @@ -1393,7 +1479,8 @@ static irqreturn_t pse_isr(int irq, void *data) * @irq_flags: the flags to be passed to request_irq * @d: PSE interrupt description * - * Return: 0 on success and errno on failure + * Return: 0 on success, -EBUSY if the controller already has an event + * source, or another errno on failure */ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, int irq_flags, const struct pse_irq_desc *d) @@ -1407,6 +1494,10 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, if (!d || !d->map_event || !d->name) return -EINVAL; + /* Only one event source per controller */ + if (WARN_ON(pcdev->poll || pcdev->irq)) + return -EBUSY; + h = devm_kzalloc_obj(dev, *h); if (!h) return -ENOMEM; @@ -1448,6 +1539,50 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, } EXPORT_SYMBOL_GPL(devm_pse_irq_helper); +/** + * devm_pse_poll_helper - Report PSE events by polling + * @pcdev: a pointer to the PSE controller device + * @d: PSE event description, the same as for devm_pse_irq_helper(). + * d->name is not used. + * + * For PSE controllers without a usable IRQ. 500 ms after each poll, the + * core calls d->map_event() again and handles the events like pse_isr() + * does. Polling pauses during suspend. + * + * With the "disabled" budget strategy, the hardware keeps the power + * control, see pse_pw_d_is_sw_pw_control(). + * + * Call it after setting pcdev->dev and before + * devm_pse_controller_register(), which starts the polling. + * + * Return: 0 on success, -EBUSY if the controller is already registered + * or already has an event source, or another errno on failure + */ +int devm_pse_poll_helper(struct pse_controller_dev *pcdev, + const struct pse_irq_desc *d) +{ + struct pse_poll *poll; + + if (!d || !d->map_event) + return -EINVAL; + + /* Call this once, and before registering, which sets pcdev->pi */ + if (WARN_ON(pcdev->pi || pcdev->poll || pcdev->irq)) + return -EBUSY; + + poll = devm_kzalloc(pcdev->dev, sizeof(*poll), GFP_KERNEL); + if (!poll) + return -ENOMEM; + + poll->pcdev = pcdev; + poll->desc = *d; + INIT_DELAYED_WORK(&poll->work, pse_poll_worker); + pcdev->poll = poll; + + return 0; +} +EXPORT_SYMBOL_GPL(devm_pse_poll_helper); + /* PSE control section */ static void __pse_control_release(struct kref *kref) @@ -1917,8 +2052,8 @@ static int pse_pi_update_pw_budget(struct pse_controller_dev *pcdev, int id, */ mutex_lock(&pcdev->lock); /* Only a PI under software power control that is enabled and has a - * PD detected gets a budget. Check this here, as pse_isr() changes - * it under the same lock. + * PD detected gets a budget. Check this here, as the event handler + * changes it under the same lock. */ if (!pse_pw_d_is_sw_pw_control(pcdev, pi->pw_d) || !pi->admin_state_enabled || !pi->isr_pd_detected) diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index 17738ffcd224..008e16b7f72d 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -43,10 +43,13 @@ struct ethtool_c33_pse_pw_limit_range { }; /** - * struct pse_irq_desc - notification sender description for IRQ based events. + * struct pse_irq_desc - notification sender description for IRQ or poll + * based events. * - * @name: the visible name for the IRQ + * @name: the visible name for the IRQ, not used for polling * @map_event: driver callback to map IRQ status into PSE devices with events. + * When polling, irq is 0, and the callback must report only + * the events since the last call, not the current state. */ struct pse_irq_desc { const char *name; @@ -186,8 +189,8 @@ struct ethtool_pse_control_status { * @pi_get_prio: Get the PSE PI priority. * @pi_set_prio: Configure the PSE PI priority. * @pi_get_pw_req: Get the power requested by a PD before enabling the PSE PI. - * This is only relevant when an interrupt is registered using - * devm_pse_irq_helper helper. + * This is only relevant when events are reported by + * devm_pse_irq_helper() or devm_pse_poll_helper(). */ struct pse_controller_ops { int (*setup_pi_matrix)(struct pse_controller_dev *pcdev); @@ -218,6 +221,7 @@ struct module; struct device_node; struct of_phandle_args; struct pse_control; +struct pse_poll; struct ethtool_pse_control_status; /* PSE PI pairset pinout can either be Alternative A or Alternative B */ @@ -249,7 +253,7 @@ struct pse_pi_pairset { * @pw_d: Power domain of the PSE PI * @pw_d_node: entry in the list of PIs that use @pw_d * @prio: Priority of the PSE PI. Used in static budget evaluation strategy - * @isr_pd_detected: PSE PI detection status managed by the interruption + * @isr_pd_detected: PSE PI detection status managed by the event * handler. This variable is relevant when the power enabled * management is managed in software like the static * budget evaluation strategy. @@ -294,6 +298,7 @@ struct pse_ntf { * @pi: table of PSE PIs described in this controller device * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used * @irq: PSE interrupt + * @poll: poll state, set by devm_pse_poll_helper(), only used by the core * @pis_prio_max: Maximum value allowed for the PSE PIs priority * @supp_budget_eval_strategies: budget evaluation strategies supported * by the PSE @@ -316,6 +321,7 @@ struct pse_controller_dev { struct pse_pi *pi; bool no_of_pse_pi; int irq; + struct pse_poll *poll; unsigned int pis_prio_max; u32 supp_budget_eval_strategies; struct work_struct ntf_work; @@ -350,6 +356,8 @@ int devm_pse_controller_register(struct device *dev, struct pse_controller_dev *pcdev); int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, int irq_flags, const struct pse_irq_desc *d); +int devm_pse_poll_helper(struct pse_controller_dev *pcdev, + const struct pse_irq_desc *d); struct pse_control *of_pse_control_get(struct device_node *node, struct phy_device *phydev); -- 2.43.0