Commit 93933831 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

pci: clean up public pci.h interface



Rename all functions with a spdk_ prefix, and provide enough of an API
to avoid apps needing to #include <pciaccess.h>.

The opaque type used in the public API for a PCI device is now
struct spdk_pci_device *.

Change-Id: I1e7a09bbc5328c624bec8cf5c8a69ab0ea8e8254
Signed-off-by: default avatarZiye Yang <ziye.yang@intel.com>
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 9a924a06
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
#include <rte_lcore.h>
#include <rte_cycles.h>
#include <rte_mempool.h>
#include <pciaccess.h>

#include "spdk/ioat.h"
#include "spdk/pci.h"
#include "spdk/string.h"
@@ -143,17 +143,16 @@ ioat_done(void *cb_arg)
}

static bool
probe_cb(void *cb_ctx, void *pdev)
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev)
{
	struct pci_device *pci_dev = pdev;

	printf(" Found matching device at %d:%d:%d "
	       "vendor:0x%04x device:0x%04x\n   name:%s\n",
	       pci_dev->bus, pci_dev->dev, pci_dev->func,
	       pci_dev->vendor_id, pci_dev->device_id,
	       pci_device_get_device_name(pci_dev));
	       spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
	       spdk_pci_device_get_func(pci_dev),
	       spdk_pci_device_get_vendor_id(pci_dev), spdk_pci_device_get_device_id(pci_dev),
	       spdk_pci_device_get_device_name(pci_dev));

	if (pci_device_has_non_uio_driver(pci_dev)) {
	if (spdk_pci_device_has_non_uio_driver(pci_dev)) {
		printf("Device has non-uio kernel driver, skipping...\n");
		return false;
	}
@@ -162,7 +161,7 @@ probe_cb(void *cb_ctx, void *pdev)
}

