1/* 2 * QEMU NVM Express Subsystem: nvme-subsys 3 * 4 * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com> 5 * 6 * This code is licensed under the GNU GPL v2. Refer COPYING. 7 */ 8 9#ifndef NVME_SUBSYS_H 10#define NVME_SUBSYS_H 11 12#define TYPE_NVME_SUBSYS "nvme-subsys" 13#define NVME_SUBSYS(obj) \ 14 OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) 15 16#define NVME_SUBSYS_MAX_CTRLS 32 17#define NVME_MAX_NAMESPACES 256 18 19typedef struct NvmeCtrl NvmeCtrl; 20typedef struct NvmeNamespace NvmeNamespace; 21typedef struct NvmeSubsystem { 22 DeviceState parent_obj; 23 uint8_t subnqn[256]; 24 25 NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; 26 /* Allocated namespaces for this subsystem */ 27 NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1]; 28 29 struct { 30 char *nqn; 31 } params; 32} NvmeSubsystem; 33 34int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); 35 36static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys, 37 uint32_t cntlid) 38{ 39 if (!subsys || cntlid >= NVME_SUBSYS_MAX_CTRLS) { 40 return NULL; 41 } 42 43 return subsys->ctrls[cntlid]; 44} 45 46/* 47 * Return allocated namespace of the specified nsid in the subsystem. 48 */ 49static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys, 50 uint32_t nsid) 51{ 52 if (!subsys || !nsid || nsid > NVME_MAX_NAMESPACES) { 53 return NULL; 54 } 55 56 return subsys->namespaces[nsid]; 57} 58 59#endif /* NVME_SUBSYS_H */ 60