nvme: add accessor to namespace id and eui64
authorPatrick Wildt <patrick@blueri.se>
Thu, 3 Oct 2019 11:48:47 +0000 (13:48 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Sun, 6 Oct 2019 14:02:37 +0000 (16:02 +0200)
This adds a function which can be used by e.g. EFI to retrieve
the namespace identifier and EUI64.  For that it adds the EUI64
to its driver internal namespace structure and copies the EUI64
during namespace identification.

Signed-off-by: Patrick Wildt <patrick@blueri.se>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
drivers/nvme/nvme.c
drivers/nvme/nvme.h
include/nvme.h

index 47f101e..ee6b581 100644 (file)
@@ -621,6 +621,18 @@ static int nvme_get_info_from_identify(struct nvme_dev *dev)
        return 0;
 }
 
+int nvme_get_namespace_id(struct udevice *udev, u32 *ns_id, u8 *eui64)
+{
+       struct nvme_ns *ns = dev_get_priv(udev);
+
+       if (ns_id)
+               *ns_id = ns->ns_id;
+       if (eui64)
+               memcpy(eui64, ns->eui64, sizeof(ns->eui64));
+
+       return 0;
+}
+
 int nvme_scan_namespace(void)
 {
        struct uclass *uc;
@@ -657,6 +669,7 @@ static int nvme_blk_probe(struct udevice *udev)
        if (nvme_identify(ndev, ns->ns_id, 0, (dma_addr_t)(long)id))
                return -EIO;
 
+       memcpy(&ns->eui64, &id->eui64, sizeof(id->eui64));
        flbas = id->flbas & NVME_NS_FLBAS_LBA_MASK;
        ns->flbas = flbas;
        ns->lba_shift = id->lbaf[flbas].ds;
index 922f7ab..0e8cb22 100644 (file)
@@ -637,6 +637,7 @@ struct nvme_ns {
        struct list_head list;
        struct nvme_dev *dev;
        unsigned ns_id;
+       u8 eui64[8];
        int devnum;
        int lba_shift;
        u8 flbas;
index 2c3d14d..2cdf8ce 100644 (file)
@@ -78,4 +78,16 @@ int nvme_scan_namespace(void);
  */
 int nvme_print_info(struct udevice *udev);
 
+/**
+ * nvme_get_namespace_id - return namespace identifier
+ *
+ * This returns the namespace identifier.
+ *
+ * @udev:      NVMe controller device
+ * @ns_id:     Place where to put the name space identifier
+ * @eui64:     Place where to put the IEEE Extended Unique Identifier
+ * @return:    0 on success, -ve on error
+ */
+int nvme_get_namespace_id(struct udevice *udev, u32 *ns_id, u8 *eui64);
+
 #endif /* __NVME_H__ */