The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=a24932dcec45ca68fa5ca2f49bbf0df539cfd710

commit a24932dcec45ca68fa5ca2f49bbf0df539cfd710
Author:     Alexey Sukhoguzov <[email protected]>
AuthorDate: 2024-10-30 11:03:30 +0000
Commit:     Warner Losh <[email protected]>
CommitDate: 2026-01-09 20:32:49 +0000

    nvme: Support Autonomous Power State Transition (APST)
    
    APST is an optional NVMe power-saving feature that allows devices
    to autonomously enter higher non-operational power states after a
    certain amount of idle time, reducing the controller's overall power
    consumption.
    
    Signed-off-by: Alexey Sukhoguzov <[email protected]>
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1444
---
 share/man/man4/nvme.4     |  9 +++++++++
 sys/dev/nvme/nvme_ctrlr.c | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/share/man/man4/nvme.4 b/share/man/man4/nvme.4
index dcd2ec86f5fa..d24ffc07ef9e 100644
--- a/share/man/man4/nvme.4
+++ b/share/man/man4/nvme.4
@@ -128,6 +128,15 @@ hw.nvme.hmb_max
 .Pp
 The default value is 5% of physical memory size per device.
 .Pp
+To enable Autonomous Power State Transition (APST), set the following
+tunable value in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+hw.nvme.apst_enable=1
+.Ed
+.Pp
+The default vendor-provided settings, if any, will be applied.
+.Pp
 The
 .Xr nvd 4
 driver is used to provide a disk driver to the system by default.
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index 7e1a3f02f326..2c13dac96342 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -781,6 +781,41 @@ nvme_ctrlr_configure_aer(struct nvme_controller *ctrlr)
        }
 }
 
+static void
+nvme_ctrlr_configure_apst(struct nvme_controller *ctrlr)
+{
+       struct nvme_completion_poll_status status;
+       uint64_t *data;
+       int data_size;
+       bool enable, error = true;
+
+       if (TUNABLE_BOOL_FETCH("hw.nvme.apst_enable", &enable) == 0 ||
+           ctrlr->cdata.apsta == 0)
+               return;
+
+       data_size = 32 * sizeof(*data);
+       data = malloc(data_size, M_NVME, M_WAITOK | M_ZERO);
+
+       status.done = 0;
+       nvme_ctrlr_cmd_get_feature(ctrlr,
+           NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION, 0,
+           data, data_size, nvme_completion_poll_cb, &status);
+       nvme_completion_poll(&status);
+       if (nvme_completion_is_error(&status.cpl))
+               goto out;
+
+       status.done = 0;
+       nvme_ctrlr_cmd_set_feature(ctrlr,
+           NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION, enable, 0, 0,
+           0, 0, data, data_size, nvme_completion_poll_cb, &status);
+       nvme_completion_poll(&status);
+       error = nvme_completion_is_error(&status.cpl);
+out:
+       if (error && bootverbose)
+               nvme_printf(ctrlr, "failed to configure APST\n");
+       free(data, M_NVME);
+}
+
 static void
 nvme_ctrlr_configure_int_coalescing(struct nvme_controller *ctrlr)
 {
@@ -1047,6 +1082,7 @@ nvme_ctrlr_start(void *ctrlr_arg, bool resetting)
        }
 
        nvme_ctrlr_configure_aer(ctrlr);
+       nvme_ctrlr_configure_apst(ctrlr);
        nvme_ctrlr_configure_int_coalescing(ctrlr);
 
        for (i = 0; i < ctrlr->num_io_queues; i++)

Reply via email to