[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 12/18] nvme: add namespace helpers
From: |
Klaus Jensen |
Subject: |
[PATCH v5 12/18] nvme: add namespace helpers |
Date: |
Tue, 5 May 2020 07:48:34 +0200 |
From: Klaus Jensen <address@hidden>
Introduce some small helpers to make the next patches easier on the eye.
Signed-off-by: Klaus Jensen <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Maxim Levitsky <address@hidden>
Reviewed-by: Keith Busch <address@hidden>
---
hw/block/nvme.c | 3 +--
hw/block/nvme.h | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index acdd735e0aca..720cc91bcb6a 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -1571,8 +1571,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
id_ns->dps = 0;
id_ns->lbaf[0].ds = BDRV_SECTOR_BITS;
id_ns->ncap = id_ns->nuse = id_ns->nsze =
- cpu_to_le64(n->ns_size >>
- id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds);
+ cpu_to_le64(nvme_ns_nlbas(n, ns));
}
}
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
index 6714616e376e..345eb7bf3a51 100644
--- a/hw/block/nvme.h
+++ b/hw/block/nvme.h
@@ -61,6 +61,17 @@ typedef struct NvmeNamespace {
NvmeIdNs id_ns;
} NvmeNamespace;
+static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns)
+{
+ NvmeIdNs *id_ns = &ns->id_ns;
+ return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
+}
+
+static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns)
+{
+ return nvme_ns_lbaf(ns)->ds;
+}
+
#define TYPE_NVME "nvme"
#define NVME(obj) \
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
@@ -97,4 +108,10 @@ typedef struct NvmeCtrl {
NvmeIdCtrl id_ctrl;
} NvmeCtrl;
+/* calculate the number of LBAs that the namespace can accomodate */
+static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns)
+{
+ return n->ns_size >> nvme_ns_lbads(ns);
+}
+
#endif /* HW_NVME_H */
--
2.26.2
- [PATCH v5 05/18] nvme: use constants in identify, (continued)
- [PATCH v5 05/18] nvme: use constants in identify, Klaus Jensen, 2020/05/05
- [PATCH v5 08/18] nvme: remove redundant cmbloc/cmbsz members, Klaus Jensen, 2020/05/05
- [PATCH v5 02/18] nvme: rename trace events to pci_nvme, Klaus Jensen, 2020/05/05
- [PATCH v5 10/18] nvme: factor out device state setup, Klaus Jensen, 2020/05/05
- [PATCH v5 07/18] nvme: add max_ioqpairs device parameter, Klaus Jensen, 2020/05/05
- [PATCH v5 15/18] nvme: factor out cmb setup, Klaus Jensen, 2020/05/05
- [PATCH v5 14/18] nvme: factor out pci setup, Klaus Jensen, 2020/05/05
- [PATCH v5 09/18] nvme: factor out property/constraint checks, Klaus Jensen, 2020/05/05
- [PATCH v5 11/18] nvme: factor out block backend setup, Klaus Jensen, 2020/05/05
- [PATCH v5 12/18] nvme: add namespace helpers,
Klaus Jensen <=
- [PATCH v5 17/18] nvme: do cmb/pmr init as part of pci init, Klaus Jensen, 2020/05/05
- [PATCH v5 13/18] nvme: factor out namespace setup, Klaus Jensen, 2020/05/05
- [PATCH v5 16/18] nvme: factor out pmr setup, Klaus Jensen, 2020/05/05
- [PATCH v5 18/18] nvme: factor out controller identify setup, Klaus Jensen, 2020/05/05
- Re: [PATCH v5 00/18] nvme: refactoring and cleanups, Philippe Mathieu-Daudé, 2020/05/05
- Re: [PATCH v5 00/18] nvme: refactoring and cleanups, Klaus Jensen, 2020/05/11