Skip to contentSkip to conversation

net: wwan: iosm: send the host sleep message on every suspend

PATCH New David Westen 1 participant 4 messages Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover net: wwan: iosm: send the host sleep message on every suspend

On platforms whose BIOS doesn't select D3L2, iosm tells the modem about system suspend with the FORCE_SLEEP and FORCE_ACTIVE doorbells, which the XMM7360 in a ThinkPad X1 Carbon 6th gen doesn't survive. Patch 3 always uses the ENTER_SLEEP/EXIT_SLEEP host sleep messages instead, as discussed in the v1 review. Patches 1 and 2 fix two bugs in that handshake that so far only D3L2 platforms could hit.

Changes in v2:
- New patches 1 and 2, for issues the AI review of v1 found.
- Patch 3: rewrite the commit message and remove the doorbell path with everything only it used (Loic).
- Patch 3: fix the Fixes: tag and the comment, and describe testing and hibernation in the commit message (AI review).

Tested on an XMM7360 with suspend-to-idle, including overnight. Not tested on the XMM7560 or on a platform where the doorbells work.

v1: https://lore.kernel.org/r/[email protected]

The investigation and the patches were done with an AI coding assistant (Claude Opus 5.5). We wrote the patches together, and I ran the tests.

David Westen (3):
net: wwan: iosm: reset the host PM state when the sleep handshake
times out
net: wwan: iosm: fix the wait for the modem in the host sleep
handshake
net: wwan: iosm: always send the host sleep message on suspend

 drivers/net/wwan/iosm/iosm_ipc_imem.c     |  5 --
 drivers/net/wwan/iosm/iosm_ipc_imem.h     |  8 --
 drivers/net/wwan/iosm/iosm_ipc_irq.c      |  3 +-
 drivers/net/wwan/iosm/iosm_ipc_pcie.c     | 96 ++---------------------
 drivers/net/wwan/iosm/iosm_ipc_pcie.h     | 14 ----
 drivers/net/wwan/iosm/iosm_ipc_pm.c       | 43 +++++-----
 drivers/net/wwan/iosm/iosm_ipc_pm.h       |  7 --
 drivers/net/wwan/iosm/iosm_ipc_protocol.c |  7 +-
 drivers/net/wwan/iosm/iosm_ipc_protocol.h |  8 --
 9 files changed, 28 insertions(+), 163 deletions(-)

base-commit: af6737b9066832a2017c281159950ba92385ce00

Signature · 1 line
2.56.0
#1 lore raw

PATCH v2 1/3 net: wwan: iosm: reset the host PM state when the sleep handshake times out

ipc_protocol_suspend() moves host_pm_state from ACTIVE to SLEEP_WAIT_D3 before it wakes the modem to send the ENTER_SLEEP message. If the modem doesn't report itself active in time, the function gives up but leaves the state at SLEEP_WAIT_D3.

From then on the driver is stuck: resume skips EXIT_SLEEP because it expects SLEEP, every later suspend is refused because it expects ACTIVE, and doorbells to the modem are held back as pending, so no data moves until the driver is bound again.

Set the state back to ACTIVE on this path, as the path where sending ENTER_SLEEP fails already does.

Found by an AI code review agent, not triggered. Tested on an XMM7360 with suspend-to-idle.

Fixes faed4c6f6f48 ("net: iosm: shared memory protocol")
---
 drivers/net/wwan/iosm/iosm_ipc_protocol.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wwan/iosm/iosm_ipc_protocol.c +2 -0
index 527355a671b6..e120e1e0ba1d 100644
@@ -185,6 +185,8 @@ bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol)
 
 	if (!ipc_pm_wait_for_device_active(&ipc_protocol->pm)) {
 		ipc_uevent_send(ipc_protocol->pcie->dev, UEVENT_MDM_TIMEOUT);
+		/* The modem wasn't told to sleep, we are still active */
+		ipc_protocol->pm.host_pm_state = IPC_MEM_HOST_PM_ACTIVE;
 		goto err;
 	}
 
Signature · 1 line
2.56.0
#2 lore raw

PATCH v2 2/3 net: wwan: iosm: fix the wait for the modem in the host sleep handshake

In reply to David Westen

