net: ipa: wake up system on RX available
Subsystems (3)
v3 cover net: ipa: wake up system on RX available
This series arranges for the IPA driver to wake up a suspended system if the IPA hardware has a packet to deliver to the AP.
Version 2 replaced the first patch from version 1 with three patches, in response to David Miller's feedback. And based on Bjorn Andersson's feedback on version 2, this version reworks the tracking of IPA clock references. As a result, we no longer need a flag to determine whether a "don't' suspend" clock reference is held (though an bit in a bitmask is still used for a different purpose).
In summary:
- A refcount_t is used to track IPA clock references where an atomic_t was previously used. (This may go away soon as well, with upcoming work to implement runtime PM.)
- We no longer track whether a special reference has been taken to avoid suspending IPA.
- A bit in a bitmask is used to ensure we only trigger a system resume once per system suspend.
And from the original series:
- Suspending endpoints only occurs when suspending the driver, not when dropping the last clock reference. Resuming endpoints is also disconnected from starting the clock.
- The IPA SUSPEND interrupt is now a wakeup interrupt. If it fires, it schedules a system resume operation.
- The GSI interrupt is no longer a wakeup interrupt.
-Alex
Alex Elder (7):
net: ipa: use refcount_t for IPA clock reference count
net: ipa: replace ipa->suspend_ref with a flag bit
net: ipa: manage endpoints separate from clock
net: ipa: use device_init_wakeup()
net: ipa: repurpose CLOCK_HELD flag
net: ipa: enable wakeup on IPA interrupt
net: ipa: do not enable GSI interrupt for wakeup
drivers/net/ipa/gsi.c | 17 +++------ drivers/net/ipa/gsi.h | 1 - drivers/net/ipa/ipa.h | 16 ++++++--- drivers/net/ipa/ipa_clock.c | 28 ++++++--------- drivers/net/ipa/ipa_interrupt.c | 14 ++++++++ drivers/net/ipa/ipa_main.c | 64 +++++++++++++++++---------------- 6 files changed, 74 insertions(+), 66 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/7 net: ipa: use refcount_t for IPA clock reference count
Take advantage of the checking provided by refcount_t, rather than using a plain atomic to represent the IPA clock reference count.
Note that we need to *set* the value to 1 in ipa_clock_get() rather than incrementing it from 0 (because doing that is considered an error for a refcount_t).
---
v2: This patch was added in version 2 of the series.
v3: No change.
drivers/net/ipa/ipa_clock.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ipa/ipa_clock.c +7 -7
@@ -4,7 +4,7 @@* Copyright (C) 2018-2020 Linaro Ltd. */ -#include <linux/atomic.h> +#include <linux/refcount.h> #include <linux/mutex.h> #include <linux/clk.h> #include <linux/device.h>
@@ -51,7 +51,7 @@* @config_path: Configuration space interconnect */ struct ipa_clock { -atomic_t count; +refcount_t count;struct mutex mutex;/* protects clock enable/disable */ struct clk *core;struct icc_path *memory_path;
@@ -195,7 +195,7 @@ static void ipa_clock_disable(struct ipa *ipa)*/ bool ipa_clock_get_additional (struct ipa *ipa) { -return !!atomic_inc_not_zero (&ipa->clock->count); +return refcount_inc_not_zero (&ipa->clock->count); }/* Get an IPA clock reference. If the reference count is non-zero, it is
@@ -231,7 +231,7 @@ void ipa_clock_get(struct ipa *ipa)ipa_endpoint_resume (ipa); -atomic_inc (&clock->count); +refcount_set (&clock->count,1 ); out_mutex_unlock:mutex_unlock (&clock->mutex);
@@ -246,7 +246,7 @@ void ipa_clock_put(struct ipa *ipa)struct ipa_clock *clock = ipa->clock;/* If this is not the last reference there's nothing more to do */ -if (!atomic_dec_and_mutex_lock (&clock->count, &clock->mutex)) +if (!refcount_dec_and_mutex_lock (&clock->count, &clock->mutex))return ;ipa_endpoint_suspend (ipa);
@@ -294,7 +294,7 @@ struct ipa_clock *ipa_clock_init(struct device *dev) goto err_kfree;mutex_init (&clock->mutex); -atomic_set (&clock->count,0 ); +refcount_set (&clock->count,0 );return clock;
@@ -311,7 +311,7 @@ void ipa_clock_exit(struct ipa_clock *clock) {struct clk *clk = clock->core; -WARN_ON (atomic_read (&clock->count) !=0 ); +WARN_ON (refcount_read (&clock->count) !=0 );mutex_destroy (&clock->mutex);ipa_interconnect_exit (clock);kfree (clock);
Signature · 1 line
2.20.1
PATCH v3 2/7 net: ipa: replace ipa->suspend_ref with a flag bit
In reply to Alex ElderWe take a clock reference in ipa_config() in order to prevent the the IPA clock from being shutdown until a power management suspend request arrives. An atomic field in the IPA structure records whether that extra reference had been taken.
Rather than using an atomic to represent a Boolean value, define a new flags bitmap, and define a "clock held" flag to represent whether the extra clock reference has been taken.
---
v2: New patch to use a bitmap bit rather than an atomic_t.
v3: No change since v2.
drivers/net/ipa/ipa.h | 14 ++++++++++++-- drivers/net/ipa/ipa_main.c | 14 +++++++------- 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/net/ipa/ipa.h +12 -2
@@ -27,15 +27,25 @@ struct ipa_clock;struct ipa_smp2p ;struct ipa_interrupt ; +/** +* enum ipa_flag - IPA state flags +* @IPA_FLAG_CLOCK_HELD: Whether IPA clock is held to prevent suspend +* @IPA_FLAG_COUNT: Number of defined IPA flags +*/ +enum ipa_flag { +IPA_FLAG_CLOCK_HELD , +IPA_FLAG_COUNT ,/* Last; not a flag */ +}; +/** * struct ipa - IPA information * @gsi: Embedded GSI structure +* @flags: Boolean state flags * @version: IPA hardware version * @pdev: Platform device * @modem_rproc: Remoteproc handle for modem subsystem * @smp2p: SMP2P information * @clock: IPA clocking information -* @suspend_ref: Whether clock reference preventing suspend taken * @table_addr: DMA address of filter/route table content * @table_virt: Virtual address of filter/route table content * @interrupt: IPA Interrupt information
@@ -70,6 +80,7 @@ struct ipa_interrupt;*/ struct ipa {struct gsi gsi; + DECLARE_BITMAP(flags, IPA_FLAG_COUNT);enum ipa_version version;struct platform_device *pdev;struct rproc *modem_rproc;
@@ -77,7 +88,6 @@ struct ipa {void *notifier;struct ipa_smp2p *smp2p;struct ipa_clock *clock; -atomic_t suspend_ref;dma_addr_t table_addr;__le64 *table_virt;
drivers/net/ipa/ipa_main.c +7 -7
@@ -84,7 +84,7 @@ static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)* endpoints will be resumed as a result. This reference will * be dropped when we get a power management suspend request. */ -if (!atomic_xchg (&ipa->suspend_ref,1 )) +if (!test_and_set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags))ipa_clock_get (ipa);/* Acknowledge/clear the suspend interrupt on all endpoints */
@@ -508,7 +508,7 @@ static int ipa_config(struct ipa *ipa, const struct ipa_data *data)* is held after initialization completes, and won't get dropped * unless/until a system suspend request arrives. */ -atomic_set (&ipa->suspend_ref,1 ); +__set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);ipa_clock_get (ipa);ipa_hardware_config (ipa);
@@ -544,7 +544,7 @@ static int ipa_config(struct ipa *ipa, const struct ipa_data *data) err_hardware_deconfig:ipa_hardware_deconfig (ipa);ipa_clock_put (ipa); -atomic_set (&ipa->suspend_ref,0 ); +__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);return ret; }
@@ -562,7 +562,7 @@ static void ipa_deconfig(struct ipa *ipa)ipa_endpoint_deconfig (ipa);ipa_hardware_deconfig (ipa);ipa_clock_put (ipa); -atomic_set (&ipa->suspend_ref,0 ); +__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags); }static int ipa_firmware_load (struct device *dev)
@@ -777,7 +777,7 @@ static int ipa_probe(struct platform_device *pdev)dev_set_drvdata (dev, ipa); ipa->modem_rproc = rproc; ipa->clock = clock; -atomic_set (&ipa->suspend_ref,0 ); +__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags); ipa->wakeup_source = wakeup_source; ipa->version = data->version;
@@ -913,7 +913,7 @@ static int ipa_suspend(struct device *dev)struct ipa *ipa =dev_get_drvdata (dev);ipa_clock_put (ipa); -atomic_set (&ipa->suspend_ref,0 ); +__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);return 0 ; }
@@ -933,7 +933,7 @@ static int ipa_resume(struct device *dev)/* This clock reference will keep the IPA out of suspend * until we get a power management suspend request. */ -atomic_set (&ipa->suspend_ref,1 ); +__set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);ipa_clock_get (ipa);return 0 ;
Signature · 1 line
2.20.1
PATCH v3 3/7 net: ipa: manage endpoints separate from clock
In reply to Alex ElderCurrently, when (before) the last IPA clock reference is dropped, all endpoints are suspended. And whenever the first IPA clock reference is taken, all endpoints are resumed (or started).
In most cases there's no need to start endpoints when the clock starts. So move the calls to ipa_endpoint_suspend() and ipa_endpoint_resume() out of ipa_clock_put() and ipa_clock_get(), respectiely. Instead, only suspend endpoints when handling a system suspend, and only resume endpoints when handling a system resume.
---
v3: Added Bjorn's reviewed-by tag.
drivers/net/ipa/ipa_clock.c | 14 ++++---------- drivers/net/ipa/ipa_main.c | 8 ++++++++ 2 files changed, 12 insertions(+), 10 deletions(-)
drivers/net/ipa/ipa_clock.c +4 -10
@@ -200,9 +200,8 @@ bool ipa_clock_get_additional(struct ipa *ipa)/* Get an IPA clock reference. If the reference count is non-zero, it is * incremented and return is immediate. Otherwise it is checked again -* under protection of the mutex, and if appropriate the clock (and -* interconnects) are enabled suspended endpoints (if any) are resumed -* before returning. +* under protection of the mutex, and if appropriate the IPA clock +* is enabled. * * Incrementing the reference count is intentionally deferred until * after the clock is running and endpoints are resumed.
@@ -229,17 +228,14 @@ void ipa_clock_get(struct ipa *ipa) goto out_mutex_unlock; } -ipa_endpoint_resume (ipa); -refcount_set (&clock->count,1 ); out_mutex_unlock:mutex_unlock (&clock->mutex); } -/* Attempt to remove an IPA clock reference. If this represents the last -* reference, suspend endpoints and disable the clock (and interconnects) -* under protection of a mutex. +/* Attempt to remove an IPA clock reference. If this represents the +* last reference, disable the IPA clock under protection of the mutex. */ void ipa_clock_put (struct ipa *ipa) {
@@ -249,8 +245,6 @@ void ipa_clock_put(struct ipa *ipa)if (!refcount_dec_and_mutex_lock (&clock->count, &clock->mutex))return ; -ipa_endpoint_suspend (ipa); -ipa_clock_disable (ipa);mutex_unlock (&clock->mutex);
drivers/net/ipa/ipa_main.c +8 -0
@@ -907,11 +907,15 @@ static int ipa_remove(struct platform_device *pdev)* Return: Always returns zero * * Called by the PM framework when a system suspend operation is invoked. +* Suspends endpoints and releases the clock reference held to keep +* the IPA clock running until this point. */ static int ipa_suspend (struct device *dev) {struct ipa *ipa =dev_get_drvdata (dev); +ipa_endpoint_suspend (ipa); +ipa_clock_put (ipa);__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);
@@ -925,6 +929,8 @@ static int ipa_suspend(struct device *dev)* Return: Always returns 0 * * Called by the PM framework when a system resume operation is invoked. +* Takes an IPA clock reference to keep the clock running until suspend, +* and resumes endpoints. */ static int ipa_resume (struct device *dev) {
@@ -936,6 +942,8 @@ static int ipa_resume(struct device *dev)__set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);ipa_clock_get (ipa); +ipa_endpoint_resume (ipa); +return 0 ; }
Signature · 1 line
2.20.1
PATCH v3 4/7 net: ipa: use device_init_wakeup()
In reply to Alex ElderThe call to wakeup_source_register() in ipa_probe() does not do what it was intended to do. Call device_init_wakeup() in ipa_setup() instead, to set the IPA device as wakeup-capable and to initially enable wakeup capability.
When we receive a SUSPEND interrupt, call pm_wakeup_dev_event() with a zero processing time, to simply call for a resume without any other processing. The ipa_resume() call will take care of waking things up again, and will handle receiving the packet.
Note that this gets rid of a clock reference counting bug that occurred when handling an IPA SUSPEND interrupt. Specifically, ipa_suspend_handler() took an IPA clock reference *in addition* to the one taken by ipa_resume(). There is no need to back-port this fix however, because it only affects code that was not previously working (this patch is part of fixing that).
---
v3: Added Bjorn's reviewed-by tag.
drivers/net/ipa/ipa.h | 2 -- drivers/net/ipa/ipa_main.c | 42 ++++++++++++++++---------------------- 2 files changed, 18 insertions(+), 26 deletions(-)
drivers/net/ipa/ipa.h +0 -2
@@ -114,8 +114,6 @@ struct ipa {void *zero_virt;size_t zero_size; -struct wakeup_source *wakeup_source; -/* Bit masks indicating endpoint state */ u32 available;/* supported by hardware */ u32 filter_map;
drivers/net/ipa/ipa_main.c +18 -24
125 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 5/7 net: ipa: repurpose CLOCK_HELD flag
In reply to Alex ElderThe previous patch causes a system resume to be triggered when a packet is available for receipt on a suspended RX endpoint.
The CLOCK_HELD flag was previously used to indicate that an extra clock reference was held, preventing suspend. But we no longer need such a flag:
- We take an initial reference in ipa_config().
- That reference is held until ipa_suspend() releases it.
- A subsequent system resume leads to a reference getting re-acquired in ipa_resume().
- This can repeat until ultimately the module is removed, where ipa_remove() releases the reference.
We no longer need a special flag to determine whether this extra reference is held--it is, provided probe has completed successfully and the driver is not suspended (or removed).
On the other hand, once suspended, it's possible for more than one endpoint to trip the IPA SUSPEND interrupt, and we only want to trigger the system resume once. So repurpose the Boolean CLOCK_HELD flag to record whether the IPA SUSPEND handler should initiate a system resume.
The flag will be be cleared each time ipa_suspend() is called, *before* any endpoints are suspended. And it will be set inside the IPA SUSPEND interrupt handler exactly once per suspend.
Rename the flag IPA_FLAG_RESUMED to reflect its new purpose.
---
v3: New; eliminated need for "clock held" flag, as Bjorn suggested.
drivers/net/ipa/ipa.h | 6 +++--- drivers/net/ipa/ipa_main.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)
drivers/net/ipa/ipa.h +3 -3
@@ -29,11 +29,11 @@ struct ipa_interrupt;/** * enum ipa_flag - IPA state flags -* @IPA_FLAG_CLOCK_HELD: Whether IPA clock is held to prevent suspend -* @IPA_FLAG_COUNT: Number of defined IPA flags +* @IPA_FLAG_RESUMED: Whether resume from suspend has been signaled +* @IPA_FLAG_COUNT: Number of defined IPA flags */ enum ipa_flag { -IPA_FLAG_CLOCK_HELD , +IPA_FLAG_RESUMED ,IPA_FLAG_COUNT ,/* Last; not a flag */ };
drivers/net/ipa/ipa_main.c +7 -7
@@ -86,7 +86,7 @@ static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)* More than one endpoint could signal this; if so, ignore * all but the first. */ -if (!test_and_set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags)) +if (!test_and_set_bit (IPA_FLAG_RESUMED , ipa->flags))pm_wakeup_dev_event (&ipa->pdev->dev,0 , true);/* Acknowledge/clear the suspend interrupt on all endpoints */
@@ -518,7 +518,6 @@ static int ipa_config(struct ipa *ipa, const struct ipa_data *data)* is held after initialization completes, and won't get dropped * unless/until a system suspend request arrives. */ -__set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);ipa_clock_get (ipa);ipa_hardware_config (ipa);
@@ -554,7 +553,6 @@ static int ipa_config(struct ipa *ipa, const struct ipa_data *data) err_hardware_deconfig:ipa_hardware_deconfig (ipa);ipa_clock_put (ipa); -__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);return ret; }
@@ -572,7 +570,6 @@ static void ipa_deconfig(struct ipa *ipa)ipa_endpoint_deconfig (ipa);ipa_hardware_deconfig (ipa);ipa_clock_put (ipa); -__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags); }static int ipa_firmware_load (struct device *dev)
@@ -778,7 +775,6 @@ static int ipa_probe(struct platform_device *pdev)dev_set_drvdata (dev, ipa); ipa->modem_rproc = rproc; ipa->clock = clock; -__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags); ipa->version = data->version; ret =ipa_reg_init (ipa);
@@ -908,10 +904,15 @@ static int ipa_suspend(struct device *dev) {struct ipa *ipa =dev_get_drvdata (dev); +/* When a suspended RX endpoint has a packet ready to receive, we +* get an IPA SUSPEND interrupt. We trigger a system resume in +* that case, but only on the first such interrupt since suspend. +*/ +__clear_bit (IPA_FLAG_RESUMED , ipa->flags); +ipa_endpoint_suspend (ipa);ipa_clock_put (ipa); -__clear_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);return 0 ; }
@@ -933,7 +934,6 @@ static int ipa_resume(struct device *dev)/* This clock reference will keep the IPA out of suspend * until we get a power management suspend request. */ -__set_bit (IPA_FLAG_CLOCK_HELD , ipa->flags);ipa_clock_get (ipa);ipa_endpoint_resume (ipa);
Signature · 1 line
2.20.1
PATCH v3 6/7 net: ipa: enable wakeup on IPA interrupt
In reply to Alex ElderNow that we handle wakeup interrupts properly, arrange for the IPA interrupt to be treated as a wakeup interrupt.
---
v3: Added Bjorn's reviewed-by tag.
drivers/net/ipa/ipa_interrupt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/ipa/ipa_interrupt.c +14 -0
@@ -237,8 +237,16 @@ struct ipa_interrupt *ipa_interrupt_setup(struct ipa *ipa) goto err_kfree; } + ret =enable_irq_wake (irq); +if (ret) { +dev_err (dev,"error %d enabling wakeup for \"ipa\" IRQ\n" , ret); + goto err_free_irq; + } +return interrupt; +err_free_irq: +free_irq (interrupt->irq, interrupt); err_kfree:kfree (interrupt);
@@ -248,6 +256,12 @@ struct ipa_interrupt *ipa_interrupt_setup(struct ipa *ipa)/* Tear down the IPA interrupt framework */ void ipa_interrupt_teardown (struct ipa_interrupt *interrupt) { +struct device *dev = &interrupt->ipa->pdev->dev; +int ret; + + ret =disable_irq_wake (interrupt->irq); +if (ret) +dev_err (dev,"error %d disabling \"ipa\" IRQ wakeup\n" , ret);free_irq (interrupt->irq, interrupt);kfree (interrupt); }
Signature · 1 line
2.20.1
PATCH v3 7/7 net: ipa: do not enable GSI interrupt for wakeup
In reply to Alex ElderWe now trigger a system resume when we receive an IPA SUSPEND interrupt. We should *not* wake up on GSI interrupts.
---
v3: Added Bjorn's reviewed-by tag.
drivers/net/ipa/gsi.c | 17 ++++------------- drivers/net/ipa/gsi.h | 1 - 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/net/ipa/gsi.c +4 -13
@@ -1987,31 +1987,26 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, bool prefetch, } gsi->irq = irq; - ret =enable_irq_wake (gsi->irq); -if (ret) -dev_warn (dev,"error %d enabling gsi wake irq\n" , ret); - gsi->irq_wake_enabled = !ret; -/* Get GSI memory range and map it */ res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"gsi" );if (!res) {dev_err (dev,"DT error getting \"gsi\" memory property\n" ); ret = -ENODEV ; - goto err_disable_irq_wake; + goto err_free_irq; } size =resource_size (res);if (res->start >U32_MAX || size >U32_MAX - res->start) {dev_err (dev,"DT memory resource \"gsi\" out of range\n" ); ret = -EINVAL ; - goto err_disable_irq_wake; + goto err_free_irq; } gsi->virt =ioremap (res->start, size);if (!gsi->virt) {dev_err (dev,"unable to remap \"gsi\" memory\n" ); ret = -ENOMEM ; - goto err_disable_irq_wake; + goto err_free_irq; } ret =gsi_channel_init (gsi, prefetch, count, data, modem_alloc);
@@ -2025,9 +2020,7 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, bool prefetch, err_iounmap:iounmap (gsi->virt); -err_disable_irq_wake: -if (gsi->irq_wake_enabled) - (void )disable_irq_wake (gsi->irq); +err_free_irq:free_irq (gsi->irq, gsi);return ret;
@@ -2038,8 +2031,6 @@ void gsi_exit(struct gsi *gsi) {mutex_destroy (&gsi->mutex);gsi_channel_exit (gsi); -if (gsi->irq_wake_enabled) - (void )disable_irq_wake (gsi->irq);free_irq (gsi->irq, gsi);iounmap (gsi->virt); }
drivers/net/ipa/gsi.h +0 -1
@@ -150,7 +150,6 @@ struct gsi {struct net_device dummy_dev;/* needed for NAPI */ void __iomem *virt;u32 irq; -bool irq_wake_enabled;u32 channel_count;u32 evt_ring_count;struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX ];
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Alex Elder <[email protected]>
Date: Thu, 17 Sep 2020 12:39:19 -0500
Quoted 10 lines
This series arranges for the IPA driver to wake up a suspended system if the IPA hardware has a packet to deliver to the AP.
Version 2 replaced the first patch from version 1 with three patches, in response to David Miller's feedback. And based on Bjorn Andersson's feedback on version 2, this version reworks the tracking of IPA clock references. As a result, we no longer need a flag to determine whether a "don't' suspend" clock reference is held (though an bit in a bitmask is still used for a different purpose).
...
Series applied, thanks.