Netdev List
 help / color / mirror / Atom feed
From: David Westen <davidlwesten@gmail.com>
To: netdev@vger.kernel.org
Cc: Loic Poulain <loic.poulain@oss.qualcomm.com>,
	Sergey Ryazanov <ryazanov.s.a@gmail.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	M Chetan Kumar <m.chetan.kumar@intel.com>,
	"Maciej S. Szmigiero" <mail@maciej.szmigiero.name>,
	David Westen <davidlwesten@gmail.com>
Subject: [PATCH net v3 2/2] net: wwan: iosm: re-bind the driver when the modem rebooted during S3
Date: Thu, 26 Nov 2026 11:41:43 -0800	[thread overview]
Message-ID: <20261126194143.32283-3-davidlwesten@gmail.com> (raw)
In-Reply-To: <20261126194143.32283-1-davidlwesten@gmail.com>

On platforms where S3 cuts power to the WWAN card, the modem boots
again while the driver still treats it as running, and the first port
open after resume fails:

  iosm 0000:03:00.0: PORT open refused, phase A-CD_READY

The driver takes this from a stale stage in the shared memory: on an
XMM7360, the modem writes CD_READY there before it loses power. The
modem itself is fine.

On resume, read the stage from the MMIO area. If the modem booted
again, mark it as gone: the driver then neither talks to it nor waits
for it, and the cleanup only releases memory. Once the modem has
reached the run stage, re-bind the driver, so that probe finds it as
after a cold boot. Nothing changes where the card keeps power, and a
crashed modem is left alone.

Tested with S3 on an XMM7360 in a ThinkPad X1 Carbon 6th gen, with
KASAN, lockdep and a strict IOMMU: five cycles, also with wwan0 up
through the suspend.

Fixes: 7e98d785ae61 ("net: iosm: entry point")
Signed-off-by: David Westen <davidlwesten@gmail.com>
---
 drivers/net/wwan/iosm/iosm_ipc_imem.c      | 47 +++++++++++++++++++++-
 drivers/net/wwan/iosm/iosm_ipc_imem.h      | 18 +++++++++
 drivers/net/wwan/iosm/iosm_ipc_imem_ops.c  |  4 ++
 drivers/net/wwan/iosm/iosm_ipc_irq.c       |  3 ++
 drivers/net/wwan/iosm/iosm_ipc_mux_codec.c |  6 +++
 drivers/net/wwan/iosm/iosm_ipc_pcie.c      | 37 +++++++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_protocol.c  |  3 ++
 7 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.c b/drivers/net/wwan/iosm/iosm_ipc_imem.c
index 3ab409166c50..673c5ad403e7 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_imem.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_imem.c
@@ -208,6 +208,9 @@ void ipc_imem_hrtimer_stop(struct hrtimer *hr_timer)
  */
 void ipc_imem_adb_timer_start(struct iosm_imem *ipc_imem)
 {
+	if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag))
+		return;
+
 	if (!hrtimer_active(&ipc_imem->adb_timer)) {
 		ipc_imem->hrtimer_period =
 			ktime_set(0, IOSM_AGGR_MUX_ADB_FINISH_TIMEOUT_NSEC);
@@ -1042,6 +1045,44 @@ void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep)
 	ipc_protocol_s2idle_sleep(ipc_imem->ipc_protocol, sleep);
 }
 
+bool ipc_imem_modem_rebooted(struct iosm_imem *ipc_imem)
+{
+	if (!test_bit(FULLY_FUNCTIONAL, &ipc_imem->flag))
+		return false;
+
+	switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) {
+	case IPC_MEM_EXEC_STAGE_RUN:
+		return ipc_mmio_get_ipc_state(ipc_imem->mmio) ==
+		       IPC_MEM_DEVICE_IPC_UNINIT;
+	case IPC_MEM_EXEC_STAGE_CRASH:
+	case IPC_MEM_EXEC_STAGE_CD_READY:
+	case IPC_MEM_EXEC_STAGE_INVALID:
+		return false;
+	default:
+		return true;
+	}
+}
+
+bool ipc_imem_wait_for_run(struct iosm_imem *ipc_imem)
+{
+	int timeout = IPC_MODEM_BOOT_TIMEOUT;
+
+	for (;;) {
+		switch (ipc_mmio_get_exec_stage(ipc_imem->mmio)) {
+		case IPC_MEM_EXEC_STAGE_RUN:
+			return true;
+		case IPC_MEM_EXEC_STAGE_CRASH:
+		case IPC_MEM_EXEC_STAGE_CD_READY:
+			return false;
+		default:
+			break;
+		}
+		if (!--timeout)
+			return false;
+		msleep(20);
+	}
+}
+
 void ipc_imem_pm_resume(struct iosm_imem *ipc_imem)
 {
 	enum ipc_mem_exec_stage stage;
@@ -1204,6 +1245,9 @@ static void ipc_imem_device_ipc_uninit(struct iosm_imem *ipc_imem)
 	int timeout = IPC_MODEM_UNINIT_TIMEOUT_MS;
 	enum ipc_mem_device_ipc_state ipc_state;
 
+	if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag))
+		return;
+
 	/* When PCIe link is up set IPC_UNINIT
 	 * of the modem otherwise ignore it when PCIe link down happens.
 	 */
