NVMe: Initial commit
PATCH v3 1/1 NVMe: Initial commit
Initial commit for emulated nvme pci device. Implements the minimum from the specification to work with existing drivers.
Just going for the simplest patch possible for this device. If this is okay, the remainining features implementing the full specification won't be far behind.
I've incorporated all the comments received. The only thing I didn't see how to make use of was the new initialization APIs; it doesn't look like there is anything for me to do with this device in "instance_init".
Thanks for all the feedback!
--- MAINTAINERS | 5 + default-configs/pci.mak | 1 + hw/Makefile.objs | 2 + hw/nvme.c | 930 +++++++++++++++++++++++++++++++++++++++++++++++ hw/nvme.h | 713 ++++++++++++++++++++++++++++++++++++ hw/pci/pci_ids.h | 1 + 6 files changed, 1652 insertions(+), 0 deletions(-) create mode 100644 hw/nvme.c create mode 100644 hw/nvme.h
MAINTAINERS +5 -0
@@ -585,6 +585,11 @@ S: Supported F: hw/virtio-serial* F: hw/virtio-console* +nvme +M: Keith Busch <[email protected]> +S: Supported +F: hw/nvme* + Xilinx EDK M: Peter Crosthwaite <[email protected]> M: Edgar E. Iglesias <[email protected]>
default-configs/pci.mak +1 -0
@@ -11,6 +11,7 @@ CONFIG_PCNET_PCI=y CONFIG_PCNET_COMMON=y CONFIG_LSI_SCSI_PCI=y CONFIG_MEGASAS_SCSI_PCI=y +CONFIG_NVME_PCI=y CONFIG_RTL8139_PCI=y CONFIG_E1000_PCI=y CONFIG_IDE_CORE=y
hw/Makefile.objs +2 -0
@@ -46,6 +46,8 @@ common-obj-$(CONFIG_I8259) += i8259_common.o i8259.o common-obj-$(CONFIG_SDHCI) += sdhci.o common-obj-y += pam.o +common-obj-$(CONFIG_NVME_PCI) += nvme.o + # PPC devices common-obj-$(CONFIG_PREP_PCI) += prep_pci.o common-obj-$(CONFIG_I82378) += i82378.o
hw/nvme.c new file +930 -0
930 lines not on this page · raw message
hw/nvme.h new file +713 -0
713 lines not on this page · raw message
hw/pci/pci_ids.h +1 -0
@@ -19,6 +19,7 @@#define PCI_CLASS_STORAGE_IDE 0x0101#define PCI_CLASS_STORAGE_RAID 0x0104#define PCI_CLASS_STORAGE_SATA 0x0106 +#define PCI_CLASS_STORAGE_EXPRESS 0x0108#define PCI_CLASS_STORAGE_OTHER 0x0180#define PCI_CLASS_NETWORK_ETHERNET 0x0200
Signature · 1 line
1.7.0.4
Quoted 14 lines · Keith Busch
hw/nvme.c new file +14
-0+static int nvme_init (PCIDevice *pci_dev) +{ +NvmeCtrl *n =NVME (pci_dev); +NvmeIdCtrl *id = &n->id_ctrl; + +int i; +int64_t bs_size; +char serial[sizeof (id->sn)]; +uint8_t *pci_conf; + +if (!(n->conf.bs)) { +return -1 ; + } +
hw/nvme.c line 802
Quoted 10 lines
hw/nvme.c new file +10
-0+ bs_size =bdrv_getlength (n->conf.bs); +if (bs_size <=0 ) { +return -1 ; + } + + n->instance = instance++; +blkconf_serial (&n->conf, &n->serial); +if (!n->serial) { +snprintf ((char *)serial,sizeof (serial),"NVMeQx10%02x" , n->instance); + }
A patch that adds serial autogeneration to virtio-blk was recently posted. Here were my concerns:
Autogenerated IDs have been proposed (for other devices?) before and I think we should avoid them.
The autogenerated serial is not persistent. It can change between QEMU invocations - due to internal changes in QEMU or because the management tool reordered -device options.
Users will be confused and their guests may stop working if they depend on an ID like this.
The solution is to do persistent naming either by really passing -drive serial= or with udev inside the guest using the bus address (PCI devfn) like the new persistent network interface naming for Linux.
Stefan
Quoted 30 lines · Stefan Hajnoczi
Quoted 23 lines · Keith Busch
hw/nvme.c new file +23
-0+static int nvme_init (PCIDevice *pci_dev) +{ +NvmeCtrl *n =NVME (pci_dev); +NvmeIdCtrl *id = &n->id_ctrl; + +int i; +int64_t bs_size; +char serial[sizeof (id->sn)]; +uint8_t *pci_conf; + +if (!(n->conf.bs)) { +return -1 ; + } + + bs_size =bdrv_getlength (n->conf.bs); +if (bs_size <=0 ) { +return -1 ; + } + + n->instance = instance++; +blkconf_serial (&n->conf, &n->serial); +if (!n->serial) { + snprintf((char *)serial, sizeof(serial), "NVMeQx10%02x",Quoted 2 lines
n->instance);
+ }A patch that adds serial autogeneration to virtio-blk was recently posted. Here were my concerns:
Quoted 2 lines
Autogenerated IDs have been proposed (for other devices?) before and I think we should avoid them.
ACK
Quoted 6 lines
The autogenerated serial is not persistent. It can change between QEMU invocations - due to internal changes in QEMU or because the management tool reordered -device options.
Users will be confused and their guests may stop working if they depend on an ID like this.
Only IDE devices auto-generate their serial number. Can't fix that mistake, because it's ABI[*]. All other devices don't. Let's keep it that way.
Quoted 3 lines
The solution is to do persistent naming either by really passing -drive serial= or with udev inside the guest using the bus address (PCI devfn) like the new persistent network interface naming for Linux.
ACK
[*] I could have avoided the mistake for ide-hd and ide-cd, but I didn't see the problem then. Perhaps we could've killed it for AHCI.