2 * QEMU NVM Express Virtual Namespace
4 * Copyright (c) 2019 CNEX Labs
5 * Copyright (c) 2020 Samsung Electronics
8 * Klaus Jensen <k.jensen@samsung.com>
10 * This work is licensed under the terms of the GNU GPL, version 2. See the
11 * COPYING file in the top-level directory.
18 #define TYPE_NVME_NS "nvme-ns"
19 #define NVME_NS(obj) \
20 OBJECT_CHECK(NvmeNamespace, (obj), TYPE_NVME_NS)
22 typedef struct NvmeNamespaceParams
{
25 } NvmeNamespaceParams
;
27 typedef struct NvmeNamespace
{
28 DeviceState parent_obj
;
36 NvmeNamespaceParams params
;
43 static inline uint32_t nvme_nsid(NvmeNamespace
*ns
)
46 return ns
->params
.nsid
;
52 static inline NvmeLBAF
*nvme_ns_lbaf(NvmeNamespace
*ns
)
54 NvmeIdNs
*id_ns
= &ns
->id_ns
;
55 return &id_ns
->lbaf
[NVME_ID_NS_FLBAS_INDEX(id_ns
->flbas
)];
58 static inline uint8_t nvme_ns_lbads(NvmeNamespace
*ns
)
60 return nvme_ns_lbaf(ns
)->ds
;
63 /* calculate the number of LBAs that the namespace can accomodate */
64 static inline uint64_t nvme_ns_nlbas(NvmeNamespace
*ns
)
66 return ns
->size
>> nvme_ns_lbads(ns
);
69 /* convert an LBA to the equivalent in bytes */
70 static inline size_t nvme_l2b(NvmeNamespace
*ns
, uint64_t lba
)
72 return lba
<< nvme_ns_lbads(ns
);
75 typedef struct NvmeCtrl NvmeCtrl
;
77 int nvme_ns_setup(NvmeCtrl
*n
, NvmeNamespace
*ns
, Error
**errp
);
78 void nvme_ns_drain(NvmeNamespace
*ns
);
79 void nvme_ns_shutdown(NvmeNamespace
*ns
);
81 #endif /* NVME_NS_H */