Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ static bool nvme_own_rtkit(void)
(nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart, false)) != NULL;
}

/*
* T6040/T6041 (M4 Pro/Max): a cold start of ANS after the generic power-off gets no RTKit HELLO
* (ASC CPU running, pmgr domains on), and an RTKit quiesce times out. T8132 (M4): the same cold
* start intermittently leaves the next stage without NVMe after a warm reboot. Keep ANS live
* between stages and adopt it in the next stage, as T6050 does.
*
* Not every post-M4 ANS (nvme_post_m4()) is listed. T8152 stays quiesced: its Linux driver wakes
* ANS with a fresh RTKit handshake and neither adopts a live session nor restarts a stopped one.
* T8140 keeps the power-off path, which works there; live adoption by the next stage is untested.
*/
static bool nvme_post_m4_keeps_live(void)
{
return chip_id == T6040 || chip_id == T6041 || chip_id == T8132;
}

static bool nvme_post_m4_hands_on_live(void)
{
return nvme_ans_storage_gated() || nvme_post_m4_keeps_live();
}

/*
* Post-M4, done with ANS: stop the controller, idle the firmware as macOS does before a sleep,
* keep the SART entries, then power ANS and the PCIe block it runs on off. Every later stage that
Expand Down Expand Up @@ -667,7 +687,7 @@ bool nvme_init(void)
* window), its firmware no longer acknowledged the idle, and ANS didn't start from off.
* T8142 does the same with a session an older stage handed on running.
*/
adopted = earlier && nvme_ans_storage_gated() &&
adopted = earlier && nvme_post_m4_hands_on_live() &&
read32(nvme_base + NVME_BOOT_STATUS) == NVME_BOOT_STATUS_OK &&
!(read32(nvme_base + NVME_CSTS) & NVME_CSTS_CFS);
from_off = !running || (earlier && !adopted);
Expand Down Expand Up @@ -940,6 +960,22 @@ bool nvme_shutdown(void)
goto out_preserve;
}

/*
* T6040/T6041: the firmware acknowledges neither an RTKit power transition (quiesce times out)
* nor a start after power-off (no HELLO), but a session left fully running is adopted by the
* next nvme_init() and reads correctly (J614c, 3/3 cycles). T8132 is handed on the same way
* (J713). Hand it on with the controller enabled and RTKit untouched; only the I/O queue
* registers are cleared. A next stage that asks for a quiesced ANS still gets one.
*/
if (nvme_type == NVME_T8132 && nvme_post_m4_keeps_live() && !nvme_quiesce_for_next) {
write64_lo_hi(nvme_qreg(NVME_IOQ_CMDS), 0);
write64_lo_hi(nvme_qreg(NVME_IOQ_CQES), 0);
nvme_initialized = false;
printf("nvme: handing the live ANS session on: CC=0x%x CSTS=0x%x BOOT_STATUS=0x%x\n",
read32(nvme_base + NVME_CC), read32(nvme_base + NVME_CSTS),
read32(nvme_base + NVME_BOOT_STATUS));
return true;
}
if (nvme_type == NVME_T8132 && !nvme_secure_regs && !nvme_quiesce_for_next) {
write64_lo_hi(nvme_qreg(NVME_IOQ_CMDS), 0);
write64_lo_hi(nvme_qreg(NVME_IOQ_CQES), 0);
Expand Down
7 changes: 5 additions & 2 deletions tests/python/test_nvme_adoption.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ def test_adopted_queue_lifetime(tmp_path):
assert(nvme_initialized);
assert(nvme_shutdown());
assert(!nvme_initialized);
/* Powered off, post-M4 frees its queues too; only Linux's live handoff keeps them. */
assert(queue_frees == (failure == 9 ? 0 : 2));
/*
* Powered off, post-M4 frees its queues too. Linux's live handoff keeps them, and so does
* T8132 (23, 26), which hands its session on live to the next stage.
*/
assert(queue_frees == (failure == 9 || failure == 23 || failure == 26 ? 0 : 2));
assert(resets == (legacy ? 2 : 0));
/* A healthy shutdown still allows reinitialization. */
assert(nvme_init());
Expand Down
Loading