static void
attach_cb(void *cb_ctx, void *pdev, struct ioat_channel *ioat)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct ioat_channel *ioat)
{
	struct ioat_device *dev;

@@ -179,7 +178,6 @@ attach_cb(void *cb_ctx, void *pdev, struct ioat_channel *ioat)
static int
ioat_init(void)
{
	pci_system_init();
	TAILQ_INIT(&g_devices);

	if (ioat_probe(NULL, probe_cb, attach_cb) != 0) {
+8 −10
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@
#include <rte_eal.h>
#include <rte_cycles.h>
#include <rte_mempool.h>
#include <pciaccess.h>

#include "spdk/ioat.h"
#include "spdk/pci.h"
#include "spdk/string.h"
@@ -199,17 +199,16 @@ ioat_done(void *cb_arg)
}

static bool
probe_cb(void *cb_ctx, void *pdev)
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev)
{
	struct pci_device *pci_dev = pdev;

	printf(" Found matching device at %d:%d:%d "
	       "vendor:0x%04x device:0x%04x\n   name:%s\n",
	       pci_dev->bus, pci_dev->dev, pci_dev->func,
	       pci_dev->vendor_id, pci_dev->device_id,
	       pci_device_get_device_name(pci_dev));
	       spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
	       spdk_pci_device_get_func(pci_dev),
	       spdk_pci_device_get_vendor_id(pci_dev), spdk_pci_device_get_device_id(pci_dev),
	       spdk_pci_device_get_device_name(pci_dev));

	if (pci_device_has_non_uio_driver(pci_dev)) {
	if (spdk_pci_device_has_non_uio_driver(pci_dev)) {
		printf("Device has non-uio kernel driver, skipping...\n");
		return false;
	}
@@ -218,7 +217,7 @@ probe_cb(void *cb_ctx, void *pdev)
}

static void
attach_cb(void *cb_ctx, void *pdev, struct ioat_channel *ioat)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct ioat_channel *ioat)
{
	struct ioat_device *dev;

@@ -236,7 +235,6 @@ attach_cb(void *cb_ctx, void *pdev, struct ioat_channel *ioat)
static int
ioat_init(void)
{
	pci_system_init();
	TAILQ_INIT(&g_devices);

	if (ioat_probe(NULL, probe_cb, attach_cb) != 0) {
+6 −11
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@
#include <stdbool.h>
#include <unistd.h>

#include <pciaccess.h>

#include <rte_config.h>
#include <rte_malloc.h>
#include <rte_mempool.h>
@@ -365,7 +363,7 @@ print_namespace(struct nvme_namespace *ns)
}

static void
print_controller(struct nvme_controller *ctrlr, struct pci_device *pci_dev)
print_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
{
	const struct nvme_controller_data	*cdata;
	uint8_t					str[128];
@@ -378,7 +376,8 @@ print_controller(struct nvme_controller *ctrlr, struct pci_device *pci_dev)

	printf("=====================================================\n");
	printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
	       pci_dev->bus, pci_dev->dev, pci_dev->func);
	       spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
	       spdk_pci_device_get_func(pci_dev));
	printf("=====================================================\n");

	if (g_hex_dump) {
@@ -769,11 +768,9 @@ parse_args(int argc, char **argv)
}

static bool
probe_cb(void *cb_ctx, void *pci_dev)
probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
{
	struct pci_device *dev = pci_dev;

	if (pci_device_has_non_uio_driver(dev)) {
	if (spdk_pci_device_has_non_uio_driver(dev)) {
		fprintf(stderr, "non-uio kernel driver attached to NVMe\n");
		fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n",
			spdk_pci_device_get_domain(dev),
@@ -788,7 +785,7 @@ probe_cb(void *cb_ctx, void *pci_dev)
}

static void
attach_cb(void *cb_ctx, void *pci_dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
{
	print_controller(ctrlr, pci_dev);
	nvme_detach(ctrlr);
@@ -827,8 +824,6 @@ int main(int argc, char **argv)
		exit(1);
	}

	pci_system_init();

	rc = 0;
	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
+3 −11
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@
#include <string.h>
#include <unistd.h>

#include <pciaccess.h>

#include <rte_config.h>
#include <rte_cycles.h>
#include <rte_mempool.h>
@@ -820,11 +818,9 @@ register_workers(void)
}

static bool
probe_cb(void *cb_ctx, void *pci_dev)
probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
{
	struct pci_device *dev = pci_dev;

	if (pci_device_has_non_uio_driver(dev)) {
	if (spdk_pci_device_has_non_uio_driver(dev)) {
		fprintf(stderr, "non-uio kernel driver attached to NVMe\n");
		fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n",
			spdk_pci_device_get_domain(dev),
@@ -845,10 +841,8 @@ probe_cb(void *cb_ctx, void *pci_dev)
}

static void
attach_cb(void *cb_ctx, void *pci_dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct nvme_controller *ctrlr)
{
	struct pci_device *dev = pci_dev;

	printf("Attached to %04x:%02x:%02x.%02x\n",
	       spdk_pci_device_get_domain(dev),
	       spdk_pci_device_get_bus(dev),
@@ -863,8 +857,6 @@ register_controllers(void)
{
	printf("Initializing NVMe Controllers\n");

	pci_system_init();

	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
		return 1;
+7 −12
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@
#include <unistd.h>
#include <inttypes.h>

#include <pciaccess.h>

#include <rte_config.h>
#include <rte_malloc.h>
#include <rte_mempool.h>
@@ -50,7 +48,7 @@ struct rte_mempool *request_mempool;
#define MAX_DEVS 64

struct dev {
	struct pci_device			*pci_dev;
	struct spdk_pci_device			*pci_dev;
	struct nvme_controller 			*ctrlr;
	char 					name[100];
};
@@ -351,7 +349,7 @@ reservation_ns_release(struct nvme_controller *ctrlr, uint16_t ns_id)
}

static void
reserve_controller(struct nvme_controller *ctrlr, struct pci_device *pci_dev)
reserve_controller(struct nvme_controller *ctrlr, struct spdk_pci_device *pci_dev)
{
	const struct nvme_controller_data	*cdata;

@@ -359,7 +357,8 @@ reserve_controller(struct nvme_controller *ctrlr, struct pci_device *pci_dev)

	printf("=====================================================\n");
	printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
	       pci_dev->bus, pci_dev->dev, pci_dev->func);
	       spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
	       spdk_pci_device_get_func(pci_dev));
	printf("=====================================================\n");

	printf("Reservations:                %s\n",
@@ -379,11 +378,9 @@ reserve_controller(struct nvme_controller *ctrlr, struct pci_device *pci_dev)
}

static bool
probe_cb(void *cb_ctx, void *pci_dev)
probe_cb(void *cb_ctx, struct spdk_pci_device *dev)
{
	struct pci_device *dev = pci_dev;

	if (pci_device_has_non_uio_driver(dev)) {
	if (spdk_pci_device_has_non_uio_driver(dev)) {
		fprintf(stderr, "non-uio kernel driver attached to NVMe\n");
		fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n",
			spdk_pci_device_get_domain(dev),
@@ -398,7 +395,7 @@ probe_cb(void *cb_ctx, void *pci_dev)
}

static void
attach_cb(void *cb_ctx, void *pci_dev, struct nvme_controller *ctrlr)
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
{
	struct dev *dev;

@@ -437,8 +434,6 @@ int main(int argc, char **argv)
		exit(1);
	}

	pci_system_init();

	if (nvme_probe(NULL, probe_cb, attach_cb) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
		return 1;
Loading