From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH v7 15/22] bus/pci: add device matching field id Date: Sun, 15 Apr 2018 17:07:44 +0200 Message-ID: References: Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id CD0D11B648 for ; Sun, 15 Apr 2018 17:08:30 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id w3so2669343wrg.2 for ; Sun, 15 Apr 2018 08:08:30 -0700 (PDT) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The PCI bus can now parse a matching field "id" as follows: "bus=pci,id=0000:00:00.0" or "bus=pci,id=00:00.0" Signed-off-by: Gaetan Rivet --- drivers/bus/pci/pci_common.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index bd9ecddc6..3666e4caa 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -499,21 +499,45 @@ pci_unplug(struct rte_device *dev) } enum pci_params { + RTE_PCI_PARAMS_ID, RTE_PCI_PARAMS_MAX, }; static const char * const pci_params_keys[] = { + [RTE_PCI_PARAMS_ID] = "id", [RTE_PCI_PARAMS_MAX] = NULL, }; static int +pci_addr_kv_cmp(const char *key __rte_unused, + const char *value, + void *_addr2) +{ + struct rte_pci_addr _addr1; + struct rte_pci_addr *addr1 = &_addr1; + struct rte_pci_addr *addr2 = _addr2; + + if (rte_pci_addr_parse(value, addr1)) + return -1; + return rte_pci_addr_cmp(addr1, addr2); +} + +static int pci_dev_match(const struct rte_device *dev, const void *_kvlist) { const struct rte_kvargs *kvlist = _kvlist; + const struct rte_pci_device *pdev; - (void) dev; - (void) kvlist; + if (kvlist == NULL) + /* Empty string matches everything. */ + return 0; + pdev = RTE_DEV_TO_PCI_CONST(dev); + /* if any field does not match. */ + if (rte_kvargs_process(kvlist, "id", + &pci_addr_kv_cmp, + (void *)(intptr_t)&pdev->addr)) + return 1; return 0; } -- 2.11.0