nvme: Record maximum allowed request size

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>
This commit is contained in:
Alexander Graf 2020-09-30 23:10:53 +02:00 committed by Kevin O'Connor
parent 58a44be024
commit b68f313c91
2 changed files with 18 additions and 3 deletions

View 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 */
};

View 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");