Skip to contentSkip to conversation

net: ipa: wake up system on RX available

PATCH Superseded Alex Elder 2 participants 10 messages Sep 9, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
author
#6 lore raw

PATCH 2/5 net: ipa: manage endpoints separate from clock

In reply to Alex Elder

Currently, 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.

---
 drivers/net/ipa/ipa_clock.c | 4 ----
 drivers/net/ipa/ipa_main.c  | 4 ++++
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ipa/ipa_clock.c +0 -4
index 398f2e47043d8..f2d61c35ef941 100644
@@ -229,8 +229,6 @@ void ipa_clock_get(struct ipa *ipa)
 		goto out_mutex_unlock;
 	}
 
-	ipa_endpoint_resume(ipa);
-
 	atomic_inc(&clock->count);
 
 out_mutex_unlock:
@@ -249,8 +247,6 @@ void ipa_clock_put(struct ipa *ipa)
 	if (!atomic_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 +4 -0
index 6b843fc989122..b8e4a2532fc1a 100644
@@ -917,6 +917,8 @@ static int ipa_suspend(struct device *dev)
 {
 	struct ipa *ipa = dev_get_drvdata(dev);
 
+	ipa_endpoint_suspend(ipa);
+
 	ipa_clock_put(ipa);
 	if (!atomic_xchg(&ipa->suspend_ref, 0))
 		dev_err(dev, "suspend: missing suspend clock reference\n");
@@ -943,6 +945,8 @@ static int ipa_resume(struct device *dev)
 		dev_err(dev, "resume: duplicate suspend clock reference\n");
 	ipa_clock_get(ipa);
 
+	ipa_endpoint_resume(ipa);
+
 	return 0;
 }
 
Signature · 1 line
2.20.1
author
#8 lore raw

PATCH 4/5 net: ipa: enable wakeup on IPA interrupt

In reply to Alex Elder

Now that we handle wakeup interrupts properly, arrange for the IPA interrupt to be treated as a wakeup interrupt.

---
 drivers/net/ipa/ipa_interrupt.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/ipa/ipa_interrupt.c +14 -0
index 90353987c45fc..cc1ea28f7bc2e 100644
@@ -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
author
#1 lore raw

PATCH 1/5 net: ipa: use atomic exchange for suspend reference

In reply to Alex Elder

We take a single IPA clock reference to keep the clock running until we get a system suspend operation. When a system suspend request arrives, we drop that reference, and if that's the last reference (likely) we'll proceed with suspending endpoints and disabling the IPA core clock and interconnects.

In most places we simply set the reference count to 0 or 1 atomically. Instead--primarily to catch coding errors--use an atomic exchange to update the reference count value, and report an error in the event the previous value was unexpected.

In a few cases it's not hard to see that the error message should never be reported. Report them anyway, but add some excitement to the message by ending it with an exclamation point.

---
 drivers/net/ipa/ipa_main.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/ipa/ipa_main.c +12 -5
index 1fdfec41e4421..6b843fc989122 100644
@@ -83,6 +83,7 @@ static void ipa_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
 	/* Take a a single clock reference to prevent suspend.  All
 	 * endpoints will be resumed as a result.  This reference will
 	 * be dropped when we get a power management suspend request.
+	 * The first call activates the clock; ignore any others.
 	 */
 	if (!atomic_xchg(&ipa->suspend_ref, 1))
 		ipa_clock_get(ipa);
@@ -502,13 +503,15 @@ static void ipa_resource_deconfig(struct ipa *ipa)
  */
 static int ipa_config(struct ipa *ipa, const struct ipa_data *data)
 {
+	struct device *dev = &ipa->pdev->dev;
 	int ret;
 
 	/* Get a clock reference to allow initialization.  This reference
 	 * is held after initialization completes, and won't get dropped
 	 * unless/until a system suspend request arrives.
 	 */
-	atomic_set(&ipa->suspend_ref, 1);
+	if (atomic_xchg(&ipa->suspend_ref, 1))
+		dev_err(dev, "suspend clock reference already taken!\n");
 	ipa_clock_get(ipa);
 
 	ipa_hardware_config(ipa);
@@ -544,7 +547,8 @@ 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);
+	if (!atomic_xchg(&ipa->suspend_ref, 0))
+		dev_err(dev, "suspend clock reference already dropped!\n");
 
 	return ret;
 }
@@ -562,7 +566,8 @@ 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);
+	if (!atomic_xchg(&ipa->suspend_ref, 0))
+		dev_err(&ipa->pdev->dev, "no suspend clock reference\n");
 }
 
 static int ipa_firmware_load(struct device *dev)
@@ -913,7 +918,8 @@ static int ipa_suspend(struct device *dev)
 	struct ipa *ipa = dev_get_drvdata(dev);
 
 	ipa_clock_put(ipa);
-	atomic_set(&ipa->suspend_ref, 0);
+	if (!atomic_xchg(&ipa->suspend_ref, 0))
+		dev_err(dev, "suspend: missing suspend clock reference\n");
 
 	return 0;
 }
@@ -933,7 +939,8 @@ 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);
+	if (atomic_xchg(&ipa->suspend_ref, 1))
+		dev_err(dev, "resume: duplicate suspend clock reference\n");
 	ipa_clock_get(ipa);
 
 	return 0;
Signature · 1 line
2.20.1

Alex Elder

author
#0 lore raw

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.

Currently, the GSI interrupt is set up to be a waking interrupt. But the GSI interrupt won't actually fire for a stopped channel (or a channel that underlies a suspended endpoint). The fix involves having the IPA rather than GSI interrupt wake up the AP.

The IPA hardware clock is managed by both the modem and the AP. Even if the AP is in a fully-suspended state, the modem can clock the IPA hardware, and can send a packet through IPA that is destined for an endpoint on the AP.

