From 7b8448d0a54126f983a566b4503af8bd82e2f40e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 16:51:54 +0100 Subject: [PATCH 1/4] TEST ONLY: J813: send the final SMC sleep notice after peer stops The MagSafe/lid failure missed ANS IOP IDLE and then SMC faulted at ANS mailbox +0xc110. The native J813 trace idles ANS before SMC's final notice; the current noirq path reverses that order. Defer the existing notice to platform entry after peer stops and before domain power-down. This is a hypothesis under hardware qualification; j813_smc_late=0 restores the original ordering. Signed-off-by: Thomas Glanzmann --- drivers/mfd/macsmc.c | 25 +++++++++++++++++++++++++ drivers/soc/apple/sleep.c | 33 +++++++++++++++++++++++++++++++-- include/linux/soc/apple/sleep.h | 3 +++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 1a4f9c2da8cfc..433f46ada0736 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -879,6 +879,26 @@ static int apple_smc_sleep_commit(struct apple_smc *smc) return ret; } +/* + * J813 keeps the existing command sequence, but the platform calls it only + * after ANS and the other peers have completed their final idle handshakes. + * IRQs are off, as in the ordinary noirq callback. No timing receipt is used + * by this experimental non-saved-context path. + */ +static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) +{ + struct apple_smc *smc = data; + int ret; + + *sent = *ack = 0; + if (!irqs_disabled() || !smc->sleep_warned || smc->ap_notified) + return -EINVAL; + apple_smc_set_polled(smc, true); + ret = apple_smc_sleep_commit(smc); + apple_smc_set_polled(smc, false); + return ret; +} + static int apple_smc_wake_reason_names(const struct apple_smc *smc, u64 record, char *buf, size_t size) { @@ -1401,6 +1421,8 @@ static int apple_smc_sleep_prepare(struct apple_smc *smc) else apple_smc_sleep_warn(smc); + if (apple_sleep_smc_defer_notice()) + return apple_sleep_smc_register(smc->dev, apple_smc_sleep_after_peers, smc); return 0; } @@ -1514,6 +1536,9 @@ static int apple_smc_sleep_enter(struct apple_smc *smc) apple_smc_outbox_poll(smc, "late sleep warning", SMC_SLEEP_WARN_MS, 0); } + /* Warning and debug-link handling stay in noirq; only the notice moves. */ + if (apple_sleep_smc_defer_notice()) + return 0; return apple_smc_sleep_commit(smc); } diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 4a92376829020..ca104779c4061 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1757,13 +1757,26 @@ const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) } EXPORT_SYMBOL_GPL(apple_sleep_smc_policy); +static bool sleep_j813_smc_late = true; +module_param_named(j813_smc_late, sleep_j813_smc_late, bool, 0444); +MODULE_PARM_DESC(j813_smc_late, + "TEST ONLY: J813 final SMC sleep notice after peer stops"); + +bool apple_sleep_smc_defer_notice(void) +{ + return apple_sleep && READ_ONCE(sleep_j813_smc_late) && + of_machine_is_compatible("apple,j813") && pm_suspend_via_firmware(); +} +EXPORT_SYMBOL_GPL(apple_sleep_smc_defer_notice); + int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { struct apple_sleep *s = apple_sleep; guard(mutex)(&apple_sleep_smc_lock); - if (!s || !s->soc->smc_policy || !pm_suspend_via_firmware()) + if (!s || (!s->soc->smc_policy && !apple_sleep_smc_defer_notice()) || + !pm_suspend_via_firmware()) return -EOPNOTSUPP; if (!late_notice || s->smc.saved_ops || (s->smc.dev && s->smc.dev != dev)) return -EBUSY; @@ -5743,7 +5756,7 @@ static void t8132_wake(struct apple_sleep *s) static int apple_sleep_smc_late_notice(struct apple_sleep *s) { - if (!s->soc->smc_policy) + if (!s->soc->smc_policy && !apple_sleep_smc_defer_notice()) return 0; if (!s->smc.dev || !s->smc.late_notice) return -ENODEV; @@ -5936,6 +5949,10 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->early_context) return apple_sleep_enter_early(s); + /* Refuse while all peer stops are still reversible. */ + if (apple_sleep_smc_defer_notice() && (!s->smc.dev || !s->smc.late_notice)) + return -ENODEV; + sleep_note(s, 0x10); ret = apple_sleep_refuse(s); if (ret) { @@ -6254,6 +6271,18 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->ack_cluster_dcs && (readl(s->cluster_dcs) & CLUSTER_UP_DONE)) writel(readl(s->cluster_dcs), s->cluster_dcs); apple_sleep_coprocs_stop(s, false); + /* + * J813 native trace: ANS idle completes before SMC slpa/AP IDLE. + * In the battery failure SMC faulted at ANS + 0xc110 after ANS's + * idle ACK was missed. Keep its final notice behind the peer stops + * and ahead of the domain power-down in the last mile. + */ + if (apple_sleep_smc_defer_notice()) { + ret = apple_sleep_smc_late_notice(s); + dev_info(s->dev, "TEST: SMC notice after peer stops: %d\n", ret); + if (ret) + panic("J813 SMC notice failed after peer stops: %d", ret); + } /* Done by now unless no SMC driver is bound. */ apple_sleep_usb_down(s); s->deep_once = READ_ONCE(sleep_deep_requested); diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 7174fc48459f3..cec1e88452676 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -38,6 +38,8 @@ struct apple_sleep_smc_saved_ops { #if IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void); +/* J813 experiment: send the final SMC notice after the peer idle handshakes. */ +bool apple_sleep_smc_defer_notice(void); int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data); int apple_sleep_smc_register_saved(struct device *dev, @@ -241,6 +243,7 @@ void apple_sleep_restore_pins(void); int apple_sleep_engine_reset(struct device *dev); #else static inline const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) { return NULL; } +static inline bool apple_sleep_smc_defer_notice(void) { return false; } static inline int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { return -EOPNOTSUPP; } static inline int apple_sleep_smc_register_saved(struct device *dev, From 5e16a7efa1d6f14005352c8c1cc922b0b159abd8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 17:06:56 +0100 Subject: [PATCH 2/4] TEST ONLY: J813: use bounded SMC transport for the late notice The platform enter callback runs with local IRQs disabled. The normal noirq SMC path can wait on scheduler work and jiffies, and the first ordering experiment stalled there. Reserve the existing saved SMC transport in prepare_late and restore it in platform wake. Keep J813's MBSE/AP sequence and delay floors without importing the other SoC's policy. Signed-off-by: Thomas Glanzmann --- drivers/mfd/macsmc.c | 66 +++++++++++++++++++++++++-------------- drivers/soc/apple/sleep.c | 13 ++++---- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 433f46ada0736..b00d98b439ca6 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -650,6 +650,9 @@ static int apple_smc_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t6050-smc"); if (smc->saved_enabled) smc->wake_reasons = apple_smc_j714s_wake_reasons; + /* J813's late notice needs the bounded, IRQ-independent transport too. */ + if (of_machine_is_compatible("apple,j813")) + smc->saved_enabled = true; smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram); if (IS_ERR(smc->sram_base)) return dev_err_probe(dev, PTR_ERR(smc->sram_base), "Failed to map SRAM region"); @@ -879,26 +882,6 @@ static int apple_smc_sleep_commit(struct apple_smc *smc) return ret; } -/* - * J813 keeps the existing command sequence, but the platform calls it only - * after ANS and the other peers have completed their final idle handshakes. - * IRQs are off, as in the ordinary noirq callback. No timing receipt is used - * by this experimental non-saved-context path. - */ -static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) -{ - struct apple_smc *smc = data; - int ret; - - *sent = *ack = 0; - if (!irqs_disabled() || !smc->sleep_warned || smc->ap_notified) - return -EINVAL; - apple_smc_set_polled(smc, true); - ret = apple_smc_sleep_commit(smc); - apple_smc_set_polled(smc, false); - return ret; -} - static int apple_smc_wake_reason_names(const struct apple_smc *smc, u64 record, char *buf, size_t size) { @@ -1150,7 +1133,8 @@ static int apple_smc_sleep_saved_begin(void *data) struct apple_smc *smc = data; int ret; - if (!smc->saved_enabled || !smc->sleep_policy) + if (!smc->saved_enabled || + (!smc->sleep_policy && !apple_sleep_smc_defer_notice())) return -EOPNOTSUPP; if (!mutex_trylock(&smc->mutex)) return -EBUSY; @@ -1356,6 +1340,42 @@ static const struct apple_sleep_smc_saved_ops apple_smc_saved_ops = { .pmvc = apple_smc_sleep_saved_pmvc, }; +/* + * J813 retains its existing MBSE/AP sequence and delay floors. The transport + * is the saved lane: no scheduler, jiffies, IRQ worker or SRAM reuse is needed + * after the peer stops. Unrelated notifications are retained until resume. + */ +static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) +{ + struct apple_smc *smc = data; + int ret; + + lockdep_assert_held(&smc->mutex); + *sent = *ack = 0; + if (!irqs_disabled() || !smc->saved_scope || !smc->sleep_warned || + smc->ap_notified) + return -EINVAL; + + smc->saved_committed = true; + ret = apple_smc_saved_write_u32(smc, SMC_KEY(MBSE), SMC_KEY(slpa)); + if (ret) + goto out; + mdelay(SMC_SLEEP_ARM_MS); + smc->ap_notified = true; + ret = apple_rtkit_m5_saved_ap_power(smc->rtk, false, sent, ack); + if (!ret) + mdelay(SMC_SLEEP_IDLE_MS); +out: + smc->saved_notice_error = ret; + return ret; +} + +static const struct apple_sleep_smc_saved_ops apple_smc_j813_saved_ops = { + .begin = apple_smc_sleep_saved_begin, + .late_notice = apple_smc_sleep_after_peers, + .end = apple_smc_sleep_saved_end, +}; + static int apple_smc_prepare_policy(struct apple_smc *smc) { const struct apple_sleep_smc_policy *p = smc->sleep_policy; @@ -1422,7 +1442,7 @@ static int apple_smc_sleep_prepare(struct apple_smc *smc) apple_smc_sleep_warn(smc); if (apple_sleep_smc_defer_notice()) - return apple_sleep_smc_register(smc->dev, apple_smc_sleep_after_peers, smc); + return apple_sleep_smc_register_saved(smc->dev, &apple_smc_j813_saved_ops, smc); return 0; } @@ -1566,7 +1586,7 @@ static int apple_smc_resume_noirq(struct device *dev) if (smc->saved_enabled && (smc->saved_recovery || smc->saved_pending || smc->saved_fault)) return smc->saved_restore_error ?: smc->saved_fault ?: -EBUSY; - if (smc->saved_enabled && smc->sleep_policy) { + if (smc->saved_enabled && (smc->sleep_policy || smc->saved_wake)) { if (smc->saved_wake) { apple_smc_set_polled(smc, true); apple_smc_sleep_wake(smc); diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index ca104779c4061..39f5801542a43 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1775,8 +1775,7 @@ int apple_sleep_smc_register(struct device *dev, struct apple_sleep *s = apple_sleep; guard(mutex)(&apple_sleep_smc_lock); - if (!s || (!s->soc->smc_policy && !apple_sleep_smc_defer_notice()) || - !pm_suspend_via_firmware()) + if (!s || !s->soc->smc_policy || !pm_suspend_via_firmware()) return -EOPNOTSUPP; if (!late_notice || s->smc.saved_ops || (s->smc.dev && s->smc.dev != dev)) return -EBUSY; @@ -1794,8 +1793,8 @@ int apple_sleep_smc_register_saved(struct device *dev, struct apple_sleep *s = apple_sleep; guard(mutex)(&apple_sleep_smc_lock); - if (!s || !s->soc->early_context || !s->soc->smc_policy || - !pm_suspend_via_firmware()) + if (!s || ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) || !pm_suspend_via_firmware()) return -EOPNOTSUPP; if (!ops || !ops->begin || !ops->late_notice || !ops->end || s->smc.dev) return -EBUSY; @@ -5760,7 +5759,8 @@ static int apple_sleep_smc_late_notice(struct apple_sleep *s) return 0; if (!s->smc.dev || !s->smc.late_notice) return -ENODEV; - if (s->soc->early_context && (!s->smc.saved_ops || !s->smc.held)) + if ((s->soc->early_context || apple_sleep_smc_defer_notice()) && + (!s->smc.saved_ops || !s->smc.held)) return -EBUSY; return s->smc.late_notice(s->smc.data, &s->smc_idle_sent, &s->smc_idle_ack); } @@ -6558,7 +6558,8 @@ static int apple_sleep_smc_scope_begin(void) struct apple_sleep *s = apple_sleep; int ret = 0; - if (!s->soc->early_context || !s->soc->smc_policy) + if ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) return 0; mutex_lock(&apple_sleep_smc_lock); if (!s->smc.saved_ops || !s->smc.dev) { From 1024bb269b4ce9ed796391996a403c890531c754 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 17:10:14 +0100 Subject: [PATCH 3/4] TEST ONLY: J813: acquire the SMC scope on the regular suspend path Only the early-context suspend ops had prepare_late and finish callbacks. Wire the SMC scope callbacks into the regular ops too, and require held ownership before entering the irreversible region. The scope begin is a no-op when the experimental late notice is disabled. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/sleep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 39f5801542a43..5a16e6f7accf2 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -5950,8 +5950,12 @@ static int apple_sleep_enter(suspend_state_t state) return apple_sleep_enter_early(s); /* Refuse while all peer stops are still reversible. */ - if (apple_sleep_smc_defer_notice() && (!s->smc.dev || !s->smc.late_notice)) - return -ENODEV; + if (apple_sleep_smc_defer_notice()) { + if (!s->smc.dev || !s->smc.late_notice) + return -ENODEV; + if (!s->smc.saved_ops || !s->smc.held) + return -EBUSY; + } sleep_note(s, 0x10); ret = apple_sleep_refuse(s); @@ -6779,6 +6783,8 @@ static const struct platform_suspend_ops apple_sleep_ops = { .valid = apple_sleep_valid, .begin = apple_sleep_begin, .prepare = apple_sleep_prepare, + .prepare_late = apple_sleep_smc_scope_begin, + .finish = apple_sleep_smc_scope_end, .enter = apple_sleep_enter, .wake = apple_sleep_report, .end = apple_sleep_end, From 651007bc81388c19544780d3930f6926294f0b73 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Mon, 16 Nov 2026 17:21:28 +0100 Subject: [PATCH 4/4] TEST ONLY: J813: preserve the existing SMC wake-notice timing The saved transport restores AP power in platform wake, before device noirq resume. Using that on J813 moved AP ON ahead of the radio's DMA restoration. Two fresh boots returned from physical sleep with healthy SMC/ANS/DCP but Alpha in firmware stage 3. Release the bounded transport at platform wake and leave ap_notified set for J813's existing resume_noirq notice. The other SoC's saved policy keeps its original release behavior. Signed-off-by: Thomas Glanzmann --- drivers/mfd/macsmc.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index b00d98b439ca6..32823667e5a6f 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -1186,7 +1186,7 @@ static int apple_smc_sleep_saved_begin(void *data) return ret; } -static int apple_smc_sleep_saved_end(void *data) +static int apple_smc_sleep_saved_release(void *data, bool wake_ap) { struct apple_smc *smc = data; int ret, restore = 0; @@ -1199,7 +1199,7 @@ static int apple_smc_sleep_saved_end(void *data) /* Bounded reconciliation; never release pending ownership on timeout. */ if (!ret && smc->saved_pending) ret = apple_smc_saved_wait_reply(smc); - if (smc->ap_notified) { + if (wake_ap && smc->ap_notified) { restore = apple_rtkit_m5_saved_ap_power(smc->rtk, true, NULL, NULL); if (!restore) { smc->ap_notified = false; @@ -1221,6 +1221,23 @@ static int apple_smc_sleep_saved_end(void *data) return ret; } +static int apple_smc_sleep_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, true); +} + +/* + * J813's ordinary wake notice belongs in macsmc's resume_noirq, after the + * device dependencies have resumed. Platform wake precedes every noirq + * device callback; an AP ON there can wake the radio before its DMA path. + * Release the bounded transport here, retaining ap_notified for the usual + * noirq wake callback. A refused entry never posted AP IDLE. + */ +static int apple_smc_j813_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, false); +} + /* Readiness is a returning operation BEFORE SEP/ANS/PMP stop. A drained * notification remains retained and can cancel only on this side of the boundary. */ @@ -1373,7 +1390,7 @@ static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) static const struct apple_sleep_smc_saved_ops apple_smc_j813_saved_ops = { .begin = apple_smc_sleep_saved_begin, .late_notice = apple_smc_sleep_after_peers, - .end = apple_smc_sleep_saved_end, + .end = apple_smc_j813_saved_end, }; static int apple_smc_prepare_policy(struct apple_smc *smc)