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: Ziye Yang <ziye.yang@intel.com> Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
9a924a066e
commit
93933831f7
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include <stdbool.h>
|
||||
#include "spdk/pci.h"
|
||||
|
||||
#include "spdk/pci.h"
|
||||
|
||||
/**
|
||||
* Opaque handle for a single I/OAT channel returned by \ref ioat_probe().
|
||||
*/
|
||||
@ -57,12 +59,13 @@ typedef void (*ioat_callback_t)(void *arg);
|
||||
*
|
||||
* \return true to attach to this device.
|
||||
*/
|
||||
typedef bool (*ioat_probe_cb)(void *cb_ctx, void *pci_dev);
|
||||
typedef bool (*ioat_probe_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev);
|
||||
|
||||
/**
|
||||
* Callback for ioat_probe() to report a device that has been attached to the userspace I/OAT driver.
|
||||
*/
|
||||
typedef void (*ioat_attach_cb)(void *cb_ctx, void *pci_dev, struct ioat_channel *ioat);
|
||||
typedef void (*ioat_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev,
|
||||
struct ioat_channel *ioat);
|
||||
|
||||
/**
|
||||
* \brief Enumerate the I/OAT devices attached to the system and attach the userspace I/OAT driver
|
||||
|
@ -57,12 +57,13 @@ struct nvme_controller;
|
||||
*
|
||||
* \return true to attach to this device.
|
||||
*/
|
||||
typedef bool (*nvme_probe_cb)(void *cb_ctx, void *pci_dev);
|
||||
typedef bool (*nvme_probe_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev);
|
||||
|
||||
/**
|
||||
* Callback for nvme_probe() to report a device that has been attached to the userspace NVMe driver.
|
||||
*/
|
||||
typedef void (*nvme_attach_cb)(void *cb_ctx, void *pci_dev, struct nvme_controller *ctrlr);
|
||||
typedef void (*nvme_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev,
|
||||
struct nvme_controller *ctrlr);
|
||||
|
||||
/**
|
||||
* \brief Enumerate the NVMe devices attached to the system and attach the userspace NVMe driver
|
||||
|
@ -34,41 +34,33 @@
|
||||
#ifndef SPDK_PCI_H
|
||||
#define SPDK_PCI_H
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
#include <pciaccess.h>
|
||||
int spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx);
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define spdk_pci_device_get_domain(dev) (dev->domain)
|
||||
#define spdk_pci_device_get_bus(dev) (dev->bus)
|
||||
#define spdk_pci_device_get_dev(pdev) (pdev->dev)
|
||||
#define spdk_pci_device_get_func(dev) (dev->func)
|
||||
#define spdk_pci_device_get_vendor_id(dev) (dev->vendor_id)
|
||||
#define spdk_pci_device_get_device_id(dev) (dev->device_id)
|
||||
#define spdk_pci_device_get_subvendor_id(dev) (dev->subvendor_id)
|
||||
#define spdk_pci_device_get_subdevice_id(dev) (dev->subdevice_id)
|
||||
#define spdk_pci_device_get_class(dev) (dev->device_class)
|
||||
struct spdk_pci_device;
|
||||
|
||||
#else
|
||||
#include <rte_pci.h>
|
||||
typedef struct rte_pci_device spdk_pci_device;
|
||||
typedef struct rte_pci_driver spdk_pci_driver;
|
||||
int spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev),
|
||||
void *enum_ctx);
|
||||
|
||||
#define spdk_pci_device_get_domain(dev) (dev->addr.domain)
|
||||
#define spdk_pci_device_get_bus(dev) (dev->addr.bus)
|
||||
#define spdk_pci_device_get_dev(dev) (dev->addr.devid)
|
||||
#define spdk_pci_device_get_func(dev) (dev->addr.function)
|
||||
|
||||
#endif
|
||||
|
||||
#define PCI_CFG_SIZE 256
|
||||
#define PCI_EXT_CAP_ID_SN 0x03
|
||||
#define PCI_UIO_DRIVER "uio_pci_generic"
|
||||
|
||||
int pci_device_get_serial_number(struct pci_device *dev, char *sn, int len);
|
||||
int pci_device_has_non_uio_driver(struct pci_device *dev);
|
||||
int pci_device_unbind_kernel_driver(struct pci_device *dev);
|
||||
int pci_device_bind_uio_driver(struct pci_device *dev, char *driver_name);
|
||||
int pci_device_switch_to_uio_driver(struct pci_device *pci_dev);
|
||||
int pci_device_claim(struct pci_device *dev);
|
||||
uint16_t spdk_pci_device_get_domain(struct spdk_pci_device *dev);
|
||||
uint8_t spdk_pci_device_get_bus(struct spdk_pci_device *dev);
|
||||
uint8_t spdk_pci_device_get_dev(struct spdk_pci_device *dev);
|
||||
uint8_t spdk_pci_device_get_func(struct spdk_pci_device *dev);
|
||||
uint16_t spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev);
|
||||
uint16_t spdk_pci_device_get_device_id(struct spdk_pci_device *dev);
|
||||
uint16_t spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev);
|
||||
uint16_t spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev);
|
||||
uint32_t spdk_pci_device_get_class(struct spdk_pci_device *dev);
|
||||
const char *spdk_pci_device_get_device_name(struct spdk_pci_device *dev);
|
||||
|
||||
int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset);
|
||||
int spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset);
|
||||
|
||||
int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len);
|
||||
int spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev);
|
||||
int spdk_pci_device_unbind_kernel_driver(struct spdk_pci_device *dev);
|
||||
int spdk_pci_device_bind_uio_driver(struct spdk_pci_device *dev);
|
||||
int spdk_pci_device_switch_to_uio_driver(struct spdk_pci_device *pci_dev);
|
||||
int spdk_pci_device_claim(struct spdk_pci_device *dev);
|
||||
|
||||
#endif
|
||||
|
@ -501,7 +501,7 @@ struct ioat_enum_ctx {
|
||||
|
||||
/* This function must only be called while holding g_ioat_driver.lock */
|
||||
static int
|
||||
ioat_enum_cb(void *ctx, void *pci_dev)
|
||||
ioat_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct ioat_enum_ctx *enum_ctx = ctx;
|
||||
struct ioat_channel *ioat;
|
||||
|
@ -13,12 +13,15 @@
|
||||
#include "spdk/pci.h"
|
||||
#include "spdk/vtophys.h"
|
||||
#include "spdk/pci.h"
|
||||
#include "spdk/ioat.h"
|
||||
#include "ioat_pci.h"
|
||||
|
||||
|
||||
#include "ioat_pci.h"
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
#include <pciaccess.h>
|
||||
#else
|
||||
#include <rte_pci.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
@ -67,6 +70,12 @@ ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
||||
*/
|
||||
#define ioat_printf(chan, fmt, args...) printf(fmt, ##args)
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#define ioat_pcicfg_read32(handle, var, offset) spdk_pci_device_cfg_read32(handle, var, offset)
|
||||
#define ioat_pcicfg_write32(handle, var, offset) spdk_pci_device_cfg_write32(handle, var, offset)
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
|
||||
static inline bool
|
||||
@ -126,15 +135,14 @@ ioat_pci_device_match_id(uint16_t vendor_id, uint16_t device_id)
|
||||
}
|
||||
|
||||
struct ioat_pci_enum_ctx {
|
||||
int (*user_enum_cb)(void *enum_ctx, void *pci_dev);
|
||||
int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
||||
void *user_enum_ctx;
|
||||
};
|
||||
|
||||
static int
|
||||
ioat_pci_enum_cb(void *enum_ctx, void *pdev)
|
||||
ioat_pci_enum_cb(void *enum_ctx, struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct ioat_pci_enum_ctx *ctx = enum_ctx;
|
||||
struct pci_device *pci_dev = pdev;
|
||||
uint16_t vendor_id = spdk_pci_device_get_vendor_id(pci_dev);
|
||||
uint16_t device_id = spdk_pci_device_get_device_id(pci_dev);
|
||||
|
||||
@ -146,7 +154,7 @@ ioat_pci_enum_cb(void *enum_ctx, void *pdev)
|
||||
}
|
||||
|
||||
static inline int
|
||||
ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx)
|
||||
ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
struct ioat_pci_enum_ctx ioat_enum_ctx;
|
||||
|
||||
@ -156,12 +164,6 @@ ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx
|
||||
return spdk_pci_enumerate(ioat_pci_enum_cb, &ioat_enum_ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#define ioat_pcicfg_read32(handle, var, offset) pci_device_cfg_read_u32(handle, var, offset)
|
||||
#define ioat_pcicfg_write32(handle, var, offset) pci_device_cfg_write_u32(handle, var, offset)
|
||||
|
||||
static inline int
|
||||
ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr)
|
||||
{
|
||||
@ -180,10 +182,7 @@ ioat_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr)
|
||||
return pci_device_unmap_range(dev, addr, dev->regions[bar].size);
|
||||
}
|
||||
|
||||
#else
|
||||
/* var should be the pointer */
|
||||
#define ioat_pcicfg_read32(handle, var, offset) rte_eal_pci_read_config(handle, var, 4, offset)
|
||||
#define ioat_pcicfg_write32(handle, var, offset) rte_eal_pci_write_config(handle, var, 4, offset)
|
||||
#else /* !USE_PCIACCESS */
|
||||
|
||||
static inline int
|
||||
ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr)
|
||||
@ -194,6 +193,7 @@ ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **ma
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: avoid duplicating the device ID list */
|
||||
static struct rte_pci_id ioat_driver_id[] = {
|
||||
{RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB0)},
|
||||
{RTE_PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB1)},
|
||||
@ -244,26 +244,54 @@ static struct rte_pci_id ioat_driver_id[] = {
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
struct ioat_pci_enum_ctx {
|
||||
int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
||||
void *user_enum_ctx;
|
||||
};
|
||||
|
||||
/*
|
||||
* TODO: eliminate this global if possible (does rte_pci_driver have a context field for this?)
|
||||
*
|
||||
* This should be protected by the ioat driver lock, since ioat_probe() holds the lock
|
||||
* the whole time, but we shouldn't have to depend on that.
|
||||
*/
|
||||
static struct ioat_pci_enum_ctx g_ioat_pci_enum_ctx;
|
||||
|
||||
static int
|
||||
ioat_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *rte_dev)
|
||||
{
|
||||
/*
|
||||
* These are actually the same type internally.
|
||||
* TODO: refactor this so it's inside pci.c
|
||||
*/
|
||||
struct spdk_pci_device *pci_dev = (struct spdk_pci_device *)rte_dev;
|
||||
|
||||
return g_ioat_pci_enum_ctx.user_enum_cb(g_ioat_pci_enum_ctx.user_enum_ctx, pci_dev);
|
||||
}
|
||||
|
||||
static struct rte_pci_driver ioat_rte_driver = {
|
||||
.name = "ioat_driver",
|
||||
.devinit = NULL,
|
||||
.devinit = ioat_driver_init,
|
||||
.id_table = ioat_driver_id,
|
||||
.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
|
||||
};
|
||||
|
||||
static inline int
|
||||
ioat_driver_register_dev_init(void *fn_t)
|
||||
ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
int rc;
|
||||
|
||||
ioat_rte_driver.devinit = fn_t;
|
||||
g_ioat_pci_enum_ctx.user_enum_cb = enum_cb;
|
||||
g_ioat_pci_enum_ctx.user_enum_ctx = enum_ctx;
|
||||
|
||||
rte_eal_pci_register(&ioat_rte_driver);
|
||||
rc = rte_eal_pci_probe();
|
||||
rte_eal_pci_unregister(&ioat_rte_driver);
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !USE_PCIACCESS */
|
||||
|
||||
typedef pthread_mutex_t ioat_mutex_t;
|
||||
|
||||
|
@ -259,7 +259,7 @@ struct nvme_enum_ctx {
|
||||
|
||||
/* This function must only be called while holding g_nvme_driver.lock */
|
||||
static int
|
||||
nvme_enum_cb(void *ctx, void *pci_dev)
|
||||
nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct nvme_enum_ctx *enum_ctx = ctx;
|
||||
struct nvme_controller *ctrlr;
|
||||
|
@ -30,7 +30,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <pciaccess.h>
|
||||
|
||||
#include "nvme_internal.h"
|
||||
#include "spdk/pci.h"
|
||||
|
||||
@ -46,7 +46,7 @@ static void
|
||||
nvme_ctrlr_construct_intel_support_log_page_list(struct nvme_controller *ctrlr,
|
||||
struct nvme_intel_log_page_directory *log_page_directory)
|
||||
{
|
||||
struct pci_device *dev;
|
||||
struct spdk_pci_device *dev;
|
||||
struct pci_id pci_id;
|
||||
|
||||
if (ctrlr->cdata.vid != PCI_VENDOR_ID_INTEL || log_page_directory == NULL)
|
||||
|
@ -43,6 +43,12 @@
|
||||
#include <rte_mempool.h>
|
||||
#include <rte_memcpy.h>
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
#include <pciaccess.h>
|
||||
#else
|
||||
#include <rte_pci.h>
|
||||
#endif
|
||||
|
||||
#include "spdk/pci.h"
|
||||
#include "spdk/nvme_spec.h"
|
||||
|
||||
@ -118,17 +124,22 @@ extern struct rte_mempool *request_mempool;
|
||||
*/
|
||||
#define nvme_dealloc_request(buf) rte_mempool_put(request_mempool, buf)
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#define nvme_pcicfg_read32(handle, var, offset) spdk_pci_device_cfg_read32(handle, var, offset)
|
||||
#define nvme_pcicfg_write32(handle, var, offset) spdk_pci_device_cfg_write32(handle, var, offset)
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
struct nvme_pci_enum_ctx {
|
||||
int (*user_enum_cb)(void *enum_ctx, void *pci_dev);
|
||||
int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
||||
void *user_enum_ctx;
|
||||
};
|
||||
|
||||
static int
|
||||
nvme_pci_enum_cb(void *enum_ctx, void *pdev)
|
||||
nvme_pci_enum_cb(void *enum_ctx, struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct nvme_pci_enum_ctx *ctx = enum_ctx;
|
||||
struct pci_device *pci_dev = pdev;
|
||||
|
||||
if (spdk_pci_device_get_class(pci_dev) != NVME_CLASS_CODE) {
|
||||
return 0;
|
||||
@ -138,7 +149,7 @@ nvme_pci_enum_cb(void *enum_ctx, void *pdev)
|
||||
}
|
||||
|
||||
static inline int
|
||||
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx)
|
||||
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
struct nvme_pci_enum_ctx nvme_enum_ctx;
|
||||
|
||||
@ -148,12 +159,6 @@ nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx
|
||||
return spdk_pci_enumerate(nvme_pci_enum_cb, &nvme_enum_ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
#define nvme_pcicfg_read32(handle, var, offset) pci_device_cfg_read_u32(handle, var, offset)
|
||||
#define nvme_pcicfg_write32(handle, var, offset) pci_device_cfg_write_u32(handle, var, offset)
|
||||
|
||||
static inline int
|
||||
nvme_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr)
|
||||
{
|
||||
@ -172,16 +177,13 @@ nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr)
|
||||
return pci_device_unmap_range(dev, addr, dev->regions[bar].size);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* var should be the pointer */
|
||||
#define nvme_pcicfg_read32(handle, var, offset) rte_eal_pci_read_config(handle, var, 4, offset)
|
||||
#define nvme_pcicfg_write32(handle, var, offset) rte_eal_pci_write_config(handle, var, 4, offset)
|
||||
#else /* !USE_PCIACCESS */
|
||||
|
||||
static inline int
|
||||
nvme_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr)
|
||||
{
|
||||
struct rte_pci_device *dev = devhandle;
|
||||
|
||||
*mapped_addr = dev->mem_resource[bar].addr;
|
||||
return 0;
|
||||
}
|
||||
@ -192,23 +194,54 @@ nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: once DPDK supports matching class code instead of device ID, switch to NVME_CLASS_CODE
|
||||
*/
|
||||
static struct rte_pci_id nvme_pci_driver_id[] = {
|
||||
{RTE_PCI_DEVICE(0x8086, 0x0953)},
|
||||
{ .vendor_id = 0, /* sentinel */ },
|
||||
};
|
||||
|
||||
struct nvme_pci_enum_ctx {
|
||||
int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
||||
void *user_enum_ctx;
|
||||
};
|
||||
|
||||
/*
|
||||
* TODO: eliminate this global if possible (does rte_pci_driver have a context field for this?)
|
||||
*
|
||||
* This should be protected by the NVMe driver lock, since nvme_probe() holds the lock
|
||||
* while calling nvme_pci_enumerate(), but we shouldn't have to depend on that.
|
||||
*/
|
||||
static struct nvme_pci_enum_ctx g_nvme_pci_enum_ctx;
|
||||
|
||||
static int
|
||||
nvme_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *rte_dev)
|
||||
{
|
||||
/*
|
||||
* These are actually the same type internally.
|
||||
* TODO: refactor this so it's inside pci.c
|
||||
*/
|
||||
struct spdk_pci_device *pci_dev = (struct spdk_pci_device *)rte_dev;
|
||||
|
||||
return g_nvme_pci_enum_ctx.user_enum_cb(g_nvme_pci_enum_ctx.user_enum_ctx, pci_dev);
|
||||
}
|
||||
|
||||
static struct rte_pci_driver nvme_rte_driver = {
|
||||
.name = "nvme_driver",
|
||||
.devinit = NULL,
|
||||
.devinit = nvme_driver_init,
|
||||
.id_table = nvme_pci_driver_id,
|
||||
.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
|
||||
};
|
||||
|
||||
static inline int nvme_driver_register_dev_init(pci_driver_init fn_t)
|
||||
static inline int
|
||||
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
int rc;
|
||||
|
||||
nvme_rte_driver.devinit = fn_t;
|
||||
g_nvme_pci_enum_ctx.user_enum_cb = enum_cb;
|
||||
g_nvme_pci_enum_ctx.user_enum_ctx = enum_ctx;
|
||||
|
||||
rte_eal_pci_register(&nvme_rte_driver);
|
||||
rc = rte_eal_pci_probe();
|
||||
rte_eal_pci_unregister(&nvme_rte_driver);
|
||||
|
@ -318,7 +318,7 @@ struct nvme_controller {
|
||||
bool feature_supported[256];
|
||||
|
||||
/* Opaque handle to associated PCI device. */
|
||||
void *devhandle;
|
||||
struct spdk_pci_device *devhandle;
|
||||
|
||||
uint32_t num_io_queues;
|
||||
|
||||
|
305
lib/util/pci.c
305
lib/util/pci.c
@ -40,6 +40,18 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
#include <pciaccess.h>
|
||||
/* When using libpciaccess, struct spdk_pci_device * is actually struct pci_device * internally. */
|
||||
#define spdk_pci_device pci_device
|
||||
#else
|
||||
#include <rte_pci.h>
|
||||
/* When using DPDK PCI, struct spdk_pci_device * is actually struct rte_pci_device * internally. */
|
||||
#define spdk_pci_device rte_pci_device
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/pciio.h>
|
||||
@ -49,61 +61,132 @@
|
||||
|
||||
#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
|
||||
#define SYSFS_PCI_DRIVERS "/sys/bus/pci/drivers"
|
||||
|
||||
#ifndef PCI_PRI_FMT /* This is defined by rte_pci.h when USE_PCIACCESS is not set */
|
||||
#define PCI_PRI_FMT "%04x:%02x:%02x.%1u"
|
||||
#endif
|
||||
|
||||
#define SPDK_PCI_PATH_MAX 256
|
||||
#define PCI_CFG_SIZE 256
|
||||
#define PCI_EXT_CAP_ID_SN 0x03
|
||||
#define PCI_UIO_DRIVER "uio_pci_generic"
|
||||
|
||||
#ifdef USE_PCIACCESS
|
||||
#define PCI_PRI_FMT "%04x:%02x:%02x.%1u"
|
||||
/* var should be the pointer */
|
||||
#define spdk_pcicfg_read32(handle, var, offset) pci_device_cfg_read_u32(handle, var, offset)
|
||||
#define spdk_pcicfg_write32(handle, var, offset) pci_device_cfg_write_u32(handle, *var, offset)
|
||||
#else
|
||||
/* var should be the pointer */
|
||||
#define spdk_pcicfg_read32(handle, var, offset) rte_eal_pci_read_config(handle, var, 4, offset)
|
||||
#define spdk_pcicfg_write32(handle, var, offset) rte_eal_pci_write_config(handle, var, 4, offset)
|
||||
#endif
|
||||
|
||||
#ifndef USE_PCIACCESS
|
||||
static int pci_device_get_info(struct pci_device *dev, const char *file, uint32_t *val)
|
||||
/*
|
||||
* libpciaccess wrapper functions
|
||||
*/
|
||||
|
||||
static pthread_mutex_t g_pci_init_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static bool g_pci_initialized = false;
|
||||
|
||||
static int
|
||||
spdk_pci_init(void)
|
||||
{
|
||||
char filename[SPDK_PCI_PATH_MAX];
|
||||
FILE *fd;
|
||||
char buf[10];
|
||||
char *end = NULL;
|
||||
int rc;
|
||||
|
||||
snprintf(filename, sizeof(filename),
|
||||
SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/%s",
|
||||
spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev),
|
||||
spdk_pci_device_get_dev(dev), spdk_pci_device_get_func(dev), file);
|
||||
pthread_mutex_lock(&g_pci_init_mutex);
|
||||
|
||||
fd = fopen(filename, "r");
|
||||
if (!fd)
|
||||
return -1;
|
||||
|
||||
if (fgets(buf, sizeof(buf), fd) == NULL) {
|
||||
fclose(fd);
|
||||
return -1;
|
||||
if (!g_pci_initialized) {
|
||||
rc = pci_system_init();
|
||||
if (rc == 0) {
|
||||
g_pci_initialized = true;
|
||||
}
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
*val = strtoul(buf, &end, 0);
|
||||
if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
|
||||
fclose(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
pthread_mutex_unlock(&g_pci_init_mutex);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_domain(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->domain;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_bus(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->bus;
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_dev(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->dev;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_func(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->func;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->vendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_device_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->device_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->subvendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->subdevice_id;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_pci_device_get_class(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->device_class;
|
||||
}
|
||||
|
||||
const char *
|
||||
spdk_pci_device_get_device_name(struct spdk_pci_device *dev)
|
||||
{
|
||||
return pci_device_get_device_name(dev);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx)
|
||||
spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset)
|
||||
{
|
||||
return pci_device_cfg_read_u32(dev, value, offset);
|
||||
}
|
||||
|
||||
int
|
||||
spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset)
|
||||
{
|
||||
return pci_device_cfg_write_u32(dev, value, offset);
|
||||
}
|
||||
|
||||
int
|
||||
spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
struct pci_device_iterator *pci_dev_iter;
|
||||
struct pci_device *pci_dev;
|
||||
struct pci_slot_match match;
|
||||
int rc;
|
||||
|
||||
rc = spdk_pci_init();
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
match.domain = PCI_MATCH_ANY;
|
||||
match.bus = PCI_MATCH_ANY;
|
||||
match.dev = PCI_MATCH_ANY;
|
||||
@ -124,8 +207,130 @@ spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx
|
||||
return rc;
|
||||
}
|
||||
|
||||
#else /* !USE_PCIACCESS */
|
||||
|
||||
/*
|
||||
* DPDK PCI wrapper functions
|
||||
*/
|
||||
|
||||
static int
|
||||
pci_device_get_u32(struct spdk_pci_device *dev, const char *file, uint32_t *val)
|
||||
{
|
||||
char filename[SPDK_PCI_PATH_MAX];
|
||||
FILE *fd;
|
||||
char buf[10];
|
||||
char *end;
|
||||
|
||||
snprintf(filename, sizeof(filename),
|
||||
SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/%s",
|
||||
spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev),
|
||||
spdk_pci_device_get_dev(dev), spdk_pci_device_get_func(dev), file);
|
||||
|
||||
fd = fopen(filename, "r");
|
||||
if (!fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fgets(buf, sizeof(buf), fd) == NULL) {
|
||||
fclose(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*val = strtoul(buf, &end, 0);
|
||||
if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
|
||||
fclose(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_domain(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->addr.domain;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_bus(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->addr.bus;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_dev(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->addr.devid;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
spdk_pci_device_get_func(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->addr.function;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->id.vendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_device_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->id.device_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->id.subsystem_vendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return dev->id.subsystem_device_id;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
spdk_pci_device_get_class(struct spdk_pci_device *dev)
|
||||
{
|
||||
uint32_t class_code;
|
||||
|
||||
if (pci_device_get_u32(dev, "class", &class_code) < 0) {
|
||||
return 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
return class_code;
|
||||
}
|
||||
|
||||
const char *
|
||||
spdk_pci_device_get_device_name(struct spdk_pci_device *dev)
|
||||
{
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
||||
spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset)
|
||||
{
|
||||
return rte_eal_pci_read_config(dev, value, 4, offset) == 4 ? 0 : -1;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset)
|
||||
{
|
||||
return rte_eal_pci_write_config(dev, &value, 4, offset) == 4 ? 0 : -1;
|
||||
}
|
||||
|
||||
#endif /* !USE_PCIACCESS */
|
||||
|
||||
|
||||
int
|
||||
spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len)
|
||||
{
|
||||
int err;
|
||||
uint32_t pos, header = 0;
|
||||
@ -134,7 +339,7 @@ pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
||||
if (len < 17)
|
||||
return -1;
|
||||
|
||||
err = spdk_pcicfg_read32(dev, &header, PCI_CFG_SIZE);
|
||||
err = spdk_pci_device_cfg_read32(dev, &header, PCI_CFG_SIZE);
|
||||
if (err || !header)
|
||||
return -1;
|
||||
|
||||
@ -145,8 +350,7 @@ pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
||||
/*skip the header*/
|
||||
pos += 4;
|
||||
for (i = 0; i < 2; i++) {
|
||||
err = spdk_pcicfg_read32(dev,
|
||||
&buf[i], pos + 4 * i);
|
||||
err = spdk_pci_device_cfg_read32(dev, &buf[i], pos + 4 * i);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
@ -158,7 +362,7 @@ pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
||||
/*0 if no other items exist*/
|
||||
if (pos < PCI_CFG_SIZE)
|
||||
return -1;
|
||||
err = spdk_pcicfg_read32(dev, &header, pos);
|
||||
err = spdk_pci_device_cfg_read32(dev, &header, pos);
|
||||
if (err)
|
||||
return -1;
|
||||
}
|
||||
@ -167,7 +371,7 @@ pci_device_get_serial_number(struct pci_device *dev, char *sn, int len)
|
||||
|
||||
#ifdef __linux__
|
||||
int
|
||||
pci_device_has_non_uio_driver(struct pci_device *dev)
|
||||
spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev)
|
||||
{
|
||||
char linkname[SPDK_PCI_PATH_MAX];
|
||||
char driver[SPDK_PCI_PATH_MAX];
|
||||
@ -202,7 +406,7 @@ pci_device_has_non_uio_driver(struct pci_device *dev)
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
int
|
||||
pci_device_has_non_uio_driver(struct pci_device *dev)
|
||||
spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev)
|
||||
{
|
||||
struct pci_conf_io configsel;
|
||||
struct pci_match_conf pattern;
|
||||
@ -254,7 +458,7 @@ pci_device_has_non_uio_driver(struct pci_device *dev)
|
||||
#endif
|
||||
|
||||
int
|
||||
pci_device_unbind_kernel_driver(struct pci_device *dev)
|
||||
spdk_pci_device_unbind_kernel_driver(struct spdk_pci_device *dev)
|
||||
{
|
||||
int n;
|
||||
FILE *fd;
|
||||
@ -286,7 +490,7 @@ error:
|
||||
}
|
||||
|
||||
static int
|
||||
check_modules(char *driver_name)
|
||||
check_modules(const char *driver_name)
|
||||
{
|
||||
FILE *fd;
|
||||
const char *proc_modules = "/proc/modules";
|
||||
@ -310,12 +514,13 @@ check_modules(char *driver_name)
|
||||
}
|
||||
|
||||
int
|
||||
pci_device_bind_uio_driver(struct pci_device *dev, char *driver_name)
|
||||
spdk_pci_device_bind_uio_driver(struct spdk_pci_device *dev)
|
||||
{
|
||||
int err, n;
|
||||
FILE *fd;
|
||||
char filename[SPDK_PCI_PATH_MAX];
|
||||
char buf[256];
|
||||
const char *driver_name = PCI_UIO_DRIVER;
|
||||
|
||||
err = check_modules(driver_name);
|
||||
if (err < 0) {
|
||||
@ -347,9 +552,9 @@ error:
|
||||
}
|
||||
|
||||
int
|
||||
pci_device_switch_to_uio_driver(struct pci_device *dev)
|
||||
spdk_pci_device_switch_to_uio_driver(struct spdk_pci_device *dev)
|
||||
{
|
||||
if (pci_device_unbind_kernel_driver(dev)) {
|
||||
if (spdk_pci_device_unbind_kernel_driver(dev)) {
|
||||
fprintf(stderr, "Device %d:%d:%d unbind from "
|
||||
"kernel driver failed\n",
|
||||
spdk_pci_device_get_bus(dev),
|
||||
@ -357,7 +562,7 @@ pci_device_switch_to_uio_driver(struct pci_device *dev)
|
||||
spdk_pci_device_get_func(dev));
|
||||
return -1;
|
||||
}
|
||||
if (pci_device_bind_uio_driver(dev, PCI_UIO_DRIVER)) {
|
||||
if (spdk_pci_device_bind_uio_driver(dev)) {
|
||||
fprintf(stderr, "Device %d:%d:%d bind to "
|
||||
"uio driver failed\n",
|
||||
spdk_pci_device_get_bus(dev),
|
||||
@ -372,7 +577,7 @@ pci_device_switch_to_uio_driver(struct pci_device *dev)
|
||||
}
|
||||
|
||||
int
|
||||
pci_device_claim(struct pci_device *dev)
|
||||
spdk_pci_device_claim(struct spdk_pci_device *dev)
|
||||
{
|
||||
int dev_fd;
|
||||
char shm_name[64];
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct spdk_pci_device;
|
||||
|
||||
static inline void *
|
||||
ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
||||
{
|
||||
@ -26,7 +28,7 @@ ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
||||
#define ioat_printf(chan, fmt, args...) printf(fmt, ##args)
|
||||
|
||||
static inline int
|
||||
ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx)
|
||||
ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -33,8 +33,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <pciaccess.h>
|
||||
|
||||
#include <rte_config.h>
|
||||
#include <rte_malloc.h>
|
||||
#include <rte_mempool.h>
|
||||
@ -48,7 +46,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;
|
||||
struct nvme_health_information_page *health_page;
|
||||
uint32_t orig_temp_threshold;
|
||||
@ -190,11 +188,9 @@ static void aer_cb(void *arg, const struct nvme_completion *cpl)
|
||||
|
||||
|
||||
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),
|
||||
@ -215,10 +211,9 @@ probe_cb(void *cb_ctx, void *pci_dev)
|
||||
}
|
||||
|
||||
static void
|
||||
attach_cb(void *cb_ctx, void *pdev, struct nvme_controller *ctrlr)
|
||||
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
|
||||
{
|
||||
struct dev *dev;
|
||||
struct pci_device *pci_dev = pdev;
|
||||
|
||||
/* add to dev list */
|
||||
dev = &devs[num_devs++];
|
||||
@ -227,7 +222,8 @@ attach_cb(void *cb_ctx, void *pdev, struct nvme_controller *ctrlr)
|
||||
dev->pci_dev = pci_dev;
|
||||
|
||||
snprintf(dev->name, sizeof(dev->name), "%04x:%02x:%02x.%02x",
|
||||
pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
|
||||
spdk_pci_device_get_domain(pci_dev), spdk_pci_device_get_bus(pci_dev),
|
||||
spdk_pci_device_get_dev(pci_dev), spdk_pci_device_get_func(pci_dev));
|
||||
|
||||
printf("Attached to %s\n", dev->name);
|
||||
|
||||
@ -269,8 +265,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;
|
||||
|
@ -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>
|
||||
@ -505,11 +503,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),
|
||||
@ -524,7 +520,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)
|
||||
{
|
||||
register_ctrlr(ctrlr);
|
||||
}
|
||||
@ -534,8 +530,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;
|
||||
|
@ -36,8 +36,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/uio.h> /* for struct iovec */
|
||||
|
||||
#include <pciaccess.h>
|
||||
|
||||
#include <rte_config.h>
|
||||
#include <rte_malloc.h>
|
||||
#include <rte_mempool.h>
|
||||
@ -57,7 +55,7 @@ struct rte_mempool *request_mempool;
|
||||
#define BASE_LBA_START 0x100000
|
||||
|
||||
struct dev {
|
||||
struct pci_device *pci_dev;
|
||||
struct spdk_pci_device *pci_dev;
|
||||
struct nvme_controller *ctrlr;
|
||||
char name[100];
|
||||
};
|
||||
@ -372,11 +370,9 @@ writev_readv_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn)
|
||||
}
|
||||
|
||||
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),
|
||||
@ -397,10 +393,9 @@ probe_cb(void *cb_ctx, void *pci_dev)
|
||||
}
|
||||
|
||||
static void
|
||||
attach_cb(void *cb_ctx, void *pdev, struct nvme_controller *ctrlr)
|
||||
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct nvme_controller *ctrlr)
|
||||
{
|
||||
struct dev *dev;
|
||||
struct pci_device *pci_dev = pdev;
|
||||
|
||||
/* add to dev list */
|
||||
dev = &devs[num_devs++];
|
||||
@ -449,8 +444,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");
|
||||
exit(1);
|
||||
|
@ -40,10 +40,39 @@ struct nvme_driver g_nvme_driver = {
|
||||
.max_io_queues = DEFAULT_MAX_IO_QUEUES
|
||||
};
|
||||
|
||||
static uint16_t g_pci_vendor_id;
|
||||
static uint16_t g_pci_device_id;
|
||||
static uint16_t g_pci_subvendor_id;
|
||||
static uint16_t g_pci_subdevice_id;
|
||||
|
||||
char outbuf[OUTBUF_SIZE];
|
||||
|
||||
__thread int nvme_thread_ioq_index = -1;
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return g_pci_vendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_device_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return g_pci_device_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return g_pci_subvendor_id;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev)
|
||||
{
|
||||
return g_pci_subdevice_id;
|
||||
}
|
||||
|
||||
int nvme_qpair_construct(struct nvme_qpair *qpair, uint16_t id,
|
||||
uint16_t num_entries, uint16_t num_trackers,
|
||||
struct nvme_controller *ctrlr)
|
||||
@ -201,10 +230,9 @@ test_nvme_ctrlr_construct_intel_support_log_page_list(void)
|
||||
bool res;
|
||||
struct nvme_controller ctrlr = {};
|
||||
struct nvme_intel_log_page_directory payload = {};
|
||||
struct pci_device device = {};
|
||||
|
||||
/* set a invalid vendor id */
|
||||
ctrlr.cdata.vid = 0xFFFF;
|
||||
ctrlr.devhandle = &device;
|
||||
|
||||
nvme_ctrlr_construct_intel_support_log_page_list(&ctrlr, &payload);
|
||||
res = nvme_ctrlr_is_log_page_supported(&ctrlr, NVME_INTEL_LOG_TEMPERATURE);
|
||||
@ -228,10 +256,10 @@ test_nvme_ctrlr_construct_intel_support_log_page_list(void)
|
||||
/* set valid vendor id, device id and sub device id*/
|
||||
ctrlr.cdata.vid = PCI_VENDOR_ID_INTEL;
|
||||
payload.temperature_statistics_log_len = 0;
|
||||
device.vendor_id = PCI_VENDOR_ID_INTEL;
|
||||
device.device_id = 0x0953;
|
||||
device.subvendor_id = PCI_VENDOR_ID_INTEL;
|
||||
device.subdevice_id = 0x3702;
|
||||
g_pci_vendor_id = PCI_VENDOR_ID_INTEL;
|
||||
g_pci_device_id = 0x0953;
|
||||
g_pci_subvendor_id = PCI_VENDOR_ID_INTEL;
|
||||
g_pci_subdevice_id = 0x3702;
|
||||
memset(ctrlr.log_page_supported, 0, sizeof(ctrlr.log_page_supported));
|
||||
|
||||
nvme_ctrlr_construct_intel_support_log_page_list(&ctrlr, &payload);
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
|
||||
struct spdk_pci_device;
|
||||
|
||||
static inline void *
|
||||
nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
||||
{
|
||||
@ -77,7 +79,7 @@ do \
|
||||
#define nvme_dealloc_request(buf) free(buf)
|
||||
|
||||
static inline int
|
||||
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx)
|
||||
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
||||
{
|
||||
/* TODO: enumeration is not needed in any unit tests yet, so it's not implemented */
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user