summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorNaveen Nagar2021-10-06 08:53:30 +0200
committerKlaus Jensen2022-03-03 09:28:49 +0100
commit763c05dfb08c5fff86275788de7f11e899167167 (patch)
tree67b2471decddddc6cc35e78383a61a8d7f2102ff /hw
parenthw/nvme: move format parameter parsing (diff)
downloadqemu-763c05dfb08c5fff86275788de7f11e899167167.tar.gz
qemu-763c05dfb08c5fff86275788de7f11e899167167.tar.xz
qemu-763c05dfb08c5fff86275788de7f11e899167167.zip
hw/nvme: add support for the lbafee hbs feature
Add support for up to 64 LBA formats through the LBAFEE field of the Host Behavior Support feature. Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Naveen Nagar <naveen.n1@samsung.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/nvme/ctrl.c34
-rw-r--r--hw/nvme/ns.c15
-rw-r--r--hw/nvme/nvme.h1
3 files changed, 41 insertions, 9 deletions
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index d8701ebf2f..52ab3450b9 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -5165,6 +5165,7 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req)
uint32_t nsid = le32_to_cpu(cmd->nsid);
uint8_t fid = NVME_GETSETFEAT_FID(dw10);
uint8_t save = NVME_SETFEAT_SAVE(dw10);
+ uint16_t status;
int i;
trace_pci_nvme_setfeat(nvme_cid(req), nsid, fid, save, dw11);
@@ -5287,8 +5288,26 @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeRequest *req)
case NVME_TIMESTAMP:
return nvme_set_feature_timestamp(n, req);
case NVME_HOST_BEHAVIOR_SUPPORT:
- return nvme_h2c(n, (uint8_t *)&n->features.hbs,
- sizeof(n->features.hbs), req);
+ status = nvme_h2c(n, (uint8_t *)&n->features.hbs,
+ sizeof(n->features.hbs), req);
+ if (status) {
+ return status;
+ }
+
+ for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
+ ns = nvme_ns(n, i);
+
+ if (!ns) {
+ continue;
+ }
+
+ ns->id_ns.nlbaf = ns->nlbaf - 1;
+ if (!n->features.hbs.lbafee) {
+ ns->id_ns.nlbaf = MIN(ns->id_ns.nlbaf, 15);
+ }
+ }
+
+ return status;
case NVME_COMMAND_SET_PROFILE:
if (dw11 & 0x1ff) {
trace_pci_nvme_err_invalid_iocsci(dw11 & 0x1ff);
@@ -5479,10 +5498,13 @@ static const AIOCBInfo nvme_format_aiocb_info = {
static void nvme_format_set(NvmeNamespace *ns, uint8_t lbaf, uint8_t mset,
uint8_t pi, uint8_t pil)
{
+ uint8_t lbafl = lbaf & 0xf;
+ uint8_t lbafu = lbaf >> 4;
+
trace_pci_nvme_format_set(ns->params.nsid, lbaf, mset, pi, pil);
ns->id_ns.dps = (pil << 3) | pi;
- ns->id_ns.flbas = lbaf | (mset << 4);
+ ns->id_ns.flbas = (lbafu << 5) | (mset << 4) | lbafl;
nvme_ns_init_format(ns);
}
@@ -5596,6 +5618,7 @@ static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)
uint8_t mset = (dw10 >> 4) & 0x1;
uint8_t pi = (dw10 >> 5) & 0x7;
uint8_t pil = (dw10 >> 8) & 0x1;
+ uint8_t lbafu = (dw10 >> 12) & 0x3;
uint16_t status;
iocb = qemu_aio_get(&nvme_format_aiocb_info, NULL, nvme_misc_cb, req);
@@ -5612,6 +5635,10 @@ static uint16_t nvme_format(NvmeCtrl *n, NvmeRequest *req)
iocb->broadcast = (nsid == NVME_NSID_BROADCAST);
iocb->offset = 0;
+ if (n->features.hbs.lbafee) {
+ iocb->lbaf |= lbafu << 4;
+ }
+
if (!iocb->broadcast) {
if (!nvme_nsid_valid(n, nsid)) {
status = NVME_INVALID_NSID | NVME_DNR;
@@ -6587,6 +6614,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
id->cntlid = cpu_to_le16(n->cntlid);
id->oaes = cpu_to_le32(NVME_OAES_NS_ATTR);
+ id->ctratt |= cpu_to_le32(NVME_CTRATT_ELBAS);
id->rab = 6;
diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
index ee673f1a5b..8dfb55130b 100644
--- a/hw/nvme/ns.c
+++ b/hw/nvme/ns.c
@@ -112,10 +112,11 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
[7] = { .ds = 12, .ms = 64 },
};
+ ns->nlbaf = 8;
+
memcpy(&id_ns->lbaf, &lbaf, sizeof(lbaf));
- id_ns->nlbaf = 7;
- for (i = 0; i <= id_ns->nlbaf; i++) {
+ for (i = 0; i < ns->nlbaf; i++) {
NvmeLBAF *lbaf = &id_ns->lbaf[i];
if (lbaf->ds == ds) {
if (lbaf->ms == ms) {
@@ -126,12 +127,14 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
}
/* add non-standard lba format */
- id_ns->nlbaf++;
- id_ns->lbaf[id_ns->nlbaf].ds = ds;
- id_ns->lbaf[id_ns->nlbaf].ms = ms;
- id_ns->flbas |= id_ns->nlbaf;
+ id_ns->lbaf[ns->nlbaf].ds = ds;
+ id_ns->lbaf[ns->nlbaf].ms = ms;
+ ns->nlbaf++;
+
+ id_ns->flbas |= i;
lbaf_found:
+ id_ns->nlbaf = ns->nlbaf - 1;
nvme_ns_init_format(ns);
return 0;
diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h
index 103407038e..e715c3255a 100644
--- a/hw/nvme/nvme.h
+++ b/hw/nvme/nvme.h
@@ -128,6 +128,7 @@ typedef struct NvmeNamespace {
int64_t moff;
NvmeIdNs id_ns;
NvmeLBAF lbaf;
+ unsigned int nlbaf;
size_t lbasz;
const uint32_t *iocs;
uint8_t csi;