nvme: Remove pci_addr from probe_info

This can be obtained by parsing the traddr.

Change-Id: Idaf35066cbf900c87e771a44934de99fb5420001
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-12-09 14:23:55 -07:00 committed by Daniel Verkamp
parent 9511b2a20b
commit 3da43e64e4
20 changed files with 143 additions and 134 deletions

View File

@ -338,13 +338,18 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
struct spdk_nvmf_probe_ctx *ctx = cb_ctx;
struct spdk_pci_addr pci_addr;
if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) {
return false;
}
if (ctx->any && !ctx->found) {
ctx->found = true;
return true;
}
if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->pci_addr) == 0) {
if (spdk_pci_addr_compare(&pci_addr, &ctx->pci_addr) == 0) {
ctx->found = true;
return true;
}
@ -360,20 +365,17 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
int rc;
char path[MAX_STRING_LEN];
int numa_node = -1;
struct spdk_pci_addr pci_addr;
SPDK_NOTICELOG("Attaching NVMe device %p at %x:%x:%x.%x to subsystem %s\n",
spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr);
SPDK_NOTICELOG("Attaching NVMe device %p at %s to subsystem %s\n",
ctrlr,
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func,
probe_info->trid.traddr,
spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem));
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%1u/numa_node",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/numa_node",
probe_info->trid.traddr);
numa_node = spdk_get_numa_node_value(path);
if (numa_node >= 0) {
@ -390,7 +392,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
}
}
rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &probe_info->pci_addr);
rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &pci_addr);
if (rc < 0) {
SPDK_ERRLOG("Failed to add controller to subsystem\n");
}

View File

@ -859,11 +859,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
/* Update with user specified arbitration configuration */
opts->arb_mechanism = g_arbitration.arbitration_mechanism;
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -872,11 +868,7 @@ static void
attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attached to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attached to %s\n", probe_info->trid.traddr);
/* Update with actual arbitration configuration in use */
g_arbitration.arbitration_mechanism = opts->arb_mechanism;

View File

@ -94,6 +94,11 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
unsigned int i;
struct thread_data *td = cb_ctx;
int rc;
struct spdk_pci_addr pci_addr;
if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) {
return false;
}
/* Check if we want to claim this device */
for_each_file(td, f, i) {
@ -103,9 +108,9 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
fprintf(stderr, "Invalid filename: %s\n", f->file_name);
continue;
}
if (bus == probe_info->pci_addr.bus &&
slot == probe_info->pci_addr.dev &&
func == probe_info->pci_addr.func) {
if (bus == pci_addr.bus &&
slot == pci_addr.dev &&
func == pci_addr.func) {
return true;
}
}
@ -123,6 +128,9 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_fio_ns *fio_ns;
struct fio_file *f;
unsigned int i;
struct spdk_pci_addr pci_addr;
spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr);
/* Create an fio_ctrlr and add it to the list */
fio_ctrlr = calloc(1, sizeof(*fio_ctrlr));
@ -137,9 +145,9 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
int domain, bus, slot, func, nsid, rc;
rc = sscanf(f->file_name, "%x.%x.%x.%x/%x", &domain, &bus, &slot, &func, &nsid);
if (rc == 5 &&
bus == probe_info->pci_addr.bus &&
slot == probe_info->pci_addr.dev &&
func == probe_info->pci_addr.func) {
bus == pci_addr.bus &&
slot == pci_addr.dev &&
func == pci_addr.func) {
fio_ns = calloc(1, sizeof(*fio_ns));
if (fio_ns == NULL) {
continue;

View File

@ -241,11 +241,7 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -264,11 +260,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
exit(1);
}
printf("Attached to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attached to %s\n", probe_info->trid.traddr);
snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);

View File

@ -265,11 +265,7 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -278,11 +274,7 @@ static void
attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attached to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attached to %s\n", probe_info->trid.traddr);
register_dev(ctrlr);
}

