From e15bd007119cefb3ce5c56358e69ab08c14f98ab Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Mon, 17 Apr 2017 10:01:55 +0800 Subject: [PATCH] nvme: support new format in spdk_pci_addr_parse The new format is: domain.bus.device.function For this format, since we use '.' as separator, to avoid misusing, we only support the following: 1 domain.bus.device.function ( 4 values provided) 2 bus.device.function (3 values provoided with domain = 0) 3 bus.device (2 values provided with domain = 0, function = 0) Change-Id: Ide03db38b4ac7802cf36f0e536e8b997101d6cd3 Signed-off-by: Ziye Yang --- include/spdk/env.h | 3 ++- include/spdk/nvme.h | 2 +- lib/env_dpdk/pci.c | 9 ++++++--- test/lib/test_env.c | 9 ++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index f50499cc5..b164ffcfc 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -291,7 +291,8 @@ int spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_ * Convert a string representation of a PCI address into a struct spdk_pci_addr. * * \param addr PCI adddress output on success - * \param bdf PCI address in domain:bus:device.function format + * \param bdf PCI address in domain:bus:device.function format or + * domain.bus.device.function format * * \return 0 on success, or a negated errno value on failure. */ diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 79958ec62..73ab523ec 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -166,7 +166,7 @@ struct spdk_nvme_transport_id { * Transport address of the NVMe-oF endpoint. For transports which use IP * addressing (e.g. RDMA), this should be an IP address. For PCIe, this * can either be a zero length string (the whole bus) or a PCI address - * in the format DDDD:BB:DD.FF + * in the format DDDD:BB:DD.FF or DDDD.BB.DD.FF */ char traddr[SPDK_NVMF_TRADDR_MAX_LEN + 1]; diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index acad241c7..9259b99d1 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -461,13 +461,16 @@ spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf) return -EINVAL; } - if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) { + if ((sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) || + (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) { + } else if ((sscanf(bdf, "%x:%x.%x", &bus, &dev, &func) == 3) || + (sscanf(bdf, "%x.%x.%x", &bus, &dev, &func) == 3)) { domain = 0; - } else if (sscanf(bdf, "%x:%x", &bus, &dev) == 2) { + } else if ((sscanf(bdf, "%x:%x", &bus, &dev) == 2) || + (sscanf(bdf, "%x.%x", &bus, &dev) == 2)) { domain = 0; func = 0; } else { diff --git a/test/lib/test_env.c b/test/lib/test_env.c index 74950421b..8b1a1b59c 100644 --- a/test/lib/test_env.c +++ b/test/lib/test_env.c @@ -171,13 +171,16 @@ spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf) return -EINVAL; } - if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) { + if ((sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) || + (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) { + } else if ((sscanf(bdf, "%x:%x.%x", &bus, &dev, &func) == 3) || + (sscanf(bdf, "%x.%x.%x", &bus, &dev, &func) == 3)) { domain = 0; - } else if (sscanf(bdf, "%x:%x", &bus, &dev) == 2) { + } else if ((sscanf(bdf, "%x:%x", &bus, &dev) == 2) || + (sscanf(bdf, "%x.%x", &bus, &dev) == 2)) { domain = 0; func = 0; } else {