2 * QEMU NVM Express Subsystem: nvme-subsys
4 * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com>
6 * This code is licensed under the GNU GPL v2. Refer COPYING.
12 #define TYPE_NVME_SUBSYS "nvme-subsys"
13 #define NVME_SUBSYS(obj) \
14 OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)
16 #define NVME_SUBSYS_MAX_CTRLS 32
17 #define NVME_MAX_NAMESPACES 256
19 typedef struct NvmeCtrl NvmeCtrl
;
20 typedef struct NvmeNamespace NvmeNamespace
;
21 typedef struct NvmeSubsystem
{
22 DeviceState parent_obj
;
25 NvmeCtrl
*ctrls
[NVME_SUBSYS_MAX_CTRLS
];
26 /* Allocated namespaces for this subsystem */
27 NvmeNamespace
*namespaces
[NVME_MAX_NAMESPACES
+ 1];
34 int nvme_subsys_register_ctrl(NvmeCtrl
*n
, Error
**errp
);
36 static inline NvmeCtrl
*nvme_subsys_ctrl(NvmeSubsystem
*subsys
,
39 if (!subsys
|| cntlid
>= NVME_SUBSYS_MAX_CTRLS
) {
43 return subsys
->ctrls
[cntlid
];
47 * Return allocated namespace of the specified nsid in the subsystem.
49 static inline NvmeNamespace
*nvme_subsys_ns(NvmeSubsystem
*subsys
,
52 if (!subsys
|| !nsid
|| nsid
> NVME_MAX_NAMESPACES
) {
56 return subsys
->namespaces
[nsid
];
59 #endif /* NVME_SUBSYS_H */