diff mbox series

net: wwan: t7xx: Ensure init is completed before system sleep

Message ID 20230516080327.359825-1-kai.heng.feng@canonical.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: wwan: t7xx: Ensure init is completed before system sleep | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 4 maintainers not CCed: matthias.bgg@gmail.com linux-arm-kernel@lists.infradead.org linux-mediatek@lists.infradead.org angelogioacchino.delregno@collabora.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 46 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kai-Heng Feng May 16, 2023, 8:03 a.m. UTC
When the system attempts to sleep while mtk_t7xx is not ready, the driver
cannot put the device to sleep:
[   12.472918] mtk_t7xx 0000:57:00.0: [PM] Exiting suspend, modem in invalid state
[   12.472936] mtk_t7xx 0000:57:00.0: PM: pci_pm_suspend(): t7xx_pci_pm_suspend+0x0/0x20 [mtk_t7xx] returns -14
[   12.473678] mtk_t7xx 0000:57:00.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -14
[   12.473711] mtk_t7xx 0000:57:00.0: PM: failed to suspend async: error -14
[   12.764776] PM: Some devices failed to suspend, or early wake event detected

Mediatek confirmed the device can take a rather long time to complete
its initialization, so wait for up to 20 seconds until init is done.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/net/wwan/t7xx/t7xx_pci.c | 15 +++++++++++++++
 drivers/net/wwan/t7xx/t7xx_pci.h |  1 +
 2 files changed, 16 insertions(+)

Comments

Piotr Raczynski May 16, 2023, 10:42 a.m. UTC | #1
On Tue, May 16, 2023 at 04:03:27PM +0800, Kai-Heng Feng wrote:
> When the system attempts to sleep while mtk_t7xx is not ready, the driver
> cannot put the device to sleep:
> [   12.472918] mtk_t7xx 0000:57:00.0: [PM] Exiting suspend, modem in invalid state
> [   12.472936] mtk_t7xx 0000:57:00.0: PM: pci_pm_suspend(): t7xx_pci_pm_suspend+0x0/0x20 [mtk_t7xx] returns -14
> [   12.473678] mtk_t7xx 0000:57:00.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -14
> [   12.473711] mtk_t7xx 0000:57:00.0: PM: failed to suspend async: error -14
> [   12.764776] PM: Some devices failed to suspend, or early wake event detected
> 
> Mediatek confirmed the device can take a rather long time to complete
> its initialization, so wait for up to 20 seconds until init is done.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Does it fix any issue? Anyway target tree would help here I guess.

[...]

