From nobody Sun Feb 8 15:07:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33829C77B75 for ; Tue, 16 May 2023 08:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231395AbjEPIE0 (ORCPT ); Tue, 16 May 2023 04:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230054AbjEPIEX (ORCPT ); Tue, 16 May 2023 04:04:23 -0400 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 590194492; Tue, 16 May 2023 01:04:21 -0700 (PDT) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 1118540203; Tue, 16 May 2023 08:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1684224259; bh=HM165daVVQlgsXpSYpBed1TlG1Fivc1kTbICBUtM1fY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tLYBale+26PODPoS1VF+h6hLhTA1nVg0JrdCtmmL0KuYEfVG6PAheebGbw7kjPzbN 6i5C/D2P9pFO4pkk1xROlDyRyEKLOGk3UHkO1tdo6l7c/SkQTXC11ukItYbKlE0BkC VShaetH7mco8w9HFAppmHL/PXPQhnvPcWhRGWZd69EFPhr2KUYNPVz0spC5xfXSm9v ReoJSrYFMJMX/OKYMyJovKxwvo1XsYhfLFLeGCuetAn26ytB2kw6Q5gPwDFzV19ERs sLXVAHIoLr2YfVNC1b7+i01xqgr6hZSwtZ6sRvbqnqvr/sWNhbs8KdGfOOBdtVjSIV 9nNA24Z5mbJZA== From: Kai-Heng Feng To: chandrashekar.devegowda@intel.com, linuxwwan@intel.com, chiranjeevi.rapolu@linux.intel.com, haijun.liu@mediatek.com, m.chetan.kumar@linux.intel.com, ricardo.martinez@linux.intel.com Cc: Kai-Heng Feng , Loic Poulain , Sergey Ryazanov , Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: wwan: t7xx: Ensure init is completed before system sleep Date: Tue, 16 May 2023 16:03:27 +0800 Message-Id: <20230516080327.359825-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 invali= d state [ 12.472936] mtk_t7xx 0000:57:00.0: PM: pci_pm_suspend(): t7xx_pci_pm_sus= pend+0x0/0x20 [mtk_t7xx] returns -14 [ 12.473678] mtk_t7xx 0000:57:00.0: PM: dpm_run_callback(): pci_pm_suspen= d+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 dete= cted 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 --- drivers/net/wwan/t7xx/t7xx_pci.c | 15 +++++++++++++++ drivers/net/wwan/t7xx/t7xx_pci.h | 1 + 2 files changed, 16 insertions(+) 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); =20 device_init_wakeup(&pdev->dev, true); @@ -124,6 +125,7 @@ void t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_de= v) 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); } =20 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); } =20 +static int t7xx_pci_pm_prepare(struct device *dev) +{ + struct pci_dev *pdev =3D to_pci_dev(dev); + struct t7xx_pci_dev *t7xx_dev; + + t7xx_dev =3D 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 *de= v) } =20 static const struct dev_pm_ops t7xx_pci_pm_ops =3D { + .prepare =3D t7xx_pci_pm_prepare, .suspend =3D t7xx_pci_pm_suspend, .resume =3D t7xx_pci_pm_resume, .resume_noirq =3D 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; =20 /* Low Power Items */ struct list_head md_pm_entities; --=20 2.34.1