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 279D3A054A; Mon, 5 Sep 2022 10:42:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B33B842B90; Mon, 5 Sep 2022 10:41:50 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id AF82942B82 for ; Mon, 5 Sep 2022 10:41:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662367308; 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=sAf7FiQPTmF6Da+qsXUHa5QScUntNgI+FljroTQwYX8=; b=RYuNTD1SDwH/XcRmWIPCjaZUgvhZxElj0fUcEiOTIPYhiff+NnQ+xjWMkEozySazOJqlip CV1h4ZFU/7vjbOoQuC/IkxTkJvo4xeEzEz1sVz7bAal0u7J14jvwBxFdV92azSuzIzuzHk KlRtvCMzB1pNFUyge7cdOdw9lP+qjR0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-zIKIsMhsPWGRNoYNwIto2Q-1; Mon, 05 Sep 2022 04:41:45 -0400 X-MC-Unique: zIKIsMhsPWGRNoYNwIto2Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F0251845D8F; Mon, 5 Sep 2022 08:41:44 +0000 (UTC) Received: from fchome.redhat.com (unknown [10.40.193.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3174CC15BB3; Mon, 5 Sep 2022 08:41:44 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, bruce.richardson@intel.com Subject: [PATCH v5 26/27] bus/pci: fill bus specific information Date: Mon, 5 Sep 2022 10:39:32 +0200 Message-Id: <20220905083933.2506819-27-david.marchand@redhat.com> In-Reply-To: <20220905083933.2506819-1-david.marchand@redhat.com> References: <20220628144643.1213026-1-david.marchand@redhat.com> <20220905083933.2506819-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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 the PCI vendor and device id. Signed-off-by: David Marchand Acked-by: Bruce Richardson --- Changes since v4: - fixed Windows build issue (missing asprintf implementation), --- 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 | 48 ++++++++++++++++++++++++++++++-- drivers/bus/pci/private.h | 10 +++++-- drivers/bus/pci/windows/pci.c | 6 ++-- 6 files changed, 74 insertions(+), 23 deletions(-) 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..bb6275ee7f 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -44,6 +44,37 @@ const char *rte_pci_get_sysfs_path(void) return path; } +#ifdef RTE_EXEC_ENV_WINDOWS +#define asprintf pci_asprintf + +static int +pci_asprintf(char **buffer, const char *format, ...) +{ + int size, ret; + va_list arg; + + va_start(arg, format); + size = vsnprintf(NULL, 0, format, arg); + va_end(arg); + if (size < 0) + return -1; + size++; + + *buffer = malloc(size); + if (*buffer == NULL) + return -1; + + va_start(arg, format); + ret = vsnprintf(*buffer, size, format, arg); + va_end(arg); + if (ret != size - 1) { + free(*buffer); + return -1; + } + return ret; +} +#endif /* RTE_EXEC_ENV_WINDOWS */ + static struct rte_devargs * pci_devargs_lookup(const struct rte_pci_addr *pci_addr) { @@ -59,7 +90,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 +111,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 +648,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; } -- 2.37.2