env: make the generic device attach API public

This follows the overall model introduced together
with PCI device hooks. Having an additional set of
attach/enumerate/hook functions for each device type
doesn't scale well. We can simplify this by moving
the driver-agnostic attach and enumerate functions to
the public headers. It'll be used directly by the
upcoming VMD driver.

Change-Id: Ie2039389b6ea530d74d568dc7ebe8b214f547057
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/435804
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Darek Stojaczyk 2018-12-02 15:16:19 +01:00 committed by Jim Harris
parent aade7e3bc7
commit 38462248bf
2 changed files with 35 additions and 20 deletions

View File

@ -627,13 +627,14 @@ typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev)
struct spdk_pci_driver *spdk_pci_nvme_get_driver(void); struct spdk_pci_driver *spdk_pci_nvme_get_driver(void);
/** /**
* Enumerate all NVMe devices on the PCI bus and try to attach those that * Enumerate all PCI devices supported by the provided driver and try to
* weren't attached yet. The provided callback will be called for each such * attach those that weren't attached yet. The provided callback will be
* device and its return code will decide whether that device is attached * called for each such device and its return code will decide whether that
* or not. Attached devices have to be manually detached with * device is attached or not. Attached devices have to be manually detached
* spdk_pci_device_detach() to be attach-able again. * with spdk_pci_device_detach() to be attach-able again.
* *
* \param enum_cb Callback to be called for each non-attached NVMe device. * \param driver Driver for a specific device type.
* \param enum_cb Callback to be called for each non-attached PCI device.
* The return code can be as follows: * The return code can be as follows:
* -1 - device was not attached, the enumeration is stopped * -1 - device was not attached, the enumeration is stopped
* 0 - device attached successfully, enumeration continues * 0 - device attached successfully, enumeration continues
@ -643,13 +644,21 @@ struct spdk_pci_driver *spdk_pci_nvme_get_driver(void);
* \return -1 if an internal error occured or the provided callback returned -1, * \return -1 if an internal error occured or the provided callback returned -1,
* 0 otherwise * 0 otherwise
*/ */
int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx);
/**
* Enumerate all NVMe devices on the PCI bus and try to attach those that
* weren't attached yet.
*
* \see spdk_pci_enumerate
*/
int spdk_pci_nvme_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); int spdk_pci_nvme_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
/** /**
* Enumerate all I/OAT devices on the PCI bus and try to attach those that * Enumerate all I/OAT devices on the PCI bus and try to attach those that
* weren't attached yet. * weren't attached yet.
* *
* \see spdk_pci_nvme_enumerate * \see spdk_pci_enumerate
*/ */
int spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); int spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
@ -657,7 +666,7 @@ int spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
* Enumerate all Virtio devices on the PCI bus and try to attach those that * Enumerate all Virtio devices on the PCI bus and try to attach those that
* weren't attached yet. * weren't attached yet.
* *
* \see spdk_pci_nvme_enumerate * \see spdk_pci_enumerate
*/ */
int spdk_pci_virtio_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx); int spdk_pci_virtio_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
@ -824,13 +833,15 @@ int spdk_pci_device_claim(const struct spdk_pci_addr *pci_addr);
void spdk_pci_device_detach(struct spdk_pci_device *device); void spdk_pci_device_detach(struct spdk_pci_device *device);
/** /**
* Attach a PCI NVMe device. This will bypass all blacklist rules and * Attach a PCI device. This will bypass all blacklist rules and explicitly
* explicitly attach a PCI device at the provided address. The return code * attach a device at the provided address. The return code of the provided
* of the provided callback will decide whether that device is attached * callback will decide whether that device is attached or not. Attached
* or not. Attached devices have to be manually detached with * devices have to be manually detached with spdk_pci_device_detach() to be
* spdk_pci_device_detach() to be attach-able again. * attach-able again.
* *
* \param enum_cb Callback to be called for the NVMe device once it's found. * \param driver Driver for a specific device type. The device will only be
* attached if it's supported by this driver.
* \param enum_cb Callback to be called for the PCI device once it's found.
* The return code can be as follows: * The return code can be as follows:
* -1, 1 - an error occured, fail the attach request entirely * -1, 1 - an error occured, fail the attach request entirely
* 0 - device attached successfully * 0 - device attached successfully
@ -841,13 +852,21 @@ void spdk_pci_device_detach(struct spdk_pci_device *device);
* -1 if an internal error happened or the provided callback returned non-zero, * -1 if an internal error happened or the provided callback returned non-zero,
* 0 otherwise * 0 otherwise
*/ */
int spdk_pci_device_attach(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb,
void *enum_ctx, struct spdk_pci_addr *pci_address);
/**
* Attach a PCI NVMe device.
*
* \see spdk_pci_device_attach
*/
int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address); struct spdk_pci_addr *pci_address);
/** /**
* Attach a PCI I/OAT device. * Attach a PCI I/OAT device.
* *
* \see spdk_pci_nvme_device_attach * \see spdk_pci_device_attach
*/ */
int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address); struct spdk_pci_addr *pci_address);
@ -855,7 +874,7 @@ int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
/** /**
* Attach a PCI Virtio device. * Attach a PCI Virtio device.
* *
* \see spdk_pci_nvme_device_attach * \see spdk_pci_device_attach
*/ */
int spdk_pci_virtio_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, int spdk_pci_virtio_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address); struct spdk_pci_addr *pci_address);

View File

@ -90,10 +90,6 @@ void spdk_pci_driver_register(struct spdk_pci_driver *driver);
int spdk_pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device); int spdk_pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device);
int spdk_pci_device_fini(struct rte_pci_device *device); int spdk_pci_device_fini(struct rte_pci_device *device);
int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx);
int spdk_pci_device_attach(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address);
void spdk_pci_init(void); void spdk_pci_init(void);
int spdk_mem_map_init(void); int spdk_mem_map_init(void);
int spdk_vtophys_init(void); int spdk_vtophys_init(void);