NVMe has a limit on how many sectors it can handle at most within a single
request. Remember that number, so that in a follow-up patch, we can verify
that we don't exceed it.
Signed-off-by: Alexander Graf <graf@amazon.com>
---
v1 -> v2:
- fix dprintf
v2 -> v3:
- Adjust the maximum request size to sector units. The hardware field
describes it in pages.
---
src/hw/nvme-int.h | 8 +++++++-
src/hw/nvme.c | 13 +++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/hw/nvme-int.h b/src/hw/nvme-int.h
index 9f95dd8..674008a 100644
--- a/src/hw/nvme-int.h
+++ b/src/hw/nvme-int.h
@@ -117,6 +117,7 @@ struct nvme_namespace {
u32 block_size;
u32 metadata_size;
+ u32 max_req_size;
/* Page aligned buffer of size NVME_PAGE_SIZE. */
char *dma_buffer;
@@ -131,7 +132,12 @@ struct nvme_identify_ctrl {
char mn[40];
char fr[8];
- char _boring[516 - 72];
+ u8 rab;
+ u8 ieee[3];
+ u8 cmic;
+ u8 mdts;
+
+ char _boring[516 - 78];
u32 nn; /* number of namespaces */
};
diff --git a/src/hw/nvme.c b/src/hw/nvme.c
index 6a01204..5bc2586 100644
--- a/src/hw/nvme.c
+++ b/src/hw/nvme.c
@@ -238,7 +238,8 @@ nvme_admin_identify_ns(struct nvme_ctrl *ctrl, u32 ns_id)
}
static void
-nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id)
+nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id,
+ u8 mdts)
{
ns->ctrl = ctrl;
ns->ns_id = ns_id;
@@ -281,6 +282,14 @@ nvme_probe_ns(struct nvme_ctrl *ctrl, struct nvme_namespace *ns, u32 ns_id)
ns->drive.blksize = ns->block_size;
ns->drive.sectors = ns->lba_count;
+ if (mdts) {
+ ns->max_req_size = ((1U << mdts) * NVME_PAGE_SIZE) / ns->block_size;
+ dprintf(3, "NVME NS %u max request size: %d sectors\n",
+ ns_id, ns->max_req_size);
+ } else {
+ ns->max_req_size = -1U;
+ }
+
ns->dma_buffer = zalloc_page_aligned(&ZoneHigh, NVME_PAGE_SIZE);
char *desc = znprintf(MAXDESCSIZE, "NVMe NS %u: %llu MiB (%llu %u-byte "
@@ -567,7 +576,7 @@ nvme_controller_enable(struct nvme_ctrl *ctrl)
/* Populate namespace IDs */
int ns_idx;
for (ns_idx = 0; ns_idx < ctrl->ns_count; ns_idx++) {
- nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1);
+ nvme_probe_ns(ctrl, &ctrl->ns[ns_idx], ns_idx + 1, identify->mdts);
}
dprintf(3, "NVMe initialization complete!\n");
--
2.16.4
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org