When the IPA hardware finds a packet's destination is stopped or suspended, it sends an *IPA interrupt* to the destination "execution environment" (EE--in this case, the AP). The desired behavior is for the EE (even if suspended) to be able to handle the incoming packet.

To do this, we arrange for the IPA interrupt to be a wakeup interrupt. And if the system is suspended when that interrupt fires, we trigger a system resume operation. While resuming the system, the IPA driver starts all its channels (or for SDM845, take its endpoints out of suspend mode).

Whenever an RX channel is started, if it has a packet ready to be consumed, the GSI interrupt will fire. At this point the inbound packet that caused this wakeup activity will be received.

The first patch just checks the previous value of a reference counter used for suspend, as precaution to catch bugs. The next three arrange for the IPA interrupt wake up the system. Finally, with this design, we no longer want the GSI interrupt to wake a suspended system, so that is removed by the last patch.`

-Alex

Alex Elder (5):
net: ipa: use atomic exchange for suspend reference
net: ipa: manage endpoints separate from clock
net: ipa: use device_init_wakeup()
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           |  2 --
 drivers/net/ipa/ipa_clock.c     |  4 ---
 drivers/net/ipa/ipa_interrupt.c | 14 ++++++++
 drivers/net/ipa/ipa_main.c      | 62 ++++++++++++++++++---------------
 6 files changed, 51 insertions(+), 49 deletions(-)
Signature · 1 line
2.20.1
author
#9 lore raw

PATCH 5/5 net: ipa: do not enable GSI interrupt for wakeup

We now trigger a system resume when we receive an IPA SUSPEND interrupt. We should *not* wake up on GSI interrupts.

---
 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
index 0e63d35320aaf..cb75f7d540571 100644
@@ -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
index 061312773df09..3f9f29d531c43 100644
@@ -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
author
#7 lore raw

PATCH 3/5 net: ipa: use device_init_wakeup()

In reply to Alex Elder

The 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.

---
 drivers/net/ipa/ipa.h      |  2 --
 drivers/net/ipa/ipa_main.c | 43 ++++++++++++++++----------------------
 2 files changed, 18 insertions(+), 27 deletions(-)
drivers/net/ipa/ipa.h +0 -2
index 407fee841a9a8..a1adc308e030f 100644
@@ -104,8 +104,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 -25

126 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [PATCH net-next 1/5] net: ipa: use atomic exchange for suspend reference

In reply to Alex Elder

From: Alex Elder <[email protected]>
Date: Tue, 8 Sep 2020 19:21:23 -0500

Quoted 11 lines

We take a single IPA clock reference to keep the clock running until we get a system suspend operation. When a system suspend request arrives, we drop that reference, and if that's the last reference (likely) we'll proceed with suspending endpoints and disabling the IPA core clock and interconnects.

In most places we simply set the reference count to 0 or 1 atomically. Instead--primarily to catch coding errors--use an atomic exchange to update the reference count value, and report an error in the event the previous value was unexpected.

Quoted 5 lines

In a few cases it's not hard to see that the error message should never be reported. Report them anyway, but add some excitement to the message by ending it with an exclamation point.

Please use refcount_t if you're wanting to validate things like this.

Thank you.

author
#3 lore raw

Re: [PATCH net-next 1/5] net: ipa: use atomic exchange for suspend reference

Quoted 14 lines · David Miller

From: Alex Elder <[email protected]>
Date: Tue, 8 Sep 2020 19:21:23 -0500

Quoted 11 lines

We take a single IPA clock reference to keep the clock running until we get a system suspend operation. When a system suspend request arrives, we drop that reference, and if that's the last reference (likely) we'll proceed with suspending endpoints and disabling the IPA core clock and interconnects.

In most places we simply set the reference count to 0 or 1 atomically. Instead--primarily to catch coding errors--use an atomic exchange to update the reference count value, and report an error in the event the previous value was unexpected.

Quoted 8 lines
Quoted 5 lines

In a few cases it's not hard to see that the error message should never be reported. Report them anyway, but add some excitement to the message by ending it with an exclamation point.

Please use refcount_t if you're wanting to validate things like this.

There is exactly one reference here; the "reference" is essentially a Boolean flag. So the value is always either 0 or 1.

I can use refcount_dec_if_one() for the 1->0 transition, but I'm not sure how I can do the 0->1 transition with refcount_t. I admit I might be missing something.

Would you like me to add refcount_inc_if_zero()?

Otherwise would you prefer a different naming convention to use for this Boolean "reference count"?

Thanks.

-Alex

Quoted 3 lines

Thank you.

maintainer
#4 lore raw

Re: [PATCH net-next 1/5] net: ipa: use atomic exchange for suspend reference

From: Alex Elder <[email protected]>
Date: Wed, 9 Sep 2020 08:43:44 -0500

Quoted 3 lines

There is exactly one reference here; the "reference" is essentially a Boolean flag. So the value is always either 0 or 1.

Aha, then why not use a bitmask and test_and_set_bit() et al.?

author
#5 lore raw

Re: [PATCH net-next 1/5] net: ipa: use atomic exchange for suspend reference

Quoted 8 lines · David Miller

From: Alex Elder <[email protected]>
Date: Wed, 9 Sep 2020 08:43:44 -0500

Quoted 3 lines

There is exactly one reference here; the "reference" is essentially a Boolean flag. So the value is always either 0 or 1.

Aha, then why not use a bitmask and test_and_set_bit() et al.?

OK I'll go take a look at that option. It's overkill for bits used but it makes it more obvious it's a single bit, so it's probably a better idea.

I'll try to turn this around again by tomorrow. Thank you.

-Alex