env: add spdk_pci_driver_register() to the public API
This allows SPDK apps to register new PCI drivers outside of the env layer, enabling SPDK as a whole with new use cases. Change-Id: I0c998a9ec249c3ca610b7b3b8b6caf616b16f64c Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3185 Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Jacek Kalwas <jacek.kalwas@intel.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
3498c0a886
commit
f425f16385
@ -41,6 +41,7 @@
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/queue.h"
|
||||
#include "spdk/pci_ids.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -663,6 +664,13 @@ struct spdk_pci_id {
|
||||
uint16_t subdevice_id; /**< Subsystem device ID or SPDK_PCI_ANY_ID. */
|
||||
};
|
||||
|
||||
/** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */
|
||||
#define SPDK_PCI_DRIVER_NEED_MAPPING 0x0001
|
||||
/** Device needs PCI BAR mapping with enabled write combining (wc) */
|
||||
#define SPDK_PCI_DRIVER_WC_ACTIVATE 0x0002
|
||||
|
||||
void spdk_pci_driver_register(const char *name, struct spdk_pci_id *id_table, uint32_t flags);
|
||||
|
||||
struct spdk_pci_device {
|
||||
struct spdk_pci_device *parent;
|
||||
void *dev_handle;
|
||||
@ -698,6 +706,19 @@ struct spdk_pci_device {
|
||||
|
||||
typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
||||
|
||||
#define SPDK_PCI_DEVICE(vend, dev) \
|
||||
.class_id = SPDK_PCI_CLASS_ANY_ID, \
|
||||
.vendor_id = (vend), \
|
||||
.device_id = (dev), \
|
||||
.subvendor_id = SPDK_PCI_ANY_ID, \
|
||||
.subdevice_id = SPDK_PCI_ANY_ID
|
||||
|
||||
#define SPDK_PCI_DRIVER_REGISTER(name, id_table, flags) \
|
||||
__attribute__((constructor)) static void pci_drv ## _register(void) \
|
||||
{ \
|
||||
spdk_pci_driver_register(name, id_table, flags); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NVMe PCI driver object.
|
||||
*
|
||||
|
@ -59,24 +59,6 @@
|
||||
#define SHIFT_1GB 30 /* (1 << 30) == 1 GB */
|
||||
#define MASK_1GB ((1ULL << SHIFT_1GB) - 1)
|
||||
|
||||
#define SPDK_PCI_DRIVER_REGISTER(pci_drv) \
|
||||
__attribute__((constructor)) static void pci_drv ## _register(void) \
|
||||
{ \
|
||||
pci_driver_register(&pci_drv); \
|
||||
}
|
||||
|
||||
/** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */
|
||||
#define SPDK_PCI_DRIVER_NEED_MAPPING 0x0001
|
||||
/** Device needs PCI BAR mapping with enabled write combining (wc) */
|
||||
#define SPDK_PCI_DRIVER_WC_ACTIVATE 0x0002
|
||||
|
||||
#define SPDK_PCI_DEVICE(vend, dev) \
|
||||
.class_id = SPDK_PCI_CLASS_ANY_ID, \
|
||||
.vendor_id = (vend), \
|
||||
.device_id = (dev), \
|
||||
.subvendor_id = SPDK_PCI_ANY_ID, \
|
||||
.subdevice_id = SPDK_PCI_ANY_ID
|
||||
|
||||
#define SPDK_PCI_DRIVER_MAX_NAME_LEN 32
|
||||
struct spdk_pci_driver {
|
||||
struct rte_pci_driver driver;
|
||||
@ -90,7 +72,6 @@ struct spdk_pci_driver {
|
||||
TAILQ_ENTRY(spdk_pci_driver) tailq;
|
||||
};
|
||||
|
||||
void pci_driver_register(struct spdk_pci_driver *driver);
|
||||
int pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device);
|
||||
int pci_device_fini(struct rte_pci_device *device);
|
||||
|
||||
|
@ -172,8 +172,19 @@ detach_rte(struct spdk_pci_device *dev)
|
||||
}
|
||||
|
||||
void
|
||||
pci_driver_register(struct spdk_pci_driver *driver)
|
||||
spdk_pci_driver_register(const char *name, struct spdk_pci_id *id_table, uint32_t flags)
|
||||
{
|
||||
struct spdk_pci_driver *driver;
|
||||
|
||||
driver = calloc(1, sizeof(*driver));
|
||||
if (!driver) {
|
||||
/* we can't do any better than bailing atm */
|
||||
return;
|
||||
}
|
||||
|
||||
driver->name = name;
|
||||
driver->id_table = id_table;
|
||||
driver->drv_flags = flags;
|
||||
TAILQ_INSERT_TAIL(&g_pci_drivers, driver, tailq);
|
||||
}
|
||||
|
||||
|
@ -41,16 +41,10 @@ static struct spdk_pci_id idxd_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
static struct spdk_pci_driver g_idxd_pci_drv = {
|
||||
.name = "idxd",
|
||||
.id_table = idxd_driver_id,
|
||||
.drv_flags = SPDK_PCI_DRIVER_NEED_MAPPING
|
||||
};
|
||||
|
||||
struct spdk_pci_driver *
|
||||
spdk_pci_idxd_get_driver(void)
|
||||
{
|
||||
return &g_idxd_pci_drv;
|
||||
return spdk_pci_get_driver("idxd");
|
||||
}
|
||||
|
||||
SPDK_PCI_DRIVER_REGISTER(g_idxd_pci_drv);
|
||||
SPDK_PCI_DRIVER_REGISTER("idxd", idxd_driver_id, SPDK_PCI_DRIVER_NEED_MAPPING);
|
||||
|
@ -89,16 +89,10 @@ static struct spdk_pci_id ioat_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
static struct spdk_pci_driver g_ioat_pci_drv = {
|
||||
.name = "ioat",
|
||||
.id_table = ioat_driver_id,
|
||||
.drv_flags = SPDK_PCI_DRIVER_NEED_MAPPING
|
||||
};
|
||||
|
||||
struct spdk_pci_driver *
|
||||
spdk_pci_ioat_get_driver(void)
|
||||
{
|
||||
return &g_ioat_pci_drv;
|
||||
return spdk_pci_get_driver("ioat");
|
||||
}
|
||||
|
||||
SPDK_PCI_DRIVER_REGISTER(g_ioat_pci_drv);
|
||||
SPDK_PCI_DRIVER_REGISTER("ioat", ioat_driver_id, SPDK_PCI_DRIVER_NEED_MAPPING);
|
||||
|
@ -46,17 +46,11 @@ static struct spdk_pci_id nvme_pci_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
static struct spdk_pci_driver g_nvme_pci_drv = {
|
||||
.name = "nvme",
|
||||
.id_table = nvme_pci_driver_id,
|
||||
.drv_flags = SPDK_PCI_DRIVER_NEED_MAPPING |
|
||||
SPDK_PCI_DRIVER_WC_ACTIVATE
|
||||
};
|
||||
|
||||
struct spdk_pci_driver *
|
||||
spdk_pci_nvme_get_driver(void)
|
||||
{
|
||||
return &g_nvme_pci_drv;
|
||||
return spdk_pci_get_driver("nvme");
|
||||
}
|
||||
|
||||
SPDK_PCI_DRIVER_REGISTER(g_nvme_pci_drv);
|
||||
SPDK_PCI_DRIVER_REGISTER("nvme", nvme_pci_driver_id,
|
||||
SPDK_PCI_DRIVER_NEED_MAPPING | SPDK_PCI_DRIVER_WC_ACTIVATE);
|
||||
|
@ -43,17 +43,11 @@ static struct spdk_pci_id virtio_pci_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
static struct spdk_pci_driver g_virtio_pci_drv = {
|
||||
.name = "virtio",
|
||||
.id_table = virtio_pci_driver_id,
|
||||
.drv_flags = SPDK_PCI_DRIVER_NEED_MAPPING |
|
||||
SPDK_PCI_DRIVER_WC_ACTIVATE
|
||||
};
|
||||
|
||||
struct spdk_pci_driver *
|
||||
spdk_pci_virtio_get_driver(void)
|
||||
{
|
||||
return &g_virtio_pci_drv;
|
||||
return spdk_pci_get_driver("virtio");
|
||||
}
|
||||
|
||||
SPDK_PCI_DRIVER_REGISTER(g_virtio_pci_drv);
|
||||
SPDK_PCI_DRIVER_REGISTER("virtio", virtio_pci_driver_id,
|
||||
SPDK_PCI_DRIVER_NEED_MAPPING | SPDK_PCI_DRIVER_WC_ACTIVATE);
|
||||
|
@ -40,17 +40,11 @@ static struct spdk_pci_id vmd_pci_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
static struct spdk_pci_driver g_vmd_pci_drv = {
|
||||
.name = "vmd",
|
||||
.id_table = vmd_pci_driver_id,
|
||||
.drv_flags = SPDK_PCI_DRIVER_NEED_MAPPING |
|
||||
SPDK_PCI_DRIVER_WC_ACTIVATE
|
||||
};
|
||||
|
||||
struct spdk_pci_driver *
|
||||
spdk_pci_vmd_get_driver(void)
|
||||
{
|
||||
return &g_vmd_pci_drv;
|
||||
return spdk_pci_get_driver("vmd");
|
||||
}
|
||||
|
||||
SPDK_PCI_DRIVER_REGISTER(g_vmd_pci_drv);
|
||||
SPDK_PCI_DRIVER_REGISTER("vmd", vmd_pci_driver_id,
|
||||
SPDK_PCI_DRIVER_NEED_MAPPING | SPDK_PCI_DRIVER_WC_ACTIVATE);
|
||||
|
@ -53,6 +53,7 @@
|
||||
spdk_iommu_is_enabled;
|
||||
spdk_vtophys;
|
||||
spdk_pci_get_driver;
|
||||
spdk_pci_driver_register;
|
||||
spdk_pci_nvme_get_driver;
|
||||
spdk_pci_vmd_get_driver;
|
||||
spdk_pci_idxd_get_driver;
|
||||
|
Loading…
Reference in New Issue
Block a user