From 0a573526b6c11ab90e2f194bedfcc63d7a742032 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 13 Jan 2017 14:20:35 +0800 Subject: [PATCH] nvme/pcie: Add the support to probe nvme by pci_addr Currently we use the pci functions provided by DPDK, it identifies the device by class id related info but not by pci bdf info, so we can add the filering by pci_addr in pcie_nvme_enum_cb function. Change-Id: I5942e98853f00fc10fa6aae5c113517653d1b357 Signed-off-by: Ziye Yang --- examples/nvme/identify/identify.c | 12 +++++++++--- lib/nvme/nvme_pcie.c | 17 ++++++++++++++++- test/lib/nvme/nvme.sh | 3 +++ test/lib/nvme/unit/nvme_pcie_c/nvme_pcie_ut.c | 6 ++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 664730069..68a6b5533 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -912,8 +912,6 @@ parse_args(int argc, char **argv) #endif break; case 'a': - g_trid.trtype = SPDK_NVME_TRANSPORT_RDMA; - g_trid.adrfam = SPDK_NVMF_ADRFAM_IPV4; snprintf(g_trid.traddr, sizeof(g_trid.traddr), "%s", optarg); break; case 's': @@ -934,6 +932,9 @@ parse_args(int argc, char **argv) return 0; } + g_trid.trtype = SPDK_NVME_TRANSPORT_RDMA; + g_trid.adrfam = SPDK_NVMF_ADRFAM_IPV4; + optind = 1; return 0; @@ -965,6 +966,7 @@ static const char *ealargs[] = { int main(int argc, char **argv) { int rc; + struct spdk_nvme_transport_id *tr_id = NULL; rc = parse_args(argc, argv); if (rc != 0) { @@ -986,7 +988,11 @@ int main(int argc, char **argv) } } - if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) { + if ((g_trid.trtype == SPDK_NVME_TRANSPORT_PCIE) && (strlen(g_trid.traddr) != 0)) { + tr_id = &g_trid; + } + + if (spdk_nvme_probe(tr_id, NULL, probe_cb, attach_cb, NULL) != 0) { fprintf(stderr, "spdk_nvme_probe() failed\n"); rc = 1; } diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 2f0591e9d..c240a2ab8 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -77,6 +77,8 @@ struct nvme_pcie_enum_ctx { spdk_nvme_probe_cb probe_cb; void *cb_ctx; + struct spdk_pci_addr pci_addr; + bool has_pci_addr; }; /* PCIe transport extensions for spdk_nvme_ctrlr */ @@ -616,6 +618,12 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev) } } + /* check whether user passes the pci_addr */ + if (enum_ctx->has_pci_addr && + (spdk_pci_addr_compare(&pci_addr, &enum_ctx->pci_addr) != 0)) { + return 0; + } + return nvme_ctrlr_probe(&trid, pci_dev, enum_ctx->probe_cb, enum_ctx->cb_ctx); } @@ -626,11 +634,18 @@ nvme_pcie_ctrlr_scan(const struct spdk_nvme_transport_id *trid, spdk_nvme_probe_cb probe_cb, spdk_nvme_remove_cb remove_cb) { - struct nvme_pcie_enum_ctx enum_ctx; + struct nvme_pcie_enum_ctx enum_ctx = {}; enum_ctx.probe_cb = probe_cb; enum_ctx.cb_ctx = cb_ctx; + if (strlen(trid->traddr) != 0) { + if (spdk_pci_addr_parse(&enum_ctx.pci_addr, trid->traddr)) { + return -1; + } + enum_ctx.has_pci_addr = true; + } + if (hotplug_fd < 0) { hotplug_fd = spdk_uevent_connect(); if (hotplug_fd < 0) { diff --git a/test/lib/nvme/nvme.sh b/test/lib/nvme/nvme.sh index 13f9dafa3..49367ec01 100755 --- a/test/lib/nvme/nvme.sh +++ b/test/lib/nvme/nvme.sh @@ -29,6 +29,9 @@ fi timing_enter identify $rootdir/examples/nvme/identify/identify +for bdf in $(linux_iter_pci 0108); do + $rootdir/examples/nvme/identify/identify -a ${bdf} +done timing_exit identify timing_enter perf diff --git a/test/lib/nvme/unit/nvme_pcie_c/nvme_pcie_ut.c b/test/lib/nvme/unit/nvme_pcie_c/nvme_pcie_ut.c index 834cf3eec..61f61fecb 100644 --- a/test/lib/nvme/unit/nvme_pcie_c/nvme_pcie_ut.c +++ b/test/lib/nvme/unit/nvme_pcie_c/nvme_pcie_ut.c @@ -135,6 +135,12 @@ spdk_pci_device_get_addr(struct spdk_pci_device *dev) abort(); } +int +spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_addr *a2) +{ + abort(); +} + int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset) {