Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net-next 0/5] net: ipa: add clock references
@ 2021-07-27 21:19 Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 1/5] net: ipa: get clock in ipa_probe() Alex Elder
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

This series continues preparation for implementing runtime power
management for IPA.  We need to ensure that the IPA core clock and
interconnects are operational whenever IPA hardware is accessed.
And in particular this means that any external entry point that can
lead to accessing IPA hardware must guarantee the hardware is "up"
when it is accessed.

The first four patches in this series take IPA clock references when
needed by such external entry points, dropping those references in
those same functions when they are no longer required.

The last patch is a bit different, though it too prepares for
enabling runtime power management.  It avoids suspending/resuming
endpoints if setup is not complete.

					-Alex

Alex Elder (5):
  net: ipa: get clock in ipa_probe()
  net: ipa: get another clock for ipa_setup()
  net: ipa: add clock reference for remoteproc SSR
  net: ipa: add a clock reference for netdev operations
  net: ipa: don't suspend endpoints if setup not complete

 drivers/net/ipa/ipa_main.c  | 37 ++++++++++++++++++++++++++-----------
 drivers/net/ipa/ipa_modem.c | 14 +++++++++++++-
 drivers/net/ipa/ipa_smp2p.c |  5 +++++
 3 files changed, 44 insertions(+), 12 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/5] net: ipa: get clock in ipa_probe()
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
@ 2021-07-27 21:19 ` Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 2/5] net: ipa: get another clock for ipa_setup() Alex Elder
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

Any entry point that leads to IPA hardware access must ensure the
hardware is operational (clocked).  Currently we ensure this by
taking an extra clock reference during setup that is not released
until we receive a system suspend request.  But this extra reference
will soon go away.

When the platform driver ->probe function is called, we first need
hardware access in ipa_config().  Although ipa_config() takes an IPA
clock reference, it the special reference taken to prevent suspending
the hardware.

Have ipa_probe() take a reference before calling ipa_config(), so
that the "no-suspend" reference can eventually go away.  Drop this
reference before ipa_probe() returns.

Similarly, the driver ->remove function can be called at any time.
Take an IPA clock reference at the beginning of that function, and
drop it again after the deconfig stage has completed (at which point
hardware access is no longer needed).

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_main.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 5bcc6cd13a9a0..67aba68e6e3b4 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -770,9 +770,12 @@ static int ipa_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_table_exit;
 
+	/* The clock needs to be active for config and setup */
+	ipa_clock_get(ipa);
+
 	ret = ipa_config(ipa, data);
 	if (ret)
-		goto err_modem_exit;
+		goto err_clock_put;	/* Error */
 
 	dev_info(dev, "IPA driver initialized");
 
@@ -781,7 +784,7 @@ static int ipa_probe(struct platform_device *pdev)
 	 * we're done here.
 	 */
 	if (modem_init)
-		return 0;
+		goto out_clock_put;	/* Done; no error */
 
 	/* Otherwise we need to load the firmware and have Trust Zone validate
 	 * and install it.  If that succeeds we can proceed with setup.
@@ -794,11 +797,15 @@ static int ipa_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_deconfig;
 
+out_clock_put:
+	ipa_clock_put(ipa);
+
 	return 0;
 
 err_deconfig:
 	ipa_deconfig(ipa);
-err_modem_exit:
+err_clock_put:
+	ipa_clock_put(ipa);
 	ipa_modem_exit(ipa);
 err_table_exit:
 	ipa_table_exit(ipa);
@@ -824,6 +831,8 @@ static int ipa_remove(struct platform_device *pdev)
 	struct ipa_clock *clock = ipa->clock;
 	int ret;
 
+	ipa_clock_get(ipa);
+
 	if (ipa->setup_complete) {
 		ret = ipa_modem_stop(ipa);
 		/* If starting or stopping is in progress, try once more */
@@ -838,6 +847,9 @@ static int ipa_remove(struct platform_device *pdev)
 	}
 
 	ipa_deconfig(ipa);
+
+	ipa_clock_put(ipa);
+
 	ipa_modem_exit(ipa);
 	ipa_table_exit(ipa);
 	ipa_endpoint_exit(ipa);
-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/5] net: ipa: get another clock for ipa_setup()
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 1/5] net: ipa: get clock in ipa_probe() Alex Elder
@ 2021-07-27 21:19 ` Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 3/5] net: ipa: add clock reference for remoteproc SSR Alex Elder
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

Two places call ipa_setup().  The first, ipa_probe(), holds an IPA
clock reference when calling ipa_setup() (if the AP is responsible
for IPA firmware loading).  But if the modem is loading IPA
firmware, ipa_smp2p_modem_setup_ready_isr() calls ipa_setup() after
the modem has signaled the hardware is ready.  This can happen at
any time, and there is no guarantee the hardware is active.

