Skip to contentSkip to conversation

hw/block/nvme: add administrative controller support

PATCH New Klaus Jensen 1 participant 4 messages Mar 11, 2021

lore
Share & tools
lore
#0 lore raw

cover hw/block/nvme: add administrative controller support

From: Klaus Jensen <[email protected]>

This series allows the controller to behave as an Administrative Controller. This is useful when emulating a subsystem.

Since some commands are prohibited for an Administrative Controller, this series includes patches that make the CSE log page dynamic and allows supported features and commands to be fine-tuned with the new 'oncs' and 'oacs' parameters. By default, the device supports as much as possible.

Gollu Appalanaidu (2):
hw/block/nvme: add oncs device parameter
hw/block/nvme: add oacs device parameter

Padmakar Kalghatgi (1):
hw/block/nvme: add administrative controller type

 hw/block/nvme.h        |  11 +++
 include/block/nvme.h   |   8 ++
 hw/block/nvme-subsys.c |   6 +-
 hw/block/nvme.c        | 193 +++++++++++++++++++++++++++++------------
 4 files changed, 162 insertions(+), 56 deletions(-)
Signature · 1 line
2.30.1
#1 lore raw

PATCH 1/3 hw/block/nvme: add oncs device parameter

From: Gollu Appalanaidu <[email protected]>

Add the 'oncs' nvme device parameter to allow optional features to be enabled/disabled explicitly. Since most of these are optional commands, make the CSE log pages dynamic to account for the value of ONCS.

---
 hw/block/nvme.h |   7 ++++
 hw/block/nvme.c | 101 ++++++++++++++++++++++++++++++++----------------
 2 files changed, 74 insertions(+), 34 deletions(-)
hw/block/nvme.h +7 -0
index 4955d649c7d4..65c80cfaef62 100644
@@ -9,6 +9,7 @@
 
 #define NVME_DEFAULT_ZONE_SIZE   (128 * MiB)
 #define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB)
+#define NVME_MAX_COMMANDS 0x100
 
 /*
  * Subsystem namespace list for allocated namespaces should be larger than
@@ -28,6 +29,7 @@ typedef struct NvmeParams {
     bool     use_intel_id;
     uint8_t  zasl;
     bool     legacy_cmb;
+    uint16_t oncs;
 } NvmeParams;
 
 typedef struct NvmeAsyncEvent {
@@ -210,6 +212,11 @@ typedef struct NvmeCtrl {
     NvmeCQueue      admin_cq;
     NvmeIdCtrl      id_ctrl;
     NvmeFeatureVal  features;
+
+    struct {
+        uint32_t nvm[NVME_MAX_COMMANDS];
+        uint32_t zoned[NVME_MAX_COMMANDS];
+    } iocs;
 } NvmeCtrl;
 
 static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)
hw/block/nvme.c +67 -34

192 lines not on this page · raw message

Signature · 1 line
2.30.1
#2 lore raw

PATCH 2/3 hw/block/nvme: add oacs device parameter

In reply to Klaus Jensen

From: Gollu Appalanaidu <[email protected]>

Add the 'oacs' nvme device parameter to allow optional features to be enabled/disabled explicitly. Since most of these are optional commands, make the CSE log pages dynamic to account for the value of OACS once the optional commands supported added to device.

---
 hw/block/nvme.h |  3 +++
 hw/block/nvme.c | 46 +++++++++++++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 17 deletions(-)
hw/block/nvme.h +3 -0
index 65c80cfaef62..cebe6018a234 100644
@@ -30,6 +30,7 @@ typedef struct NvmeParams {
     uint8_t  zasl;
     bool     legacy_cmb;
     uint16_t oncs;
+    uint16_t oacs;
 } NvmeParams;
 
 typedef struct NvmeAsyncEvent {
@@ -213,6 +214,8 @@ typedef struct NvmeCtrl {
     NvmeIdCtrl      id_ctrl;
     NvmeFeatureVal  features;
 
+    uint32_t acs[NVME_MAX_COMMANDS];
+
     struct {
         uint32_t nvm[NVME_MAX_COMMANDS];
         uint32_t zoned[NVME_MAX_COMMANDS];
hw/block/nvme.c +29 -17

94 lines not on this page · raw message

Signature · 1 line
2.30.1
#3 lore raw

PATCH 3/3 hw/block/nvme: add administrative controller type

In reply to Klaus Jensen

From: Padmakar Kalghatgi <[email protected]>

Add the 'administrative' nvme device parameter. This causes the controller to behave as an Administrative Controller.

See NVM Express v1.4b, Section 7.1.2 ("Administrative Controller").

---
 hw/block/nvme.h        |  1 +
 include/block/nvme.h   |  8 ++++
 hw/block/nvme-subsys.c |  6 ++-
 hw/block/nvme.c        | 86 ++++++++++++++++++++++++++++++------------
 4 files changed, 76 insertions(+), 25 deletions(-)
hw/block/nvme.h +1 -0
index cebe6018a234..364edb82b60e 100644
@@ -31,6 +31,7 @@ typedef struct NvmeParams {
     bool     legacy_cmb;
     uint16_t oncs;
     uint16_t oacs;
+    bool     administrative;
 } NvmeParams;
 
 typedef struct NvmeAsyncEvent {
include/block/nvme.h +8 -0
index 372d0f2799fb..907cd5a9cf62 100644
@@ -586,6 +586,11 @@ enum NvmeIoCommands {
     NVME_CMD_ZONE_APPEND        = 0x7d,
 };
 
+enum NvmeIdCtrlCntrlType {
+    NVME_CNTRL_TYPE_IO          = 0x1,
+    NVME_CNTRL_TYPE_ADMIN       = 0x3,
+};
+
 typedef struct QEMU_PACKED NvmeDeleteQ {
     uint8_t     opcode;
     uint8_t     flags;
@@ -944,6 +949,8 @@ enum NvmeLogIdentifier {
     NVME_LOG_FW_SLOT_INFO   = 0x03,
     NVME_LOG_CHANGED_NSLIST = 0x04,
     NVME_LOG_CMD_EFFECTS    = 0x05,
+
+    NVME_LID_MAX            = 0x100,
 };
 
 typedef struct QEMU_PACKED NvmePSD {
@@ -1165,6 +1172,7 @@ enum NvmeFeatureIds {
     NVME_TIMESTAMP                  = 0xe,
     NVME_COMMAND_SET_PROFILE        = 0x19,
     NVME_SOFTWARE_PROGRESS_MARKER   = 0x80,
+
     NVME_FID_MAX                    = 0x100,
 };
 
hw/block/nvme-subsys.c +5 -1
index af4804a819ee..051ef0f32b3f 100644
@@ -60,7 +60,11 @@ int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp)
     for (i = 0; i < ARRAY_SIZE(subsys->ctrls); i++) {
         n = subsys->ctrls[i];
 
-        if (n && nvme_register_namespace(n, ns, errp)) {
+        if (!n || n->params.administrative) {
+            continue;
+        }
+
+        if (nvme_register_namespace(n, ns, errp)) {
             return -1;
         }
     }
hw/block/nvme.c +62 -24

168 lines not on this page · raw message

Signature · 1 line
2.30.1