mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
hw/nvme: always initialize a subsystem
If no nvme-subsys is explicitly configured, instantiate one. Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
This commit is contained in:
parent
23a4b3ebc7
commit
cd59f50ab0
2 changed files with 42 additions and 58 deletions
|
@ -8823,15 +8823,13 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)
|
|||
id->psd[0].enlat = cpu_to_le32(0x10);
|
||||
id->psd[0].exlat = cpu_to_le32(0x4);
|
||||
|
||||
if (n->subsys) {
|
||||
id->cmic |= NVME_CMIC_MULTI_CTRL;
|
||||
ctratt |= NVME_CTRATT_ENDGRPS;
|
||||
id->cmic |= NVME_CMIC_MULTI_CTRL;
|
||||
ctratt |= NVME_CTRATT_ENDGRPS;
|
||||
|
||||
id->endgidmax = cpu_to_le16(0x1);
|
||||
id->endgidmax = cpu_to_le16(0x1);
|
||||
|
||||
if (n->subsys->endgrp.fdp.enabled) {
|
||||
ctratt |= NVME_CTRATT_FDPS;
|
||||
}
|
||||
if (n->subsys->endgrp.fdp.enabled) {
|
||||
ctratt |= NVME_CTRATT_FDPS;
|
||||
}
|
||||
|
||||
id->ctratt = cpu_to_le32(ctratt);
|
||||
|
@ -8860,7 +8858,15 @@ static int nvme_init_subsys(NvmeCtrl *n, Error **errp)
|
|||
int cntlid;
|
||||
|
||||
if (!n->subsys) {
|
||||
return 0;
|
||||
DeviceState *dev = qdev_new(TYPE_NVME_SUBSYS);
|
||||
|
||||
qdev_prop_set_string(dev, "nqn", n->params.serial);
|
||||
|
||||
if (!qdev_realize(dev, NULL, errp)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
n->subsys = NVME_SUBSYS(dev);
|
||||
}
|
||||
|
||||
cntlid = nvme_subsys_register_ctrl(n, errp);
|
||||
|
@ -8950,17 +8956,15 @@ static void nvme_exit(PCIDevice *pci_dev)
|
|||
|
||||
nvme_ctrl_reset(n, NVME_RESET_FUNCTION);
|
||||
|
||||
if (n->subsys) {
|
||||
for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
|
||||
ns = nvme_ns(n, i);
|
||||
if (ns) {
|
||||
ns->attached--;
|
||||
}
|
||||
for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
|
||||
ns = nvme_ns(n, i);
|
||||
if (ns) {
|
||||
ns->attached--;
|
||||
}
|
||||
|
||||
nvme_subsys_unregister_ctrl(n->subsys, n);
|
||||
}
|
||||
|
||||
nvme_subsys_unregister_ctrl(n->subsys, n);
|
||||
|
||||
g_free(n->cq);
|
||||
g_free(n->sq);
|
||||
g_free(n->aer_reqs);
|
||||
|
|
64
hw/nvme/ns.c
64
hw/nvme/ns.c
|
@ -727,25 +727,14 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)
|
|||
uint32_t nsid = ns->params.nsid;
|
||||
int i;
|
||||
|
||||
if (!n->subsys) {
|
||||
/* If no subsys, the ns cannot be attached to more than one ctrl. */
|
||||
ns->params.shared = false;
|
||||
if (ns->params.detached) {
|
||||
error_setg(errp, "detached requires that the nvme device is "
|
||||
"linked to an nvme-subsys device");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* If this namespace belongs to a subsystem (through a link on the
|
||||
* controller device), reparent the device.
|
||||
*/
|
||||
if (!qdev_set_parent_bus(dev, &subsys->bus.parent_bus, errp)) {
|
||||
return;
|
||||
}
|
||||
ns->subsys = subsys;
|
||||
ns->endgrp = &subsys->endgrp;
|
||||
assert(subsys);
|
||||
|
||||
/* reparent to subsystem bus */
|
||||
if (!qdev_set_parent_bus(dev, &subsys->bus.parent_bus, errp)) {
|
||||
return;
|
||||
}
|
||||
ns->subsys = subsys;
|
||||
ns->endgrp = &subsys->endgrp;
|
||||
|
||||
if (nvme_ns_setup(ns, errp)) {
|
||||
return;
|
||||
|
@ -753,7 +742,7 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)
|
|||
|
||||
if (!nsid) {
|
||||
for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
|
||||
if (nvme_ns(n, i) || nvme_subsys_ns(subsys, i)) {
|
||||
if (nvme_subsys_ns(subsys, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -765,38 +754,29 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)
|
|||
error_setg(errp, "no free namespace id");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (nvme_ns(n, nsid) || nvme_subsys_ns(subsys, nsid)) {
|
||||
error_setg(errp, "namespace id '%d' already allocated", nsid);
|
||||
return;
|
||||
}
|
||||
} else if (nvme_subsys_ns(subsys, nsid)) {
|
||||
error_setg(errp, "namespace id '%d' already allocated", nsid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (subsys) {
|
||||
subsys->namespaces[nsid] = ns;
|
||||
subsys->namespaces[nsid] = ns;
|
||||
|
||||
ns->id_ns.endgid = cpu_to_le16(0x1);
|
||||
ns->id_ns_ind.endgrpid = cpu_to_le16(0x1);
|
||||
ns->id_ns.endgid = cpu_to_le16(0x1);
|
||||
ns->id_ns_ind.endgrpid = cpu_to_le16(0x1);
|
||||
|
||||
if (ns->params.detached) {
|
||||
return;
|
||||
}
|
||||
if (ns->params.detached) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ns->params.shared) {
|
||||
for (i = 0; i < ARRAY_SIZE(subsys->ctrls); i++) {
|
||||
NvmeCtrl *ctrl = subsys->ctrls[i];
|
||||
if (ns->params.shared) {
|
||||
for (i = 0; i < ARRAY_SIZE(subsys->ctrls); i++) {
|
||||
NvmeCtrl *ctrl = subsys->ctrls[i];
|
||||
|
||||
if (ctrl && ctrl != SUBSYS_SLOT_RSVD) {
|
||||
nvme_attach_ns(ctrl, ns);
|
||||
}
|
||||
if (ctrl && ctrl != SUBSYS_SLOT_RSVD) {
|
||||
nvme_attach_ns(ctrl, ns);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nvme_attach_ns(n, ns);
|
||||
}
|
||||
|
||||
static const Property nvme_ns_props[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue