From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9A0A7A00C5; Thu, 28 Jul 2022 17:29:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC47D42C25; Thu, 28 Jul 2022 17:28:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 89BBE42BEB for ; Thu, 28 Jul 2022 17:28:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659022138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wwiWLIlIVpKZCU5FAI9ovzPmJIQwdFpy73PhuRXOIHU=; b=evJ/z/qwoskMjY96rZspBP4LxSXCChjWRKv68BfXmbwgwXxu4l4DOZTlq6gltIGVC/cHGp uwjVDkBwjqCNtgVVpSV0G5rTal/16+iLqOZD/wKQxIDsgjJ8HS2AXw+a05EY/IEQw5ffAn 6hQe89WL+WHa8UyEKdPrJmkfBfkTC/4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-Dmdhtv4AMSq9a8WLRohviw-1; Thu, 28 Jul 2022 11:28:54 -0400 X-MC-Unique: Dmdhtv4AMSq9a8WLRohviw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6F1F93C1014D; Thu, 28 Jul 2022 15:28:54 +0000 (UTC) Received: from fchome.redhat.com (unknown [10.40.195.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81FC11415121; Thu, 28 Jul 2022 15:28:53 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Aman Singh , Yuying Zhang , Ray Kinsella Subject: [RFC v3 25/26] dev: provide Bus specific information Date: Thu, 28 Jul 2022 17:26:39 +0200 Message-Id: <20220728152640.547725-26-david.marchand@redhat.com> In-Reply-To: <20220728152640.547725-1-david.marchand@redhat.com> References: <20220628144643.1213026-1-david.marchand@redhat.com> <20220728152640.547725-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org For diagnostic, it may be useful to provide a description of the device with Bus specific information like, for PCI, the vendor and device ID. Signed-off-by: David Marchand --- app/test-pmd/config.c | 2 ++ drivers/bus/pci/bsd/pci.c | 8 ++++---- drivers/bus/pci/bus_pci_driver.h | 1 + drivers/bus/pci/linux/pci.c | 24 ++++++++++++------------ drivers/bus/pci/pci_common.c | 17 +++++++++++++++-- drivers/bus/pci/private.h | 10 ++++++++-- drivers/bus/pci/windows/pci.c | 6 +++--- lib/eal/common/eal_common_dev.c | 6 ++++++ lib/eal/include/rte_dev.h | 16 ++++++++++++++++ lib/eal/version.map | 1 + 10 files changed, 68 insertions(+), 23 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index de74690f06..d3e1714af5 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -654,6 +654,8 @@ device_infos_display(const char *identifier) printf("\n%s Infos for device %s %s\n", info_border, rte_dev_name(dev), info_border); printf("Bus name: %s", rte_bus_name(rte_dev_bus(dev))); + printf("\nBus information: %s", + rte_dev_bus_info(dev) ? rte_dev_bus_info(dev) : ""); printf("\nDriver name: %s", rte_driver_name(rte_dev_driver(dev))); printf("\nDevargs: %s", rte_dev_devargs(dev) ? rte_dev_devargs(dev)->args : ""); diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index bc560a2a56..844d145fed 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -248,7 +248,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) /* FreeBSD has no NUMA support (yet) */ dev->device.numa_node = 0; - pci_name_set(dev); + pci_common_set(dev); /* FreeBSD has only one pass through driver */ dev->kdrv = RTE_PCI_KDRV_NIC_UIO; @@ -299,11 +299,11 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) } else { /* already registered */ dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; - pci_name_set(dev2); + pci_common_set(dev2); memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); - free(dev); + pci_free(dev); } return 0; } @@ -313,7 +313,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) return 0; skipdev: - free(dev); + pci_free(dev); return 0; } diff --git a/drivers/bus/pci/bus_pci_driver.h b/drivers/bus/pci/bus_pci_driver.h index 0f2f9b5101..be32263a82 100644 --- a/drivers/bus/pci/bus_pci_driver.h +++ b/drivers/bus/pci/bus_pci_driver.h @@ -43,6 +43,7 @@ struct rte_pci_device { uint16_t max_vfs; /**< sriov enable if not zero */ enum rte_pci_kernel_driver kdrv; /**< Kernel driver passthrough */ char name[PCI_PRI_STR_SIZE+1]; /**< PCI location (ASCII) */ + char *bus_info; /**< PCI bus specific info */ struct rte_intr_handle *vfio_req_intr_handle; /**< Handler of VFIO request interrupt */ }; diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index fa5d5e131d..c8703d52f3 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -226,7 +226,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) /* get vendor id */ snprintf(filename, sizeof(filename), "%s/vendor", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.vendor_id = (uint16_t)tmp; @@ -234,7 +234,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) /* get device id */ snprintf(filename, sizeof(filename), "%s/device", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.device_id = (uint16_t)tmp; @@ -243,7 +243,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/subsystem_vendor", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.subsystem_vendor_id = (uint16_t)tmp; @@ -252,7 +252,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/subsystem_device", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } dev->id.subsystem_device_id = (uint16_t)tmp; @@ -261,7 +261,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) snprintf(filename, sizeof(filename), "%s/class", dirname); if (eal_parse_sysfs_value(filename, &tmp) < 0) { - free(dev); + pci_free(dev); return -1; } /* the least 24 bits are valid: class, subclass, program interface */ @@ -295,13 +295,13 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev->device.numa_node = 0; } - pci_name_set(dev); + pci_common_set(dev); /* parse resources */ snprintf(filename, sizeof(filename), "%s/resource", dirname); if (pci_parse_sysfs_resource(filename, dev) < 0) { RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__); - free(dev); + pci_free(dev); return -1; } @@ -310,7 +310,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) ret = pci_get_kernel_driver_by_path(filename, driver, sizeof(driver)); if (ret < 0) { RTE_LOG(ERR, EAL, "Fail to get kernel driver\n"); - free(dev); + pci_free(dev); return -1; } @@ -324,7 +324,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) else dev->kdrv = RTE_PCI_KDRV_UNKNOWN; } else { - free(dev); + pci_free(dev); return 0; } /* device is valid, add in list (sorted) */ @@ -346,7 +346,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev2->kdrv = dev->kdrv; dev2->max_vfs = dev->max_vfs; dev2->id = dev->id; - pci_name_set(dev2); + pci_common_set(dev2); memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); @@ -376,10 +376,10 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) else if (dev2->device.devargs != dev->device.devargs) { rte_devargs_remove(dev2->device.devargs); - pci_name_set(dev2); + pci_common_set(dev2); } } - free(dev); + pci_free(dev); } return 0; } diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index c26aacd364..0f344d46aa 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -59,7 +59,7 @@ pci_devargs_lookup(const struct rte_pci_addr *pci_addr) } void -pci_name_set(struct rte_pci_device *dev) +pci_common_set(struct rte_pci_device *dev) { struct rte_devargs *devargs; @@ -80,6 +80,19 @@ pci_name_set(struct rte_pci_device *dev) else /* Otherwise, it uses the internal, canonical form. */ dev->device.name = dev->name; + + if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, + dev->id.vendor_id, dev->id.device_id) != -1) + dev->device.bus_info = dev->bus_info; +} + +void +pci_free(struct rte_pci_device *dev) +{ + if (dev == NULL) + return; + free(dev->bus_info); + free(dev); } /* map a particular resource from a file */ @@ -604,7 +617,7 @@ pci_unplug(struct rte_device *dev) if (ret == 0) { rte_pci_remove_device(pdev); rte_devargs_remove(dev->devargs); - free(pdev); + pci_free(pdev); } return ret; } diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index fddf49251d..c8161a1074 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -44,10 +44,16 @@ struct rte_pci_device; int rte_pci_scan(void); /** - * Find the name of a PCI device. + * Set common internal information for a PCI device. */ void -pci_name_set(struct rte_pci_device *dev); +pci_common_set(struct rte_pci_device *dev); + +/** + * Free a PCI device. + */ +void +pci_free(struct rte_pci_device *dev); /** * Validate whether a device with given PCI address should be ignored or not. diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c index f013b743b3..3f7a8b9432 100644 --- a/drivers/bus/pci/windows/pci.c +++ b/drivers/bus/pci/windows/pci.c @@ -382,7 +382,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) dev->id = pci_id; dev->max_vfs = 0; /* TODO: get max_vfs */ - pci_name_set(dev); + pci_common_set(dev); set_kernel_driver_type(device_info_data, dev); @@ -410,7 +410,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) dev2->max_vfs = dev->max_vfs; memmove(dev2->mem_resource, dev->mem_resource, sizeof(dev->mem_resource)); - free(dev); + pci_free(dev); } return 0; } @@ -419,7 +419,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) return 0; end: - free(dev); + pci_free(dev); return ret; } diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c index 7b12d6e531..a190bd37af 100644 --- a/lib/eal/common/eal_common_dev.c +++ b/lib/eal/common/eal_common_dev.c @@ -31,6 +31,12 @@ rte_dev_bus(const struct rte_device *dev) return dev->bus; } +const char * +rte_dev_bus_info(const struct rte_device *dev) +{ + return dev->bus_info; +} + const struct rte_devargs * rte_dev_devargs(const struct rte_device *dev) { diff --git a/lib/eal/include/rte_dev.h b/lib/eal/include/rte_dev.h index 5f671a05f7..be8bbe79ee 100644 --- a/lib/eal/include/rte_dev.h +++ b/lib/eal/include/rte_dev.h @@ -84,6 +84,21 @@ __rte_experimental const struct rte_bus * rte_dev_bus(const struct rte_device *dev); +/** + * Retrieve bus specific information for a device. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param dev + * A pointer to a device structure. + * @return + * A string describing this device or NULL if none is available. + */ +__rte_experimental +const char * +rte_dev_bus_info(const struct rte_device *dev); + /** * Retrieve a device arguments. * @@ -156,6 +171,7 @@ rte_dev_numa_node(const struct rte_device *dev); struct rte_device { RTE_TAILQ_ENTRY(rte_device) next; /**< Next device */ const char *name; /**< Device name */ + const char *bus_info; /**< Device bus specific information */ const struct rte_driver *driver; /**< Driver assigned after probing */ const struct rte_bus *bus; /**< Bus handle assigned on scan */ int numa_node; /**< NUMA node connection */ diff --git a/lib/eal/version.map b/lib/eal/version.map index 719789b8d1..0cf321605e 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -427,6 +427,7 @@ EXPERIMENTAL { # added in 22.11 rte_dev_bus; + rte_dev_bus_info; rte_dev_devargs; rte_dev_driver; rte_dev_name; -- 2.36.1