View File

@ -396,6 +396,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_probe_inf
uint8_t str[512];
uint32_t i;
struct spdk_nvme_error_information_entry *error_entry;
struct spdk_pci_addr pci_addr;
cap = spdk_nvme_ctrlr_get_regs_cap(ctrlr);
vs = spdk_nvme_ctrlr_get_regs_vs(ctrlr);
@ -406,13 +407,17 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_probe_inf
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
printf("=====================================================\n");
if (probe_info->trid.subnqn[0]) {
if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
printf("NVMe over Fabrics controller at %s:%s: %s\n",
probe_info->trid.traddr, probe_info->trid.trsvcid, probe_info->trid.subnqn);
} else {
if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr) != 0) {
return;
}
printf("NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n",
probe_info->pci_addr.domain, probe_info->pci_addr.bus,
probe_info->pci_addr.dev, probe_info->pci_addr.func,
pci_addr.domain, pci_addr.bus,
pci_addr.dev, pci_addr.func,
probe_info->pci_id.vendor_id, probe_info->pci_id.device_id);
}
printf("=====================================================\n");

View File

@ -107,7 +107,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
/* add to dev list */
dev = &devs[num_devs++];
dev->pci_addr = probe_info->pci_addr;
spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr);
dev->ctrlr = ctrlr;
/* Retrieve controller data */

View File