@@ -1440,7 +1484,8 @@ struct iosm_imem *ipc_imem_init(struct iosm_pcie *pcie, unsigned int device_id,
 void ipc_imem_irq_process(struct iosm_imem *ipc_imem, int irq)
 {
 	/* Debounce IPC_EV_IRQ. */
-	if (ipc_imem && !ipc_imem->ev_irq_pending[irq]) {
+	if (ipc_imem && !ipc_imem->ev_irq_pending[irq] &&
+	    !test_bit(IOSM_MODEM_GONE, &ipc_imem->flag)) {
 		ipc_imem->ev_irq_pending[irq] = true;
 		ipc_task_queue_send_task(ipc_imem, ipc_imem_tq_irq_cb, irq,
 					 NULL, 0, false);
diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem.h b/drivers/net/wwan/iosm/iosm_ipc_imem.h
index 5664ac507c90..3f6d1ccf2a7c 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_imem.h
+++ b/drivers/net/wwan/iosm/iosm_ipc_imem.h
@@ -102,6 +102,8 @@ struct ipc_chnl_cfg;
 
 #define FULLY_FUNCTIONAL 0
 #define IOSM_DEVLINK_INIT 1
+/* The modem rebooted: don't talk to it or wait for it until the re-bind */
+#define IOSM_MODEM_GONE 2
 
 /* List of the supported UL/DL pipes. */
 enum ipc_mem_pipes {
@@ -404,6 +406,22 @@ void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep);
  */
 void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem);
 
+/**
+ * ipc_imem_modem_rebooted - Check whether the modem booted again
+ * @ipc_imem:	Pointer to imem data-struct
+ *
+ * Returns: true if it did after the driver had brought it up
+ */
+bool ipc_imem_modem_rebooted(struct iosm_imem *ipc_imem);
+
+/**
+ * ipc_imem_wait_for_run - Wait up to about 10 s for the run stage
+ * @ipc_imem:	Pointer to imem data-struct
+ *
+ * Returns: true if the modem reached it
+ */
+bool ipc_imem_wait_for_run(struct iosm_imem *ipc_imem);
+
 /**
  * ipc_imem_pm_resume - The HAL shall inform the shared memory layer
  *			that the device is active.
diff --git a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c
index 109cf8930488..8cff81919480 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_imem_ops.c
@@ -218,6 +218,9 @@ void ipc_imem_sys_port_close(struct iosm_imem *ipc_imem,
 		return;
 	}
 
+	if (test_bit(IOSM_MODEM_GONE, &ipc_imem->flag))
+		goto close;
+
 	/* If there are any pending TDs then wait for Timeout/Completion before
 	 * closing pipe.
 	 */
@@ -267,6 +270,7 @@ void ipc_imem_sys_port_close(struct iosm_imem *ipc_imem,
 		ipc_imem->app_notify_dl_pend = 0;
 	}
 
+close:
 	/* Due to wait for completion in messages, there is a small window
 	 * between closing the pipe and updating the channel is closed. In this
 	 * small window there could be HP update from Host Driver. Hence update
diff --git a/drivers/net/wwan/iosm/iosm_ipc_irq.c b/drivers/net/wwan/iosm/iosm_ipc_irq.c
index 702f50a48151..d9d0e28fafae 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_irq.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_irq.c
@@ -25,6 +25,9 @@ static void ipc_write_dbell_reg(struct iosm_pcie *ipc_pcie, int irq_n, u32 data)
 
 void ipc_doorbell_fire(struct iosm_pcie *ipc_pcie, int irq_n, u32 data)
 {
+	if (ipc_pcie->imem && test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag))
+		return;
+
 	ipc_write_dbell_reg(ipc_pcie, irq_n, data);
 }
 
diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
index 0bbd41263cc2..a31f6fa7ea55 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
@@ -150,6 +150,9 @@ int ipc_mux_dl_acb_send_cmds(struct iosm_mux *ipc_mux, u32 cmd_type, u8 if_id,
 	union mux_type_cmdh cmdh;
 	int ret = 0;
 
+	if (test_bit(IOSM_MODEM_GONE, &ipc_mux->imem->flag))
+		return -EIO;
+
 	acb->if_id = if_id;
 	ret = ipc_mux_acb_alloc(ipc_mux);
 	if (ret)
@@ -1525,6 +1528,9 @@ int ipc_mux_ul_trigger_encode(struct iosm_mux *ipc_mux, int if_id,
 	struct mux_session *session = &ipc_mux->session[if_id];
 	int ret = -EINVAL;
 
+	if (test_bit(IOSM_MODEM_GONE, &ipc_mux->imem->flag))
+		return -EIO;
+
 	if (ipc_mux->channel &&
 	    ipc_mux->channel->state != IMEM_CHANNEL_ACTIVE) {
 		dev_err(ipc_mux->dev,
diff --git a/drivers/net/wwan/iosm/iosm_ipc_pcie.c b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
index 49052eb511ba..767a609462b4 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_pcie.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_pcie.c
@@ -427,6 +427,10 @@ static int __maybe_unused ipc_pcie_resume_cb(struct device *dev)
 
 	ipc_pcie = pci_get_drvdata(pdev);
 
+	/* pm_notify() re-binds the driver for a modem that booted again */
+	if (ipc_imem_modem_rebooted(ipc_pcie->imem))
+		set_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag);
+
 	switch (ipc_pcie->d3l2_support) {
 	case IPC_PCIE_D0L12:
 		ipc_pcie_resume_s2idle(ipc_pcie);
@@ -532,6 +536,37 @@ void ipc_pcie_kfree_skb(struct iosm_pcie *ipc_pcie, struct sk_buff *skb)
 	dev_kfree_skb(skb);
 }
 
+static void ipc_pcie_rebind_if_rebooted(struct pci_dev *pdev)
+{
+	struct iosm_pcie *ipc_pcie;
+	bool rebooted = false;
+
+	device_lock(&pdev->dev);
+	if (pdev->dev.driver == &iosm_ipc_driver.driver) {
+		ipc_pcie = pci_get_drvdata(pdev);
+		rebooted = test_bit(IOSM_MODEM_GONE, &ipc_pcie->imem->flag);
+		/* Let probe find it in the run stage, as after a cold boot */
+		if (rebooted && !ipc_imem_wait_for_run(ipc_pcie->imem))
+			dev_warn(&pdev->dev, "modem not running after resume");
+	}
+	device_unlock(&pdev->dev);
+
+	if (rebooted && device_reprobe(&pdev->dev))
+		dev_err(&pdev->dev, "re-binding the driver failed");
+}
+
+static void ipc_pcie_rebind_rebooted(void)
+{
+	const struct pci_device_id *id;
+	struct pci_dev *pdev;
+
+	for (id = iosm_ipc_ids; id->vendor; id++) {
+		pdev = NULL;
+		while ((pdev = pci_get_device(id->vendor, id->device, pdev)))
+			ipc_pcie_rebind_if_rebooted(pdev);
+	}
+}
+
 static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused)
 {
 	if (mode == PM_HIBERNATION_PREPARE || mode == PM_RESTORE_PREPARE) {
@@ -551,6 +586,8 @@ static int pm_notify(struct notifier_block *nb, unsigned long mode, void *_unuse
 				pci_registered = true;
 			}
 		}
+	} else if (mode == PM_POST_SUSPEND) {
+		ipc_pcie_rebind_rebooted();
 	}
 
 	return 0;
diff --git a/drivers/net/wwan/iosm/iosm_ipc_protocol.c b/drivers/net/wwan/iosm/iosm_ipc_protocol.c
index 527355a671b6..a49a45ed0b0d 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_protocol.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_protocol.c
@@ -69,6 +69,9 @@ int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol,
 	/* Trap if called from non-preemptible context */
 	might_sleep();
 
+	if (test_bit(IOSM_MODEM_GONE, &ipc_protocol->imem->flag))
+		return -EIO;
+
 	response.status = IPC_MEM_MSG_CS_INVALID;
 	init_completion(&response.completion);
 
-- 
2.56.0


      parent reply	other threads:[~2026-11-26 19:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 19:41 [PATCH net v3 0/2] net: wwan: iosm: fix S3 resume by re-binding the driver after it David Westen
2026-11-26 19:41 ` [PATCH net v3 1/2] net: wwan: iosm: free the MUX after the netdevs that use it David Westen
2026-11-26 19:41 ` David Westen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126194143.32283-3-davidlwesten@gmail.com \
    --to=davidlwesten@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=m.chetan.kumar@intel.com \
    --cc=mail@maciej.szmigiero.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox