Commit a78ddd82 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/405707


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent ed1ce319
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
		}
+1 −1
Original line number Diff line number Diff line
@@ -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;
		}
+9 −0
Original line number Diff line number Diff line
@@ -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.
 *
+14 −0
Original line number Diff line number Diff line
@@ -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,