Have ipa_smp2p_modem_setup() take an IPA clock reference before it
calls ipa_setup(), and release it once setup is complete.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_smp2p.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ipa/ipa_smp2p.c b/drivers/net/ipa/ipa_smp2p.c
index 93270e50b6b35..0d15438a79e2d 100644
--- a/drivers/net/ipa/ipa_smp2p.c
+++ b/drivers/net/ipa/ipa_smp2p.c
@@ -156,11 +156,16 @@ static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id)
 	if (!smp2p->disabled) {
 		int ret;
 
+		/* The clock needs to be active for setup */
+		ipa_clock_get(smp2p->ipa);
+
 		ret = ipa_setup(smp2p->ipa);
 		if (ret)
 			dev_err(&smp2p->ipa->pdev->dev,
 				"error %d from ipa_setup()\n", ret);
 		smp2p->disabled = true;
+
+		ipa_clock_put(smp2p->ipa);
 	}
 
 	mutex_unlock(&smp2p->mutex);
-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/5] net: ipa: add clock reference for remoteproc SSR
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 1/5] net: ipa: get clock in ipa_probe() Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 2/5] net: ipa: get another clock for ipa_setup() Alex Elder
@ 2021-07-27 21:19 ` Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 4/5] net: ipa: add a clock reference for netdev operations Alex Elder
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

The remoteproc SSR callback function for the modem requires hardware
access when handling a modem crash or shutdown.  Take and later
release an IPA clock reference in ipa_modem_crashed(), to ensure the
hardware is operational.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_modem.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index c851e2cf12552..a744b81db0d9f 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -20,6 +20,7 @@
 #include "ipa_smp2p.h"
 #include "ipa_qmi.h"
 #include "ipa_uc.h"
+#include "ipa_clock.h"
 
 #define IPA_NETDEV_NAME		"rmnet_ipa%d"
 #define IPA_NETDEV_TAILROOM	0	/* for padding by mux layer */
@@ -279,6 +280,8 @@ static void ipa_modem_crashed(struct ipa *ipa)
 	struct device *dev = &ipa->pdev->dev;
 	int ret;
 
+	ipa_clock_get(ipa);
+
 	ipa_endpoint_modem_pause_all(ipa, true);
 
 	ipa_endpoint_modem_hol_block_clear_all(ipa);
@@ -303,6 +306,8 @@ static void ipa_modem_crashed(struct ipa *ipa)
 	ret = ipa_mem_zero_modem(ipa);
 	if (ret)
 		dev_err(dev, "error %d zeroing modem memory regions\n", ret);
+
+	ipa_clock_put(ipa);
 }
 
 static int ipa_modem_notify(struct notifier_block *nb, unsigned long action,
-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 4/5] net: ipa: add a clock reference for netdev operations
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
                   ` (2 preceding siblings ...)
  2021-07-27 21:19 ` [PATCH net-next 3/5] net: ipa: add clock reference for remoteproc SSR Alex Elder
@ 2021-07-27 21:19 ` Alex Elder
  2021-07-27 21:19 ` [PATCH net-next 5/5] net: ipa: don't suspend endpoints if setup not complete Alex Elder
  2021-07-27 23:10 ` [PATCH net-next 0/5] net: ipa: add clock references patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

The IPA network device can be opened at any time, and an opened
network device can be stopped any time.  Both of these callback
functions require access to the hardware, and therefore they need
the IPA clock to be operational.  Take an IPA clock reference in
both the ->open and ->stop callback functions, dropping the
reference when they are done accessing hardware.

The ->start_xmit callback requires a little different handling,
and that will be added separately.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_modem.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index a744b81db0d9f..4ea8287e9d237 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -45,9 +45,12 @@ static int ipa_open(struct net_device *netdev)
 	struct ipa *ipa = priv->ipa;
 	int ret;
 
+	ipa_clock_get(ipa);
+
 	ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
 	if (ret)
-		return ret;
+		goto err_clock_put;
+
 	ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
 	if (ret)
 		goto err_disable_tx;
@@ -58,6 +61,8 @@ static int ipa_open(struct net_device *netdev)
 
 err_disable_tx:
 	ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
+err_clock_put:
+	ipa_clock_put(ipa);
 
 	return ret;
 }
@@ -73,6 +78,8 @@ static int ipa_stop(struct net_device *netdev)
 	ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
 	ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
 
