git: f262bdcf24f1 - main - nvme: Restore the host memory buffer size calculation

From: Kenneth D. Merry <ken_at_FreeBSD.org>
Date: Mon, 09 Nov 2026 19:14:10 UTC
The branch main has been updated by ken:

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

commit f262bdcf24f1f946edcd01f5eb5dfa2910da9e7b
Author:     Kenneth D. Merry <ken@FreeBSD.org>
AuthorDate: 2026-11-09 18:46:59 +0000
Commit:     Kenneth D. Merry <ken@FreeBSD.org>
CommitDate: 2026-11-09 18:59:13 +0000

    nvme: Restore the host memory buffer size calculation
    
    When the nvme_ctrlr_cmd_set_feature() call in
    nvme_ctrlr_hmb_enable() was rewritten for the widened Set Features
    API, the HSIZE calculation reverted to dividing by a hard coded
    4096 instead of the controller page size, undoing commit
    3740a8db13ba.  The Host Memory Buffer Size field is in units of
    the current memory page size (CC.MPS), so the wrong size would be
    programmed on controllers configured with a page size other than
    4KB.
    
    Reported by:    llm-postcr
    Fixes:          7a9e4375316b
    MFC after:      1 week
    Sponsored by:   Spectra Logic
    Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
---
 sys/dev/nvme/nvme_ctrlr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index 6eff9af77aac..11c09efc684f 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -1180,7 +1180,7 @@ nvme_ctrlr_hmb_enable(struct nvme_controller *ctrlr, bool enable, bool memret)
 		cdw11 |= 2;
 	status.done = 0;
 	nvme_ctrlr_cmd_set_feature(ctrlr, 0, 0, NVME_FEAT_HOST_MEMORY_BUFFER,
-	    cdw11, ctrlr->hmb_nchunks * ctrlr->hmb_chunk / 4096,
+	    cdw11, ctrlr->hmb_nchunks * ctrlr->hmb_chunk / ctrlr->page_size,
 	    ctrlr->hmb_desc_paddr, ctrlr->hmb_desc_paddr >> 32,
 	    ctrlr->hmb_nchunks, NULL, 0, nvme_completion_poll_cb, &status);
 	nvme_completion_poll(&status);