@ -976,14 +976,13 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
if (probe_info->trid.subnqn[0]) {
if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
printf("Attaching to NVMe over Fabrics controller at %s:%s: %s\n",
probe_info->trid.traddr, probe_info->trid.trsvcid,
probe_info->trid.subnqn);
} else {
printf("Attaching to NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n",
probe_info->pci_addr.domain, probe_info->pci_addr.bus,
probe_info->pci_addr.dev, probe_info->pci_addr.func,
printf("Attaching to NVMe Controller at %s [%04x:%04x]\n",
probe_info->trid.traddr,
probe_info->pci_id.vendor_id, probe_info->pci_id.device_id);
}
@ -994,14 +993,13 @@ static void
attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
{
if (probe_info->trid.subnqn[0]) {
if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
printf("Attached to NVMe over Fabrics controller at %s:%s: %s\n",
probe_info->trid.traddr, probe_info->trid.trsvcid,
probe_info->trid.subnqn);
} else {
printf("Attached to NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n",
probe_info->pci_addr.domain, probe_info->pci_addr.bus,
probe_info->pci_addr.dev, probe_info->pci_addr.func,
printf("Attached to NVMe Controller at %s [%04x:%04x]\n",
probe_info->trid.traddr,
probe_info->pci_id.vendor_id, probe_info->pci_id.device_id);
}

View File

@ -376,7 +376,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
/* add to dev list */
dev = &devs[num_devs++];
dev->pci_addr = probe_info->pci_addr;
spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr);
dev->ctrlr = ctrlr;
}

View File

@ -166,13 +166,6 @@ struct spdk_nvme_transport_id {
* NVMe controller information provided during spdk_nvme_probe().
*/
struct spdk_nvme_probe_info {
/**
* PCI address.
*
* If not available, each field will be filled with all 0xFs.
*/
struct spdk_pci_addr pci_addr;
/**
* PCI device ID.
*

View File

@ -413,12 +413,14 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct nvme_probe_ctx *ctx = cb_ctx;
int i;
bool claim_device = false;
struct spdk_pci_addr pci_addr;
SPDK_NOTICELOG("Probing device %x:%x:%x.%x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) {
return false;
}
SPDK_NOTICELOG("Probing device %s\n",
probe_info->trid.traddr);
if (ctx->controllers_remaining == 0) {
return false;
@ -428,7 +430,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
claim_device = true;
} else {
for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {
if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->whitelist[i]) == 0) {
if (spdk_pci_addr_compare(&pci_addr, &ctx->whitelist[i]) == 0) {
claim_device = true;
break;
}
@ -440,7 +442,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
}
/* Claim the device in case conflict with other process */
if (spdk_pci_device_claim(&probe_info->pci_addr) != 0) {
if (spdk_pci_device_claim(&pci_addr) != 0) {
return false;
}
@ -475,7 +477,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
}
dev->ctrlr = ctrlr;
dev->pci_addr = probe_info->pci_addr;
spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr);
dev->id = nvme_controller_index++;
nvme_ctrlr_initialize_blockdevs(dev, nvme_luns_per_ns, dev->id);

View File

@ -476,20 +476,23 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb,
{
struct spdk_nvme_ctrlr *ctrlr;
struct spdk_uevent event;
struct spdk_pci_addr pci_addr;
while (spdk_get_uevent(hotplug_fd, &event) > 0) {
if (event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_UIO) {
if (event.action == SPDK_NVME_UEVENT_ADD) {
SPDK_TRACELOG(SPDK_TRACE_NVME, "add nvme address: %04x:%02x:%02x.%u\n",
event.pci_addr.domain, event.pci_addr.bus, event.pci_addr.dev, event.pci_addr.func);
SPDK_TRACELOG(SPDK_TRACE_NVME, "add nvme address: %s\n",
event.traddr);
if (spdk_process_is_primary()) {
nvme_transport_ctrlr_attach(SPDK_NVME_TRANSPORT_PCIE, probe_cb, cb_ctx, &event.pci_addr);
if (spdk_pci_addr_parse(&pci_addr, event.traddr)) {
nvme_transport_ctrlr_attach(SPDK_NVME_TRANSPORT_PCIE, probe_cb, cb_ctx, &pci_addr);
}
}
} else if (event.action == SPDK_NVME_UEVENT_REMOVE) {
bool in_list = false;
TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) {
if (spdk_pci_addr_compare(&event.pci_addr, &ctrlr->probe_info.pci_addr) == 0) {
if (strcmp(event.traddr, ctrlr->probe_info.trid.traddr) == 0) {
in_list = true;
break;
}
@ -497,8 +500,8 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb,
if (in_list == false) {
return 0;
}
SPDK_TRACELOG(SPDK_TRACE_NVME, "remove nvme address: %04x:%02x:%02x.%u\n",
event.pci_addr.domain, event.pci_addr.bus, event.pci_addr.dev, event.pci_addr.func);
SPDK_TRACELOG(SPDK_TRACE_NVME, "remove nvme address: %s\n",
event.traddr);
nvme_ctrlr_fail(ctrlr, true);

View File

@ -528,9 +528,12 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
struct nvme_pcie_enum_ctx *enum_ctx = ctx;
struct spdk_nvme_ctrlr *ctrlr;
int rc = 0;
struct spdk_pci_addr pci_addr;
pci_addr = spdk_pci_device_get_addr(pci_dev);
probe_info.trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
probe_info.pci_addr = spdk_pci_device_get_addr(pci_dev);
spdk_pci_addr_fmt(probe_info.trid.traddr, sizeof(probe_info.trid.traddr), &pci_addr);
probe_info.pci_id = spdk_pci_device_get_id(pci_dev);
/* Verify that this controller is not already attached */
@ -539,7 +542,7 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
* different per each process, we compare by BDF to determine whether it is the
* same controller.
*/
if (spdk_pci_addr_compare(&probe_info.pci_addr, &ctrlr->probe_info.pci_addr) == 0) {
if (strcmp(probe_info.trid.traddr, ctrlr->probe_info.trid.traddr) == 0) {
if (!spdk_process_is_primary()) {
rc = nvme_ctrlr_add_process(ctrlr, pci_dev);
}

View File

@ -38,6 +38,8 @@
#ifdef __linux__
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@ -48,6 +50,7 @@
#include <linux/netlink.h>
#define SPDK_UEVENT_MSG_LEN 4096
#define TRADDR_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
int
spdk_uevent_connect(void)
@ -138,10 +141,7 @@ parse_event(const char *buf, struct spdk_uevent *event)
if (ret != 4) {
SPDK_ERRLOG("Invalid format for NVMe BDF: %s\n", pci_address);
}
event->pci_addr.domain = domain;
event->pci_addr.bus = bus;
event->pci_addr.dev = dev;
event->pci_addr.func = func;
snprintf(event->traddr, sizeof(event->traddr), TRADDR_FMT, domain, bus, dev, func);
return 1;
}
return -1;

View File

@ -36,6 +36,7 @@
*/
#include "spdk/env.h"
#include "spdk/nvmf_spec.h"
#ifndef SPDK_UEVENT_H_
#define SPDK_UEVENT_H_
@ -50,7 +51,7 @@ enum spdk_nvme_uevent_action {
struct spdk_uevent {
enum spdk_nvme_uevent_action action;
int subsystem;
struct spdk_pci_addr pci_addr;
char traddr[SPDK_NVMF_TRADDR_MAX_LEN + 1];
};
int spdk_uevent_connect(void);

View File

@ -188,11 +188,7 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -208,11 +204,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
dev->ctrlr = ctrlr;
snprintf(dev->name, sizeof(dev->name), "%04x:%02x:%02x.%02x",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
snprintf(dev->name, sizeof(dev->name), "%s",
probe_info->trid.traddr);
printf("Attached to %s\n", dev->name);

View File

@ -609,11 +609,7 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -629,11 +625,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
dev->ctrlr = ctrlr;
snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
snprintf(dev->name, sizeof(dev->name), "%s",
probe_info->trid.traddr);
printf("Attached to %s\n", dev->name);
}

View File

@ -537,20 +537,13 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
if (ctrlr_found == 1) {
fprintf(stderr, "only attching to one controller, so skipping\n");
fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
fprintf(stderr, " controller at PCI address %s\n",
probe_info->trid.traddr);
return false;
}
ctrlr_found = 1;
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -559,11 +552,7 @@ static void
attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attached to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attached to %s\n", probe_info->trid.traddr);
register_ctrlr(ctrlr);
}

View File

@ -383,11 +383,7 @@ static bool
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
printf("Attaching to %04x:%02x:%02x.%02x\n",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
printf("Attaching to %s\n", probe_info->trid.traddr);
return true;
}
@ -403,11 +399,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
dev->ctrlr = ctrlr;
snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X",
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
snprintf(dev->name, sizeof(dev->name), "%s",
probe_info->trid.traddr);
printf("Attached to %s\n", dev->name);
}

View File

@ -145,3 +145,53 @@ uint64_t spdk_get_ticks_hz(void)
{
return 1000000;
}
int
spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf)
{
unsigned domain, bus, dev, func;
if (addr == NULL || bdf == NULL) {
return -EINVAL;
}
if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) {
/* Matched a full address - all variables are initialized */
} else if (sscanf(bdf, "%x:%x:%x", &domain, &bus, &dev) == 3) {
func = 0;
} else if (sscanf(bdf, "%x:%x.%x", &bus, &dev, &func) == 3) {
domain = 0;
} else if (sscanf(bdf, "%x:%x", &bus, &dev) == 2) {
domain = 0;
func = 0;
} else {
return -EINVAL;
}
if (domain > 0xFFFF || bus > 0xFF || dev > 0x1F || func > 7) {
return -EINVAL;
}
addr->domain = domain;
addr->bus = bus;
addr->dev = dev;
addr->func = func;
return 0;
}
int
spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr)
{
int rc;
rc = snprintf(bdf, sz, "%04x:%02x:%02x.%x",
addr->domain, addr->bus,
addr->dev, addr->func);
if (rc > 0 && (size_t)rc < sz) {
return 0;
}
return -1;
}