+	ipa_clock_put(ipa);
+
 	return 0;
 }
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 5/5] net: ipa: don't suspend endpoints if setup not complete
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
                   ` (3 preceding siblings ...)
  2021-07-27 21:19 ` [PATCH net-next 4/5] net: ipa: add a clock reference for netdev operations Alex Elder
@ 2021-07-27 21:19 ` Alex Elder
  2021-07-27 23:10 ` [PATCH net-next 0/5] net: ipa: add clock references patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Alex Elder @ 2021-07-27 21:19 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, elder, netdev,
	linux-kernel

Until we complete the setup stage of initialization, GSI is not
initialized and therefore endpoints aren't usable.  So avoid
suspending endpoints during system suspend unless setup is complete.

Clear the setup_complete flag at the top of ipa_teardown() to
reflect the fact that things are no longer in setup state.

Get rid of a misplaced (and superfluous) comment.

Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/ipa_main.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 67aba68e6e3b4..2e728d4914c82 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -194,6 +194,9 @@ static void ipa_teardown(struct ipa *ipa)
 	struct ipa_endpoint *exception_endpoint;
 	struct ipa_endpoint *command_endpoint;
 
+	/* We're going to tear everything down, as if setup never completed */
+	ipa->setup_complete = false;
+
 	ipa_qmi_teardown(ipa);
 	ipa_endpoint_default_route_clear(ipa);
 	exception_endpoint = ipa->name_map[IPA_ENDPOINT_AP_LAN_RX];
@@ -885,13 +888,11 @@ 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);
+	/* Endpoints aren't usable until setup is complete */
+	if (ipa->setup_complete) {
+		__clear_bit(IPA_FLAG_RESUMED, ipa->flags);
+		ipa_endpoint_suspend(ipa);
+	}
 
 	ipa_clock_put(ipa);
 
@@ -917,7 +918,9 @@ static int ipa_resume(struct device *dev)
 	 */
 	ipa_clock_get(ipa);
 
-	ipa_endpoint_resume(ipa);
+	/* Endpoints aren't usable until setup is complete */
+	if (ipa->setup_complete)
+		ipa_endpoint_resume(ipa);
 
 	return 0;
 }
-- 
2.27.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/5] net: ipa: add clock references
  2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
                   ` (4 preceding siblings ...)
  2021-07-27 21:19 ` [PATCH net-next 5/5] net: ipa: don't suspend endpoints if setup not complete Alex Elder
@ 2021-07-27 23:10 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-27 23:10 UTC (permalink / raw)
  To: Alex Elder
  Cc: davem, kuba, bjorn.andersson, evgreen, cpratapa, subashab, elder,
	netdev, linux-kernel

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

On Tue, 27 Jul 2021 16:19:28 -0500 you wrote:
> This series continues preparation for implementing runtime power
> management for IPA.  We need to ensure that the IPA core clock and
> interconnects are operational whenever IPA hardware is accessed.
> And in particular this means that any external entry point that can
> lead to accessing IPA hardware must guarantee the hardware is "up"
> when it is accessed.
> 
> [...]

Here is the summary with links:
  - [net-next,1/5] net: ipa: get clock in ipa_probe()
    https://git.kernel.org/netdev/net-next/c/923a6b698447
  - [net-next,2/5] net: ipa: get another clock for ipa_setup()
    https://git.kernel.org/netdev/net-next/c/cf8dfe6ab8e7
  - [net-next,3/5] net: ipa: add clock reference for remoteproc SSR
    https://git.kernel.org/netdev/net-next/c/34c6034b4764
  - [net-next,4/5] net: ipa: add a clock reference for netdev operations
    https://git.kernel.org/netdev/net-next/c/f2b0355363f3
  - [net-next,5/5] net: ipa: don't suspend endpoints if setup not complete
    https://git.kernel.org/netdev/net-next/c/2c257248ce8e

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-27 23:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 21:19 [PATCH net-next 0/5] net: ipa: add clock references Alex Elder
2021-07-27 21:19 ` [PATCH net-next 1/5] net: ipa: get clock in ipa_probe() Alex Elder
2021-07-27 21:19 ` [PATCH net-next 2/5] net: ipa: get another clock for ipa_setup() Alex Elder
2021-07-27 21:19 ` [PATCH net-next 3/5] net: ipa: add clock reference for remoteproc SSR Alex Elder
2021-07-27 21:19 ` [PATCH net-next 4/5] net: ipa: add a clock reference for netdev operations Alex Elder
2021-07-27 21:19 ` [PATCH net-next 5/5] net: ipa: don't suspend endpoints if setup not complete Alex Elder
2021-07-27 23:10 ` [PATCH net-next 0/5] net: ipa: add clock references patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).