From 6c0ffd42d964e71c003e35786dd2ab0225c02693 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Sun, 8 Nov 2026 18:59:51 -0500 Subject: [PATCH 1/2] phy: apple: atc: park the PIPE at the wake, not before a sleep in place After a sleep that keeps the USB host's always-on side, the wake holds the power control's PHY lock (pwrctl +0x18, acknowledged in +0x1c) around the common block's USB3 setup. It was never acknowledged ("PHY lock request not acknowledged: 0x0"): the entry had parked the PIPE on the dummy backend, and on the J700 the lock is only acknowledged with the PIPE on the USB3 PHY (measured). macOS leaves the PIPE on the USB3 PHY through its sleep (measured). The park at the entry wasn't acknowledged either, as the controller is halted by then, and went ahead unlocked on every sleep. Leave the PIPE where it is for the hibernation, and park it at the wake instead, under the PHY lock and with the controller's core still in reset, before the common block is set up again. That's the state the USB3 routing after the wake starts from, as after a wake that lost the always-on side. Signed-off-by: Diljit Singh --- drivers/phy/apple/atc.c | 42 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 3f5fe45fb2124..329178d06f850 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -6643,10 +6643,11 @@ static int atcphy_probe(struct platform_device *pdev) * controller is brought to D0, and xHCI restores its own state. * * USB2 and USB3 qualify, without DisplayPort, whose link the common block's power-down - * would end. With USB3 the halted controller's PIPE is parked on the dummy backend just - * before the hibernation, as macOS locks and parks it when its host goes to Sleep - * (setUSB3Mode, static), and the lanes are left as they are: the commit takes them down. - * At the wake the lanes come back in USB3 and the PIPE is routed to them when the controller's + * would end. With USB3 the PIPE stays routed to the USB3 PHY, as macOS leaves it (measured): + * the halted controller doesn't acknowledge a PIPE lock, and the power control acknowledges + * its PHY lock at the wake only with the PIPE on the PHY. The lanes are left as they are: the + * commit takes them down. At the wake the common block is set up again under that lock, with + * the PIPE parked, and the PIPE is routed to the lanes when the controller's * core is set up, before xHCI starts, with no Type-C mode change and no SuperSpeed port power * cycle. macOS's raise from Sleep to its saved USB3 mode is also just a handshake and the USB3 * PHY's power level (static, setUSB3Mode). macOS also stops its PHY's fabric traffic before @@ -6680,26 +6681,6 @@ static bool atcphy_can_sleep_in_place(const struct apple_atcphy *atcphy) !atcphy->dp_owned_pmas && !atcphy->aux_power_requested && !atcphy->tunnel_users; } -/* - * The halted controller's PIPE goes to the dummy backend for the hibernation. A lock it - * doesn't acknowledge is only logged, as macOS's sleep only logs it too; the PIPE is then - * parked unlocked, as for a stopped controller. - */ -static int atcphy_sleep_park_pipe(struct apple_atcphy *atcphy) -{ - bool dirty = atcphy->mode_dirty; - int ret; - - ret = atcphy_park_pipehandler(atcphy, false); - if (!ret) - return 0; - - dev_warn(atcphy->dev, "PIPE lock not acknowledged for the sleep (%d): parking unlocked\n", - ret); - atcphy->mode_dirty = dirty; - return atcphy_park_pipehandler(atcphy, true); -} - static void atcphy_usb2_sleep_enter(struct apple_atcphy *atcphy) { set32(atcphy->regs.usb2phy + USB2PHY_MISCTUNE, USB2PHY_MISCTUNE_REFCLK_GATE_OFF); @@ -6895,13 +6876,17 @@ static int atcphy_sleep_power_down(struct apple_atcphy *atcphy) * USB3, without the controller's reset or a USB2 PHY power cycle: atcphy_configure() powers * the USB2 PHY on over the running one, which rewrites only what it holds, so the hub's link * stays. The host role goes in again as at probe, for a USB2 PHY that lost its registers - * too. The PIPE stays parked until the controller's core is set up and routes it. + * too. The PIPE is parked first, unlocked as the controller's core is in reset, and stays + * parked until the core is set up and routes it. */ static int atcphy_common_restore(struct apple_atcphy *atcphy) { enum atcphy_mode mode = atcphy->mode; int ret; + ret = atcphy_park_pipehandler(atcphy, true); + if (ret) + dev_warn(atcphy->dev, "PIPE not parked after the sleep: %d\n", ret); atcphy_forget_common_state(atcphy); ret = atcphy_power_off(atcphy); if (ret) @@ -6978,13 +6963,6 @@ static int atcphy_suspend_noirq(struct device *dev) atcphy->sleep_ret = -EBUSY; return -EBUSY; } - ret = atcphy_sleep_park_pipe(atcphy); - if (ret) { - dev_err(dev, "PIPE not parked for the sleep: %d, refusing it\n", ret); - atcphy->sleep_ret = -EBUSY; - return -EBUSY; - } - ret = atcphy_controller_hibernate(atcphy); if (ret) return ret; From 88cb0d36d534f243e7b93a4250c0b566de24de9d Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Sun, 8 Nov 2026 18:59:51 -0500 Subject: [PATCH 2/2] EDAC: apple_soc: read and acknowledge the T8140 NI error status The T8140 data is interrupt-only, so a latched fabric NI error keeps its line asserted. After a sleep that keeps DRAM up, SoC NI 1 reports a link error on its PCIe port (0x80 in +0x1b58), and the line fires under the backoff until it's masked for good. Map the six NI apertures, from the ADT's niN-metadata, and on an NI interrupt read its status words, from macOS's decoder tables. Log each word that's set and acknowledge it by writing the bits back, as on T6041. A line whose status cleared stays unmasked; anything else goes through the backoff as before. On the J700 the write-back clears the word and the line stays quiet. Signed-off-by: Diljit Singh --- drivers/edac/apple_soc_edac.c | 103 +++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 3 deletions(-) diff --git a/drivers/edac/apple_soc_edac.c b/drivers/edac/apple_soc_edac.c index 1626a19dcd8f0..862e06b3cf78c 100644 --- a/drivers/edac/apple_soc_edac.c +++ b/drivers/edac/apple_soc_edac.c @@ -5,6 +5,7 @@ * Copyright The Aurora Silicon Contributors */ +#include #include #include #include @@ -36,9 +37,23 @@ struct apple_soc_edac_range { const char *name; }; +/* + * A fabric NI whose error status sits in its aperture: a block of status words, + * one per error type, whose set bits name the port. They're acknowledged by + * writing the set bits back. + */ +struct apple_soc_edac_ni { + u8 index; /* interrupt index */ + u8 reg; /* reg index of the NI's aperture */ + u16 status; /* offset of the first status word */ + u32 words; /* bit n: a status word at status + 4 * n */ +}; + struct apple_soc_edac_hw { const struct apple_soc_edac_range *ranges; size_t nranges; + const struct apple_soc_edac_ni *ni; + size_t nni; unsigned int num_irqs; unsigned int num_status_regs; bool event_log; @@ -51,6 +66,8 @@ struct apple_soc_edac_irq { const char *source; unsigned int index; int irq; + const struct apple_soc_edac_ni *ni; + void __iomem *ni_base; unsigned int retries; unsigned int backoff_ms; unsigned long armed_jiffies; @@ -98,6 +115,16 @@ static const struct apple_soc_edac_range t8140_error_ranges[] = { { 25, 1, "pio" }, }; +/* From the ADT's niN-metadata and macOS's NI decoder tables */ +static const struct apple_soc_edac_ni t8140_ni[] = { + { 18, 9, 0x1900, 0x1ffd7ff }, /* SoC NI 0 */ + { 19, 10, 0x1b00, 0x1ffd7ff }, /* SoC NI 1 */ + { 20, 11, 0x1500, 0x1ffd7ff }, /* SoC NI 2 */ + { 21, 12, 0x2500, 0x1ffd7ff }, /* MCC NI */ + { 22, 13, 0x2100, 0x7fefff }, /* AFC MCC NI */ + { 23, 14, 0x1d00, 0x3ff7ff }, /* GFX NI */ +}; + static const struct apple_soc_edac_hw t6041_error_hw = { .ranges = t6041_error_ranges, .nranges = ARRAY_SIZE(t6041_error_ranges), @@ -108,6 +135,8 @@ static const struct apple_soc_edac_hw t6041_error_hw = { static const struct apple_soc_edac_hw t8140_error_hw = { .ranges = t8140_error_ranges, .nranges = ARRAY_SIZE(t8140_error_ranges), + .ni = t8140_ni, + .nni = ARRAY_SIZE(t8140_ni), .num_irqs = 26, }; @@ -164,6 +193,38 @@ static bool apple_soc_edac_t6041_status(struct apple_soc_edac_irq *irq_data, return false; } +/* + * Log and acknowledge an NI's set status words. Returns whether any was set; + * @cleared says whether all of them read back clear. + */ +static bool apple_soc_edac_ni_status(struct apple_soc_edac_irq *irq_data, + bool *cleared) +{ + const struct apple_soc_edac_ni *ni = irq_data->ni; + unsigned long words = ni->words; + unsigned int bit, offset; + bool found = false; + u32 status, left; + + *cleared = true; + for_each_set_bit(bit, &words, 32) { + offset = ni->status + 4 * bit; + status = readl(irq_data->ni_base + offset); + if (!status) + continue; + writel(status, irq_data->ni_base + offset); + left = readl(irq_data->ni_base + offset); + dev_err_ratelimited(irq_data->edac->dev, + "%s: status %#x at %#x, %#x after the acknowledge\n", + irq_data->source, status, offset, left); + found = true; + if (left) + *cleared = false; + } + + return found; +} + static void apple_soc_edac_rearm(struct work_struct *work) { struct apple_soc_edac_irq *irq_data = @@ -194,12 +255,27 @@ static irqreturn_t apple_soc_edac_irq_thread(int irq, void *data) return IRQ_HANDLED; } + snprintf(msg, sizeof(msg), "%s source %u", irq_data->source, + irq_data->index); + if (irq_data->ni) { + bool cleared; + + if (apple_soc_edac_ni_status(irq_data, &cleared)) { + edac_device_handle_ue(edac->dci, 0, 0, msg); + dev_err_ratelimited(edac->dev, "hardware error: %s (IRQ %d)\n", + msg, irq); + if (cleared) + return IRQ_HANDLED; + } else { + dev_err_ratelimited(edac->dev, "%s asserted with no status set\n", + msg); + } + } + /* No status was pending, or this source has no clear contract. */ disable_irq_nosync(irq); - snprintf(msg, sizeof(msg), "%s source %u", irq_data->source, - irq_data->index); - if (!edac->hw->num_status_regs || irq_data->index < 45) { + if (!irq_data->ni && (!edac->hw->num_status_regs || irq_data->index < 45)) { edac_device_handle_ue(edac->dci, 0, 0, msg); dev_err_ratelimited(edac->dev, "hardware error: %s (IRQ %d)\n", msg, irq); @@ -230,6 +306,24 @@ static irqreturn_t apple_soc_edac_irq_thread(int irq, void *data) return IRQ_HANDLED; } +static int apple_soc_edac_map_ni(struct platform_device *pdev, + struct apple_soc_edac_irq *irq_data) +{ + const struct apple_soc_edac_hw *hw = irq_data->edac->hw; + size_t i; + + for (i = 0; i < hw->nni; i++) { + if (hw->ni[i].index != irq_data->index) + continue; + irq_data->ni_base = devm_platform_ioremap_resource(pdev, hw->ni[i].reg); + if (IS_ERR(irq_data->ni_base)) + return PTR_ERR(irq_data->ni_base); + irq_data->ni = &hw->ni[i]; + } + + return 0; +} + static int apple_soc_edac_probe(struct platform_device *pdev) { const struct apple_soc_edac_hw *hw; @@ -306,6 +400,9 @@ static int apple_soc_edac_probe(struct platform_device *pdev) irq_data->irq = irq; irq_data->backoff_ms = APPLE_SOC_EDAC_BACKOFF_MS; irq_data->armed_jiffies = jiffies; + ret = apple_soc_edac_map_ni(pdev, irq_data); + if (ret) + goto err_del_device; INIT_DELAYED_WORK(&irq_data->rearm, apple_soc_edac_rearm); ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,