diff --git a/include/spdk/env.h b/include/spdk/env.h index 1acaae88f..3f20c86e8 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -302,6 +302,7 @@ typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev) int spdk_pci_nvme_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); int spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); +int spdk_pci_virtio_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); struct spdk_pci_device *spdk_pci_get_device(struct spdk_pci_addr *pci_addr); @@ -340,6 +341,8 @@ int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, struct spdk_pci_addr *pci_address); int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, struct spdk_pci_addr *pci_address); +int spdk_pci_virtio_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, + struct spdk_pci_addr *pci_address); int spdk_pci_device_cfg_read(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t offset); diff --git a/include/spdk/pci_ids.h b/include/spdk/pci_ids.h index 2ac94cf82..ee7e559d8 100644 --- a/include/spdk/pci_ids.h +++ b/include/spdk/pci_ids.h @@ -48,6 +48,7 @@ extern "C" { #define SPDK_PCI_VID_INTEL 0x8086 #define SPDK_PCI_VID_MEMBLAZE 0x1c5f #define SPDK_PCI_VID_VIRTUALBOX 0x80ee +#define SPDK_PCI_VID_VIRTIO 0x1af4 /** * PCI class code for NVMe devices. @@ -114,6 +115,8 @@ extern "C" { #define PCI_DEVICE_ID_INTEL_IOAT_SKX 0x2021 +#define PCI_DEVICE_ID_VIRTIO_SCSI_MODERN 0x1004 + #ifdef __cplusplus } #endif diff --git a/lib/env_dpdk/Makefile b/lib/env_dpdk/Makefile index 6cb70ad1b..b7a6961ff 100644 --- a/lib/env_dpdk/Makefile +++ b/lib/env_dpdk/Makefile @@ -36,7 +36,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk CFLAGS += $(ENV_CFLAGS) C_SRCS = env.c memory.c pci.c vtophys.c init.c threads.c -C_SRCS += pci_nvme.c pci_ioat.c +C_SRCS += pci_nvme.c pci_ioat.c pci_virtio.c LIBNAME = env_dpdk include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/env_dpdk/pci_virtio.c b/lib/env_dpdk/pci_virtio.c new file mode 100644 index 000000000..955b7ff4c --- /dev/null +++ b/lib/env_dpdk/pci_virtio.c @@ -0,0 +1,75 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "env_internal.h" + +#include "spdk/pci_ids.h" + +static struct rte_pci_id virtio_pci_driver_id[] = { + { RTE_PCI_DEVICE(SPDK_PCI_VID_VIRTIO, PCI_DEVICE_ID_VIRTIO_SCSI_MODERN) }, + { .vendor_id = 0, /* sentinel */ }, +}; + +static struct spdk_pci_enum_ctx g_virtio_pci_drv = { + .driver = { + .drv_flags = RTE_PCI_DRV_NEED_MAPPING, + .id_table = virtio_pci_driver_id, +#if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) + .probe = spdk_pci_device_init, + .remove = spdk_pci_device_fini, + .driver.name = "spdk_virtio", +#else + .devinit = spdk_pci_device_init, + .devuninit = spdk_pci_device_fini, + .name = "spdk_virtio", +#endif + }, + + .cb_fn = NULL, + .cb_arg = NULL, + .mtx = PTHREAD_MUTEX_INITIALIZER, + .is_registered = false, +}; + +int +spdk_pci_virtio_device_attach(spdk_pci_enum_cb enum_cb, + void *enum_ctx, struct spdk_pci_addr *pci_address) +{ + return spdk_pci_device_attach(&g_virtio_pci_drv, enum_cb, enum_ctx, pci_address); +} + +int +spdk_pci_virtio_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx) +{ + return spdk_pci_enumerate(&g_virtio_pci_drv, enum_cb, enum_ctx); +}