> +static int t7xx_pci_pm_prepare(struct device *dev)
> +{
> +	struct pci_dev *pdev = to_pci_dev(dev);
> +	struct t7xx_pci_dev *t7xx_dev;
> +
> +	t7xx_dev = pci_get_drvdata(pdev);
> +	if (!wait_for_completion_timeout(&t7xx_dev->init_done, 20 * HZ))

#define T7XX_INIT_TIMEOUT or something similar wouldn't do any harm here.

> +		dev_warn(dev, "Not ready for system sleep.\n");
> +
> +	return 0;

So in case of a timeout you still return 0, is that OK?

[...]
Thanks, Piotr.
Kai-Heng Feng May 17, 2023, 4:28 a.m. UTC | #2
On Tue, May 16, 2023 at 6:42 PM Piotr Raczynski
<piotr.raczynski@intel.com> wrote:
>
> On Tue, May 16, 2023 at 04:03:27PM +0800, Kai-Heng Feng wrote:
> > When the system attempts to sleep while mtk_t7xx is not ready, the driver
> > cannot put the device to sleep:
> > [   12.472918] mtk_t7xx 0000:57:00.0: [PM] Exiting suspend, modem in invalid state
> > [   12.472936] mtk_t7xx 0000:57:00.0: PM: pci_pm_suspend(): t7xx_pci_pm_suspend+0x0/0x20 [mtk_t7xx] returns -14
> > [   12.473678] mtk_t7xx 0000:57:00.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x1b0 returns -14
> > [   12.473711] mtk_t7xx 0000:57:00.0: PM: failed to suspend async: error -14
> > [   12.764776] PM: Some devices failed to suspend, or early wake event detected
> >
> > Mediatek confirmed the device can take a rather long time to complete
> > its initialization, so wait for up to 20 seconds until init is done.
> >
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>
> Does it fix any issue? Anyway target tree would help here I guess.

It fixes "PM: failed to suspend async: error -14" mentioned in the
commit message.

>
> [...]
>
> > +static int t7xx_pci_pm_prepare(struct device *dev)
> > +{
> > +     struct pci_dev *pdev = to_pci_dev(dev);
> > +     struct t7xx_pci_dev *t7xx_dev;
> > +
> > +     t7xx_dev = pci_get_drvdata(pdev);
> > +     if (!wait_for_completion_timeout(&t7xx_dev->init_done, 20 * HZ))
>
> #define T7XX_INIT_TIMEOUT or something similar wouldn't do any harm here.

Sure, will do in next revision.

>
> > +             dev_warn(dev, "Not ready for system sleep.\n");
> > +
> > +     return 0;
>
> So in case of a timeout you still return 0, is that OK?

You are right, error code should be returned instead.

Kai-Heng

>
> [...]
> Thanks, Piotr.
diff mbox series

Patch

diff --git a/drivers/net/wwan/t7xx/t7xx_pci.c b/drivers/net/wwan/t7xx/t7xx_pci.c
index 226fc1703e90..7ae85f09cdbf 100644
--- a/drivers/net/wwan/t7xx/t7xx_pci.c
+++ b/drivers/net/wwan/t7xx/t7xx_pci.c
@@ -96,6 +96,7 @@  static int t7xx_pci_pm_init(struct t7xx_pci_dev *t7xx_dev)
 	spin_lock_init(&t7xx_dev->md_pm_lock);
 	init_completion(&t7xx_dev->sleep_lock_acquire);
 	init_completion(&t7xx_dev->pm_sr_ack);
+	init_completion(&t7xx_dev->init_done);
 	atomic_set(&t7xx_dev->md_pm_state, MTK_PM_INIT);
 
 	device_init_wakeup(&pdev->dev, true);
@@ -124,6 +125,7 @@  void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev)
 	pm_runtime_mark_last_busy(&t7xx_dev->pdev->dev);
 	pm_runtime_allow(&t7xx_dev->pdev->dev);
 	pm_runtime_put_noidle(&t7xx_dev->pdev->dev);
+	complete_all(&t7xx_dev->init_done);
 }
 
 static int t7xx_pci_pm_reinit(struct t7xx_pci_dev *t7xx_dev)
@@ -529,6 +531,18 @@  static void t7xx_pci_shutdown(struct pci_dev *pdev)
 	__t7xx_pci_pm_suspend(pdev);
 }
 
+static int t7xx_pci_pm_prepare(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct t7xx_pci_dev *t7xx_dev;
+
+	t7xx_dev = pci_get_drvdata(pdev);
+	if (!wait_for_completion_timeout(&t7xx_dev->init_done, 20 * HZ))
+		dev_warn(dev, "Not ready for system sleep.\n");
+
+	return 0;
+}
+
 static int t7xx_pci_pm_suspend(struct device *dev)
 {
 	return __t7xx_pci_pm_suspend(to_pci_dev(dev));
@@ -555,6 +569,7 @@  static int t7xx_pci_pm_runtime_resume(struct device *dev)
 }
 
 static const struct dev_pm_ops t7xx_pci_pm_ops = {
+	.prepare = t7xx_pci_pm_prepare,
 	.suspend = t7xx_pci_pm_suspend,
 	.resume = t7xx_pci_pm_resume,
 	.resume_noirq = t7xx_pci_pm_resume_noirq,
diff --git a/drivers/net/wwan/t7xx/t7xx_pci.h b/drivers/net/wwan/t7xx/t7xx_pci.h
index 112efa534eac..f08f1ab74469 100644
--- a/drivers/net/wwan/t7xx/t7xx_pci.h
+++ b/drivers/net/wwan/t7xx/t7xx_pci.h
@@ -69,6 +69,7 @@  struct t7xx_pci_dev {
 	struct t7xx_modem	*md;
 	struct t7xx_ccmni_ctrl	*ccmni_ctlb;
 	bool			rgu_pci_irq_en;
+	struct completion	init_done;
 
 	/* Low Power Items */
 	struct list_head	md_pm_entities;