]> xenbits.xensource.com Git - osstest/seabios.git/commitdiff
nvme: Record maximum allowed request size
authorAlexander Graf <graf@amazon.com>
Wed, 30 Sep 2020 21:10:53 +0000 (23:10 +0200)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 28 Oct 2020 19:18:29 +0000 (15:18 -0400)
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>
src/hw/nvme-int.h
src/hw/nvme.c

index 9f95dd802eff5a75839003b7841b22e534cbca7d..674008a55861d0971445e9069a3e1948f8290c9f 100644 (file)
@@ -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 */
 };
index 6a0120473aa6796e4a0309a62348c4efd647d3e1..5bc2586235ac15d9910b2d03547e343f3d95e4bf 100644 (file)
@@ -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");