nvme: add function to get PCI device from ctrlr

This allows us to remove most uses of spdk_pci_get_device(), which looks
up a PCI device structure from an arbitrary PCI address.  This function
is problematic, since it uses internal DPDK data structures that aren't
meant to be part of the public API.  There is still one use in the
codebase, which will be cleaned up in another patch.

Change-Id: Ia1fe1f799c240195f6871c1d92821074f884c4e6
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/405707
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2018-03-28 15:36:02 -07:00 committed by Jim Harris
parent ed1ce3197f
commit a78ddd8231
4 changed files with 25 additions and 2 deletions

View File

@ -571,7 +571,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
return;
}
pci_dev = spdk_pci_get_device(&pci_addr);
pci_dev = spdk_nvme_ctrlr_get_pci_device(ctrlr);
if (!pci_dev) {
return;
}

View File

@ -1483,7 +1483,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
return;
}
pci_dev = spdk_pci_get_device(&pci_addr);
pci_dev = spdk_nvme_ctrlr_get_pci_device(ctrlr);
if (!pci_dev) {
return;
}

View File

@ -459,6 +459,15 @@ union spdk_nvme_vs_register spdk_nvme_ctrlr_get_regs_vs(struct spdk_nvme_ctrlr *
*/
uint32_t spdk_nvme_ctrlr_get_num_ns(struct spdk_nvme_ctrlr *ctrlr);
/**
* \brief Get the PCI device of a given NVMe controller.
*
* \return PCI device of the NVMe controller, or NULL if not available.
*
* This only works for local (PCIe-attached) NVMe controllers; other transports will return NULL.
*/
struct spdk_pci_device *spdk_nvme_ctrlr_get_pci_device(struct spdk_nvme_ctrlr *ctrlr);
/**
* \brief Determine if a particular log page is supported by the given NVMe controller.
*

View File

@ -1796,6 +1796,20 @@ spdk_nvme_ctrlr_get_ns(struct spdk_nvme_ctrlr *ctrlr, uint32_t ns_id)
return &ctrlr->ns[ns_id - 1];
}
struct spdk_pci_device *
spdk_nvme_ctrlr_get_pci_device(struct spdk_nvme_ctrlr *ctrlr)
{
if (ctrlr == NULL) {
return NULL;
}
if (ctrlr->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
return NULL;
}
return nvme_ctrlr_proc_get_devhandle(ctrlr);
}
void
spdk_nvme_ctrlr_register_aer_callback(struct spdk_nvme_ctrlr *ctrlr,
spdk_nvme_aer_cb aer_cb_fn,