From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796052354; b=Nd4Wz125RZOrj7sn5Rnmuw6S1eSYkJSV2Oz/erW/TjJbv0bvJyvwy1lUPBYnrwxm11/d 4XIBqjkDsnHLcjyGRWYqG/2SVdcZXbFDJeOJdnQZpJCyyncgph0zpWrtoIj/C1PQ7QcCX NeoFE86pqRuNqC6KWgrc+ITIEuIed8e9ZKdIYPy4ivoFouPiKWRMK4L7RLYh3PeyxGXXw IbEplXb9VTPclDcRPS9on6yO2LVQxlaZe0J96RZDRjUbnk0B7JtRlyAQHdY2q979Fer5n MFKLk2qNjs+oa9fy5PA863ZBZ4mXgkdwrq4ip7fvVFYpuB12KWk3EHlG8PysZ84UzJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796052354; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-Last-TLS-Session-Version; bh=k3R/pbm/9t7H6gxa8nzib4HaFPsU7F4haOH/z9cEhDk=; b=aVMwTMlyF50Z/pOUweyit1RtTf26Gr5oR5REHTqwT5AQMuTrE3eOZVKMrS0VeeKy0H9t ud15WobGlfXNU9lIzIB0sQruEyc5YKBGcoo/CzDz18hq/8bHQMm9+G9YuJEqA2xeLfilP dY4OEq8TQgNE2cM2HiZ6XyX/AIQ+VX5y2JJwdFpw4+OMFjQMb2/ouobSRaIi8XqDkxP/s ej8Vgsm8rac2RQq8h1jhg+4CRnB7BlTqZCyadC5vTfyqWEQgshXhRyR6WDcXLCgqcyMzv TgNiTq/OKiZx4Gzi/k1cVNxidafdeqXD5lkJ5Ug4KGtw3kkDTFX4s38TTmBH7VQU5Mg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=tb8r3fBE; arc=none smtp.remote-ip=185.246.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5238D606A31C for ; Mon, 30 Nov 2026 15:25:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5238D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=tb8r3fBE Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id E0D061A1890; Mon, 30 Nov 2026 15:25:51 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id AC9656007C; Mon, 30 Nov 2026 15:25:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9F5AC11EA00C4; Mon, 30 Nov 2026 16:25:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796052350; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=k3R/pbm/9t7H6gxa8nzib4HaFPsU7F4haOH/z9cEhDk=; b=tb8r3fBEQuiGNpQaQmj4oPXd8fDFwcLeFAqxV4beCyfcc/mVvurlpkePEeRIY1jI7yk/u4 Em2DPgP/q6lLxDD/SrmdrpfS7jT9mQFeX4fGYX4FPoEdMqJIhaOZCOPTBVj+Y+cSqYZEN0 YDg9PO08tAZIcLwuAk64dGjC/7qHe1Xh1uiM2+UITaX9ZFFrTSjzC3Ilw46R5xCmPBfRLe /x9Vi9acLFI3W/UJBUy5e0+L0qAR+StG6qV/csBaK0qVZlZtNfN5UklUJ5L4owml8nE/uh 1BKtcneDVNj7hwuF5m9flU2efb6fWqRgyIy/ApLPD93VhkVd1z0XiT1fbG8Vmg== Message-ID: Date: Mon, 30 Nov 2026 16:25:45 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Betterbird (Linux) Subject: Re: [PATCH net-next v6 1/2] net: pse-pd: add pse_poll_helper() To: Carlo Szelinsky , Oleksij Rempel 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 References: <20261128121525.3909836-1-github@szelinsky.de> <20261128121525.3909836-2-github@szelinsky.de> From: Kory Maincent Content-Language: en-US In-Reply-To: <20261128121525.3909836-2-github@szelinsky.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 On 11/28/26 13:15, Carlo Szelinsky wrote: > Some PSE controllers have no interrupt line, or the board does not wire > it. These controllers can still report events if the core polls them. > > Move the event loop of pse_isr() into pse_handle_events(), and add > pse_poll_helper(). It uses the same pse_irq_desc as the IRQ path. > A delayed work calls the driver's map_event() every poll_interval_ms > (default 500 ms) and passes the events to pse_handle_events(). When > map_event() starts or stops failing, the core logs it once, and the > next poll runs as usual. > > The helper must be called before the controller registers, and returns > -EBUSY otherwise. It has no devm_ prefix, as it allocates nothing and > adds no devres action. pse_controller_register() allocates the poll > buffers once nr_lines is final, and starts the work at its end, so the > work never runs on a controller that is not fully set up, or on one > whose probe failed. pse_controller_unregister() stops it next to the IRQ, > before the PI data and power domains are released. > > The work runs on system_freezable_power_efficient_wq, so it does not > access the bus during suspend, and it is not bound to one CPU when > power efficient workqueues are enabled. > > With the "disabled" budget strategy, a polled controller keeps the > power control in hardware, as a controller without events does today. > The core takes it over only for an IRQ controller, which it expects to > report PD detection while a PI is off. With the static strategy, a > polled controller uses the software power control, as an IRQ one does. > Update the comments that say this needs an IRQ. Can you write the commit message manually and don't use LLM that only explain the code and not the why. > Signed-off-by: Carlo Szelinsky > --- > drivers/net/pse-pd/pse_core.c | 183 ++++++++++++++++++++++++++++------ > include/linux/pse-pd/pse.h | 27 ++++- > 2 files changed, 177 insertions(+), 33 deletions(-) > > diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c > index 0477cf6787bd..2fb10f5d8f8e 100644 > --- a/drivers/net/pse-pd/pse_core.c > +++ b/drivers/net/pse-pd/pse_core.c > @@ -14,10 +14,14 @@ > #include > #include > #include > +#include > #include > > #define PSE_PW_D_LIMIT INT_MAX > > +/* Default poll interval: fast enough for PD events, light on the I2C bus */ > +#define PSE_DEFAULT_POLL_INTERVAL_MS 500 > + > static DEFINE_MUTEX(pse_list_mutex); > static LIST_HEAD(pse_controller_list); > static DEFINE_XARRAY_ALLOC(pse_pw_d_map); > @@ -392,8 +396,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 > @@ -1119,6 +1123,19 @@ int pse_controller_register(struct pse_controller_dev *pcdev) > goto free_kfifo; > } > > + if (pcdev->polling) { > + pcdev->poll_notifs = devm_kzalloc_objs(pcdev->dev, > + *pcdev->poll_notifs, > + pcdev->nr_lines); > + pcdev->poll_notifs_mask = devm_bitmap_zalloc(pcdev->dev, > + pcdev->nr_lines, > + GFP_KERNEL); > + if (!pcdev->poll_notifs || !pcdev->poll_notifs_mask) { > + ret = -ENOMEM; > + goto free_kfifo; > + } > + } > + > ret = of_load_pse_pis(pcdev); > if (ret) > goto free_kfifo; > @@ -1171,6 +1188,14 @@ int pse_controller_register(struct pse_controller_dev *pcdev) > list_add(&pcdev->list, &pse_controller_list); > mutex_unlock(&pse_list_mutex); > > + /* Start polling only now, so the worker never sees a controller > + * that is not fully set up. > + */ This comment seems a bit useless. > + if (pcdev->polling) > + queue_delayed_work(system_freezable_power_efficient_wq, > + &pcdev->poll_work, > + msecs_to_jiffies(pcdev->poll_interval_ms)); > + > return 0; > > free_kfifo: > @@ -1193,12 +1218,15 @@ 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 the IRQ, the poll work and the notification worker first: > + * pse_isr() and pse_poll_worker() use pcdev->pi and the power > + * domains that pse_flush_pw_ds() drops, and the worker reads the > + * kfifo that is freed below. > */ Could you make this comment human readable with only a few words? Yes I should not have accepted this AI comment in the first place. Now I feel that it brings more confusion that explanation. > if (pcdev->irq) > disable_irq(pcdev->irq); > + if (pcdev->polling) > + 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 +1354,39 @@ 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 - Process PSE events for all PIs > + * @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 > + * Common event handling shared between IRQ and poll paths. > + * 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; > - > - desc = &h->desc; > - pcdev = h->pcdev; > + int i; > > - /* 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; > - } > + lockdep_assert_held(&pcdev->lock); > > - 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 +1399,73 @@ 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_controller_dev *pcdev = > + container_of(work, struct pse_controller_dev, > + poll_work.work); > + int ret; > + > + memset(pcdev->poll_notifs, 0, > + pcdev->nr_lines * sizeof(*pcdev->poll_notifs)); > + bitmap_zero(pcdev->poll_notifs_mask, pcdev->nr_lines); > + mutex_lock(&pcdev->lock); > + ret = pcdev->poll_desc.map_event(0, pcdev, pcdev->poll_notifs, > + pcdev->poll_notifs_mask); > + /* Log only changes: a controller that stopped answering would > + * otherwise log an error at every poll. > + */ > + if (ret != pcdev->poll_err) { > + if (ret) > + dev_err(pcdev->dev, "Failed to poll events: %pe\n", > + ERR_PTR(ret)); > + else > + dev_info(pcdev->dev, "Polling events works again\n"); > + pcdev->poll_err = ret; > + } > + if (!ret && !bitmap_empty(pcdev->poll_notifs_mask, pcdev->nr_lines)) > + pse_handle_events(pcdev, pcdev->poll_notifs, > + pcdev->poll_notifs_mask); > + mutex_unlock(&pcdev->lock); > + > + queue_delayed_work(system_freezable_power_efficient_wq, > + &pcdev->poll_work, > + msecs_to_jiffies(pcdev->poll_interval_ms)); > +} > + > /** > * devm_pse_irq_helper - Register IRQ based PSE event notifier > * @pcdev: a pointer to the PSE > @@ -1448,6 +1528,51 @@ int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, > } > EXPORT_SYMBOL_GPL(devm_pse_irq_helper); > > +/** > + * pse_poll_helper - Set up a poll-based PSE event notifier > + * @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. Every poll_interval_ms > + * (default 500 ms), a delayed work calls d->map_event() with irq 0 and > + * handles the events like pse_isr() does. The work runs on a freezable > + * workqueue, so it does not touch the hardware during suspend. > + * > + * With the "disabled" budget strategy, the hardware keeps the power > + * control of a polled controller. The PSE core takes it over only for > + * an IRQ controller, see pse_pw_d_is_sw_pw_control(). > + * > + * Must be called before devm_pse_controller_register(), which allocates > + * the poll buffers and starts the polling once the controller is > + * registered. > + * > + * Return: 0 on success, -EBUSY if the controller is already registered, > + * or another errno on failure > + */ > +int pse_poll_helper(struct pse_controller_dev *pcdev, > + const struct pse_irq_desc *d) > +{ > + if (!d || !d->map_event) > + return -EINVAL; > + > + /* pcdev->pi is set by pse_controller_register(), which must come > + * after this call to start the polling. > + */ > + if (WARN_ON(pcdev->pi)) > + return -EBUSY; > + > + pcdev->poll_desc = *d; > + if (!pcdev->poll_interval_ms) > + pcdev->poll_interval_ms = PSE_DEFAULT_POLL_INTERVAL_MS; > + > + INIT_DELAYED_WORK(&pcdev->poll_work, pse_poll_worker); > + pcdev->polling = true; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(pse_poll_helper); > + > /* PSE control section */ > > static void __pse_control_release(struct kref *kref) > diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h > index 17738ffcd224..e40ed754dbdb 100644 > --- a/include/linux/pse-pd/pse.h > +++ b/include/linux/pse-pd/pse.h > @@ -43,10 +43,12 @@ 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. > + * irq is 0 when it is called from the poll work. You can rather say that the irq value is not used in case of polling. > */ > struct pse_irq_desc { > const char *name; > @@ -186,8 +188,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, using the > + * devm_pse_irq_helper() or pse_poll_helper() helper. > */ > struct pse_controller_ops { > int (*setup_pi_matrix)(struct pse_controller_dev *pcdev); > @@ -294,6 +296,14 @@ 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 > + * @polling: flag indicating poll-based event detection is active > + * @poll_interval_ms: poll interval in milliseconds, a driver may set it > + * before pse_poll_helper(), 0 means 500 ms > + * @poll_work: delayed work for poll-based event detection > + * @poll_desc: copy of the driver's event descriptor for polling > + * @poll_notifs: per-PI notification scratch space for poll worker > + * @poll_notifs_mask: bitmap of PIs with events for poll worker > + * @poll_err: result of the last poll, to log only changes > * @pis_prio_max: Maximum value allowed for the PSE PIs priority > * @supp_budget_eval_strategies: budget evaluation strategies supported > * by the PSE > @@ -316,6 +326,13 @@ struct pse_controller_dev { > struct pse_pi *pi; > bool no_of_pse_pi; > int irq; > + bool polling; > + unsigned int poll_interval_ms; > + struct delayed_work poll_work; > + struct pse_irq_desc poll_desc; > + unsigned long *poll_notifs; > + unsigned long *poll_notifs_mask; > + int poll_err; I would prefer here to use an internal sub structure with its content not accessible from the drivers. I am glad to see this development and have tested it on a new project that does not have the interruption line wired. So you have saved some of my time. Thank you! -- Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com