Before the ENTER_SLEEP message is sent, ipc_pm_wait_for_device_active() waits for the modem to report itself active, but:

- it tests ap_state before it sets the bit that asks the tasklet for a wake-up, so a wake-up in between is lost and the wait times out
- a wake-up that arrives after a timeout leaves the completion done, so a later wait returns at once
- an -ERESTARTSYS return from the interruptible wait counts as success

Set the bit first, paired with a barrier in the tasklet, reinitialize the completion before each wait, and wait uninterruptibly, like the wait for the ENTER_SLEEP reply does.

Found by an AI code review agent, not reproduced. Tested on an XMM7360 with suspend-to-idle.

Fixes be8c936e540f ("net: iosm: power management")
---
 drivers/net/wwan/iosm/iosm_ipc_pm.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_pm.c +20 -9
index 413601c72dcd..c76cb9663039 100644
@@ -72,19 +72,25 @@ bool ipc_pm_wait_for_device_active(struct iosm_pm *ipc_pm)
 {
 	bool ret_val = false;
 
-	if (ipc_pm->ap_state != IPC_MEM_DEV_PM_ACTIVE) {
-		/* Complete all memory stores before setting bit */
-		smp_mb__before_atomic();
+	/* Drop a completion left over from an earlier timeout */
+	reinit_completion(&ipc_pm->host_sleep_complete);
 
+	/* Complete all memory stores before setting bit */
+	smp_mb__before_atomic();
+
+	set_bit(0, &ipc_pm->host_sleep_pend);
+
+	/* Set the bit before testing ap_state, so that a wake-up after the
+	 * test completes host_sleep_complete. Pairs with the barrier in
+	 * ipc_pm_on_link_wake().
+	 */
+	smp_mb__after_atomic();
+
+	if (ipc_pm->ap_state != IPC_MEM_DEV_PM_ACTIVE) {
 		/* Wait for IPC_PM_ACTIVE_TIMEOUT_MS for Device sleep state
 		 * machine to enter ACTIVE state.
 		 */
-		set_bit(0, &ipc_pm->host_sleep_pend);
-
-		/* Complete all memory stores after setting bit */
-		smp_mb__after_atomic();
-
-		if (!wait_for_completion_interruptible_timeout
+		if (!wait_for_completion_timeout
 		   (&ipc_pm->host_sleep_complete,
 		    msecs_to_jiffies(IPC_PM_ACTIVE_TIMEOUT_MS))) {
 			dev_err(ipc_pm->dev,
@@ -130,6 +136,11 @@ static void ipc_pm_on_link_wake(struct iosm_pm *ipc_pm, bool ack)
 
 		ipc_cp_irq_sleep_control(ipc_pm->pcie, IPC_MEM_DEV_PM_ACTIVE);
 
+		/* Order the ap_state store before the bit test, pairs with
+		 * ipc_pm_wait_for_device_active().
+		 */
+		smp_mb();
+
 		/* check the consume state !!! */
 		if (test_bit(CONSUME_STATE, &ipc_pm->host_sleep_pend))
 			complete(&ipc_pm->host_sleep_complete);
Signature · 1 line
2.56.0
#3 lore raw

PATCH v2 3/3 net: wwan: iosm: always send the host sleep message on suspend

In reply to David Westen

The driver picks how to tell the modem about system suspend from a BIOS RTD3 setting: the ENTER_SLEEP and EXIT_SLEEP host sleep messages for D3L2, otherwise the FORCE_SLEEP and FORCE_ACTIVE doorbells. The doorbells don't wait for the modem, and the PCI core may put the device into D3hot either way.

On a ThinkPad X1 Carbon 6th gen, whose BIOS has no WWAN _DSM, the XMM7360 doesn't survive the doorbells: after suspend-to-idle it is in CD_READY ("PORT open refused, phase A-CD_READY") until an ACPI reset. Keeping the device in D0 doesn't help either.

Always send the host sleep messages, and remove the doorbell path, the BIOS setting and the suspend flag that only that path used. MSIs that arrive between the suspend and resume callbacks are now processed, as they already were with D3L2.

Tested on an XMM7360 with suspend-to-idle, not on the XMM7560. On kernels that don't unbind the driver around hibernation yet, hibernation also switches to the host sleep messages.

Fixes 7e98d785ae61 ("net: iosm: entry point")
---
 drivers/net/wwan/iosm/iosm_ipc_imem.c     |  5 --
 drivers/net/wwan/iosm/iosm_ipc_imem.h     |  8 --
 drivers/net/wwan/iosm/iosm_ipc_irq.c      |  3 +-
 drivers/net/wwan/iosm/iosm_ipc_pcie.c     | 96 ++---------------------
 drivers/net/wwan/iosm/iosm_ipc_pcie.h     | 14 ----
 drivers/net/wwan/iosm/iosm_ipc_pm.c       | 14 ----
 drivers/net/wwan/iosm/iosm_ipc_pm.h       |  7 --
 drivers/net/wwan/iosm/iosm_ipc_protocol.c |  5 --
 drivers/net/wwan/iosm/iosm_ipc_protocol.h |  8 --
 9 files changed, 6 insertions(+), 154 deletions(-)
drivers/net/wwan/iosm/iosm_ipc_imem.c +0 -5
index 4405c8531888..e9e630f52451 100644
@@ -1036,11 +1036,6 @@ void ipc_imem_pm_suspend(struct iosm_imem *ipc_imem)
 	ipc_protocol_suspend(ipc_imem->ipc_protocol);
 }
 
-void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep)
-{
-	ipc_protocol_s2idle_sleep(ipc_imem->ipc_protocol, sleep);
-}
-
 void ipc_imem_pm_resume(struct iosm_imem *ipc_imem)
 {
 	enum ipc_mem_exec_stage stage;
drivers/net/wwan/iosm/iosm_ipc_imem.h +0 -8
index 5664ac507c90..2628c0655271 100644
@@ -389,14 +389,6 @@ struct iosm_imem {
 struct iosm_imem *ipc_imem_init(struct iosm_pcie *pcie, unsigned int device_id,
 				void __iomem *mmio, struct device *dev);
 
-/**
- * ipc_imem_pm_s2idle_sleep - Set PM variables to sleep/active for
- *			      s2idle sleep/active
- * @ipc_imem:	Pointer to imem data-struct
- * @sleep:	Set PM Variable to sleep/active
- */
-void ipc_imem_pm_s2idle_sleep(struct iosm_imem *ipc_imem, bool sleep);
-
 /**
  * ipc_imem_pm_suspend - The HAL shall ask the shared memory layer
  *			 whether D3 is allowed.
drivers/net/wwan/iosm/iosm_ipc_irq.c +1 -2
index 702f50a48151..3b0576a54d5c 100644
@@ -40,8 +40,7 @@ static irqreturn_t ipc_msi_interrupt(int irq, void *dev_id)
 	if (instance >= ipc_pcie->nvec)
 		return IRQ_NONE;
 
-	if (!test_bit(0, &ipc_pcie->suspend))
-		ipc_imem_irq_process(ipc_pcie->imem, instance);
+	ipc_imem_irq_process(ipc_pcie->imem, instance);
 
 	return IRQ_HANDLED;
 }
drivers/net/wwan/iosm/iosm_ipc_pcie.c +5 -91

138 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_pcie.h +0 -14
index 844cf1fed994..ed67dcbddb14 100644
@@ -31,16 +31,6 @@
 /* Total number of Maximum IPC IRQ vectors used for IPC */
 #define IPC_IRQ_VECTORS IPC_MSI_VECTORS
 
-/**
- * enum ipc_pcie_sleep_state - Enum type to different sleep state transitions
- * @IPC_PCIE_D0L12:	Put the sleep state in D0L12
- * @IPC_PCIE_D3L2:	Put the sleep state in D3L2
- */
-enum ipc_pcie_sleep_state {
-	IPC_PCIE_D0L12,
-	IPC_PCIE_D3L2,
-};
-
 /**
  * struct iosm_pcie - IPC_PCIE struct.
  * @pci:			Address of the device description
@@ -58,8 +48,6 @@ enum ipc_pcie_sleep_state {
  * @doorbell_reg_offset:	doorbell_reg_offset
  * @doorbell_write:		doorbell write register
  * @doorbell_capture:		doorbell capture resgister
- * @suspend:			S2IDLE sleep/active
- * @d3l2_support:		Read WWAN RTD3 BIOS setting for D3L2 support
  */
 struct iosm_pcie {
 	struct pci_dev *pci;
@@ -73,8 +61,6 @@ struct iosm_pcie {
 	u32 doorbell_reg_offset;
 	u32 doorbell_write;
 	u32 doorbell_capture;
-	unsigned long suspend;
-	enum ipc_pcie_sleep_state d3l2_support;
 };
 
 /**
drivers/net/wwan/iosm/iosm_ipc_pm.c +0 -14
index c76cb9663039..1d7538131440 100644
@@ -238,20 +238,6 @@ bool ipc_pm_prepare_host_active(struct iosm_pm *ipc_pm)
 	return true;
 }
 
-void ipc_pm_set_s2idle_sleep(struct iosm_pm *ipc_pm, bool sleep)
-{
-	if (sleep) {
-		ipc_pm->ap_state = IPC_MEM_DEV_PM_SLEEP;
-		ipc_pm->cp_state = IPC_MEM_DEV_PM_SLEEP;
-		ipc_pm->device_sleep_notification = IPC_MEM_DEV_PM_SLEEP;
-	} else {
-		ipc_pm->ap_state = IPC_MEM_DEV_PM_ACTIVE;
-		ipc_pm->cp_state = IPC_MEM_DEV_PM_ACTIVE;
-		ipc_pm->device_sleep_notification = IPC_MEM_DEV_PM_ACTIVE;
-		ipc_pm->pm_cond.link = IPC_PM_ACTIVE;
-	}
-}
-
 bool ipc_pm_dev_slp_notification(struct iosm_pm *ipc_pm, u32 cp_pm_req)
 {
 	if (cp_pm_req == ipc_pm->device_sleep_notification)
drivers/net/wwan/iosm/iosm_ipc_pm.h +0 -7
index 5f14d7932af9..e43a65686366 100644
@@ -146,13 +146,6 @@ void ipc_pm_deinit(struct iosm_protocol *ipc_protocol);
 bool ipc_pm_dev_slp_notification(struct iosm_pm *ipc_pm,
 				 u32 sleep_notification);
 
-/**
- * ipc_pm_set_s2idle_sleep - Set PM variables to sleep/active
- * @ipc_pm:	Pointer to power management component
- * @sleep:	true to enter sleep/false to exit sleep
- */
-void ipc_pm_set_s2idle_sleep(struct iosm_pm *ipc_pm, bool sleep);
-
 /**
  * ipc_pm_prepare_host_sleep - Prepare the PM for sleep by entering
  *			       IPC_MEM_HOST_PM_SLEEP_WAIT_D3 state.
drivers/net/wwan/iosm/iosm_ipc_protocol.c +0 -5
index e120e1e0ba1d..3c3c9b52eaf1 100644
@@ -169,11 +169,6 @@ static int ipc_protocol_tq_wakeup_dev_slp(struct iosm_imem *ipc_imem, int arg,
 	return 0;
 }
 
-void ipc_protocol_s2idle_sleep(struct iosm_protocol *ipc_protocol, bool sleep)
-{
-	ipc_pm_set_s2idle_sleep(&ipc_protocol->pm, sleep);
-}
-
 bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol)
 {
 	if (!ipc_pm_prepare_host_sleep(&ipc_protocol->pm))
drivers/net/wwan/iosm/iosm_ipc_protocol.h +0 -8
index 289397c4ea6c..12c4aa6e3110 100644
@@ -174,14 +174,6 @@ int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol,
  */
 bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol);
 
-/**
- * ipc_protocol_s2idle_sleep - Call PM function to set PM variables in s2idle
- *			       sleep/active case
- * @ipc_protocol:	Pointer to ipc_protocol instance
- * @sleep:		True for sleep/False for active
- */
-void ipc_protocol_s2idle_sleep(struct iosm_protocol *ipc_protocol, bool sleep);
-
 /**
  * ipc_protocol_resume - Signal to CP that host wants to resume operation.
  * @ipc_protocol:	Pointer to ipc_protocol instance
Signature · 1 line
2.56.0