diff mbox series

[v3,2/2] hw/nvme: Add property for user-specified IEEE-OUI ID

Message ID 20241202091049.2250-3-saif.abrar@linux.vnet.ibm.com (mailing list archive)
State New
Headers show
Series hw/nvme: Add properties for PCI vendor/device IDs and IEEE-OUI | expand

Commit Message

Saif Abrar Dec. 2, 2024, 9:10 a.m. UTC
User-specified IEEE-OUI ID (Identify Controller bytes 75:73)
is to be specified in LE format.
(e.g. ieee_oui=0xABCDEF => Byte[73]=0xEF, Byte[74]=0xCD, Byte[75]=0xAB)

Signed-off-by: Saif Abrar <saif.abrar@linux.vnet.ibm.com>
---
This is a new commit for setting IEEE-OUI ID.

 hw/nvme/ctrl.c | 24 ++++++++++++++++++++++++
 hw/nvme/nvme.h |  2 ++
 2 files changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index e1aaab01bc..cf7b487a67 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -8708,6 +8708,10 @@  static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
         id->ieee[0] = 0xb3;
         id->ieee[1] = 0x02;
         id->ieee[2] = 0x00;
+    } else if (n->params.ieee_oui) {
+        id->ieee[0] = extract32(n->params.ieee_oui, 0,  8);
+        id->ieee[1] = extract32(n->params.ieee_oui, 8,  8);
+        id->ieee[2] = extract32(n->params.ieee_oui, 16, 8);
     } else {
         id->ieee[0] = 0x00;
         id->ieee[1] = 0x54;
@@ -8925,6 +8929,24 @@  static void nvme_exit(PCIDevice *pci_dev)
     memory_region_del_subregion(&n->bar0, &n->iomem);
 }
 
+static void nvme_prop_ieee_set(Object *obj, Visitor *v, const char *name,
+        void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    uint32_t *val = object_field_prop_ptr(obj, prop);
+    if (!visit_type_uint32(v, name, val, errp)) {
+        return;
+    }
+}
+
+static const PropertyInfo nvme_prop_ieee = {
+    .name  = "uint32",
+    .description = "IEEE OUI: Identify Controller bytes 75:73\
+ in LE format. (e.g. ieee_oui=0xABCDEF => Byte[73]=0xEF, Byte[74]=0xCD,\
+ Byte[75]=0xAB)",
+    .set = nvme_prop_ieee_set,
+};
+
 static Property nvme_props[] = {
     DEFINE_BLOCK_PROPERTIES(NvmeCtrl, namespace.blkconf),
     DEFINE_PROP_LINK("pmrdev", NvmeCtrl, pmr.dev, TYPE_MEMORY_BACKEND,
@@ -8968,6 +8990,8 @@  static Property nvme_props[] = {
     DEFINE_PROP_UINT16("id_subsys_vendor", NvmeCtrl,
                                                     params.id_subsys_vendor, 0),
     DEFINE_PROP_UINT16("id_subsys", NvmeCtrl, params.id_subsys, 0),
+    DEFINE_PROP("ieee_oui", NvmeCtrl, params.ieee_oui, nvme_prop_ieee,
+                                                                      uint32_t),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h
index 79404b3129..f26bf7052c 100644
--- a/hw/nvme/nvme.h
+++ b/hw/nvme/nvme.h
@@ -558,6 +558,8 @@  typedef struct NvmeParams {
     uint16_t id_device;
     uint16_t id_subsys_vendor;
     uint16_t id_subsys;
+
+    uint32_t ieee_oui;
 } NvmeParams;
 
 typedef struct NvmeCtrl {