Commit 4b08c07a authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

env/pci: call driver callback in pci_hook_device



Now that we have a attach_device() callback, the devices can be hooked
during spdk_pci_device_attach().  With DPDK, driver->cb_fn() is called
in pci_device_init(), so we need to do the same in
spdk_pci_hook_device().

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: Iada8b83ce7592aa62561530192072a50ec3a904b
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13884


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTom Nabarro <tom.nabarro@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent ac8b65bd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1149,8 +1149,10 @@ int spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr);
 *
 * \param drv driver that will be able to attach the device
 * \param dev fully initialized PCI device struct
 *
 * \return 0 on success, negative errno otherwise.
 */
void spdk_pci_hook_device(struct spdk_pci_driver *drv, struct spdk_pci_device *dev);
int spdk_pci_hook_device(struct spdk_pci_driver *drv, struct spdk_pci_device *dev);

/**
 * Un-hook a custom PCI device from the PCI layer. The device must not be attached.
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 9
SO_MINOR := 1
SO_VER := 10
SO_MINOR := 0

CFLAGS += $(ENV_CFLAGS)
C_SRCS = env.c memory.c pci.c init.c threads.c
+15 −1
Original line number Diff line number Diff line
@@ -1147,15 +1147,29 @@ spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr)
	return -1;
}

void
int
spdk_pci_hook_device(struct spdk_pci_driver *drv, struct spdk_pci_device *dev)
{
	int rc;

	assert(dev->map_bar != NULL);
	assert(dev->unmap_bar != NULL);
	assert(dev->cfg_read != NULL);
	assert(dev->cfg_write != NULL);
	dev->internal.driver = drv;

	if (drv->cb_fn != NULL) {
		rc = drv->cb_fn(drv->cb_arg, dev);
		if (rc != 0) {
			return -ECANCELED;
		}

		dev->internal.attached = true;
	}

	TAILQ_INSERT_TAIL(&g_pci_devices, dev, internal.tailq);

	return 0;
}

void
+8 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include "vmd_internal.h"

#include "spdk/stdinc.h"
#include "spdk/string.h"
#include "spdk/likely.h"

static unsigned char *device_type[] = {
@@ -896,6 +897,7 @@ vmd_init_end_device(struct vmd_pci_device *dev)
	struct vmd_pci_bus *bus = dev->bus;
	struct vmd_adapter *vmd;
	uint8_t bdf[32];
	int rc;

	if (!vmd_assign_base_addrs(dev)) {
		SPDK_ERRLOG("Failed to allocate BARs for device: %p\n", dev);
@@ -909,7 +911,12 @@ vmd_init_end_device(struct vmd_pci_device *dev)
		spdk_pci_addr_fmt(bdf, sizeof(bdf), &dev->pci.addr);
		SPDK_INFOLOG(vmd, "Initializing NVMe device at %s\n", bdf);
		dev->pci.parent = dev->bus->vmd->pci;
		spdk_pci_hook_device(spdk_pci_nvme_get_driver(), &dev->pci);

		rc = spdk_pci_hook_device(spdk_pci_nvme_get_driver(), &dev->pci);
		if (rc != 0) {
			SPDK_ERRLOG("Failed to hook device %s: %s\n", bdf, spdk_strerror(-rc));
			return -1;
		}

		vmd = bus->vmd;
		vmd->target[vmd->nvme_count] = dev;
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ DEPDIRS-ioat := log
DEPDIRS-idxd := log util
DEPDIRS-sock := log $(JSON_LIBS)
DEPDIRS-util := log
DEPDIRS-vmd := log
DEPDIRS-vmd := log util
DEPDIRS-dma := log
DEPDIRS-trace_parser := log
ifeq ($(CONFIG_VFIO_USER),y)
Loading