From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Viktorin Subject: Re: [PATCH v6 13/17] pci: add a helper to update a device Date: Thu, 14 Jul 2016 19:01:14 +0200 Message-ID: <20160714190114.755c3de8@jvn> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1468303282-2806-1-git-send-email-shreyansh.jain@nxp.com> <1468303282-2806-14-git-send-email-shreyansh.jain@nxp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: , , To: Shreyansh Jain Return-path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id ECF603237 for ; Thu, 14 Jul 2016 19:01:07 +0200 (CEST) In-Reply-To: <1468303282-2806-14-git-send-email-shreyansh.jain@nxp.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, 12 Jul 2016 11:31:18 +0530 Shreyansh Jain wrote: > This helper updates a pci device object with latest information it can > find. > It will be used mainly for hotplug code. > > Signed-off-by: David Marchand > Signed-off-by: Shreyansh Jain > --- > lib/librte_eal/bsdapp/eal/eal_pci.c | 49 +++++++++++++++++++++++++++++++++ > lib/librte_eal/common/eal_common_pci.c | 2 -- > lib/librte_eal/common/eal_private.h | 13 +++++++++ > lib/librte_eal/common/include/rte_pci.h | 3 ++ > lib/librte_eal/linuxapp/eal/eal_pci.c | 13 +++++++++ > 5 files changed, 78 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c > index a73cbb0..1d91c78 100644 > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c > @@ -406,6 +406,55 @@ error: > return -1; > } > > +int > +pci_update_device(const struct rte_pci_addr *addr) > +{ > + int fd; > + struct pci_conf matches[2]; > + struct pci_match_conf match = { > + .pc_sel = { > + .pc_domain = addr->domain, > + .pc_bus = addr->bus, > + .pc_dev = addr->devid, > + .pc_func = addr->function, > + }, > + }; > + struct pci_conf_io conf_io = { > + .pat_buf_len = 0, > + .num_patterns = 1, > + .patterns = &match, > + .match_buf_len = sizeof(matches), > + .matches = &matches[0], > + }; > + > + fd = open("/dev/pci", O_RDONLY); > + if (fd < 0) { > + RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); > + goto error; > + } > + > + if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) { > + RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n", > + __func__, strerror(errno)); > + goto error; > + } > + > + if (conf_io.num_matches != 1) > + goto error; > + > + if (pci_scan_one(fd, &matches[0]) < 0) > + goto error; > + > + close(fd); > + > + return 0; > + > +error: > + if (fd >= 0) > + close(fd); > + return -1; > +} > + > /* Read PCI config space. */ > int rte_eal_pci_read_config(const struct rte_pci_device *dev, > void *buf, size_t len, off_t offset) > diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c > index 6a0f6ac..58f0c74 100644 > --- a/lib/librte_eal/common/eal_common_pci.c > +++ b/lib/librte_eal/common/eal_common_pci.c > @@ -87,8 +87,6 @@ struct pci_driver_list pci_driver_list = > struct pci_device_list pci_device_list = > TAILQ_HEAD_INITIALIZER(pci_device_list); > > -#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" > - Is this delete correct? The SYSFS_PCI_DEVICES was moved here from rte_pci.h. A relict of some rebase? > const char *pci_get_sysfs_path(void) > { > const char *path = NULL; > diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h > index 06a68f6..b8ff9c5 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -152,6 +152,19 @@ struct rte_pci_driver; > struct rte_pci_device; > > /** > + * Update a pci device object by asking the kernel for the latest information. > + * > + * This function is private to EAL. > + * > + * @param addr > + * The PCI Bus-Device-Function address to look for > + * @return > + * - 0 on success. > + * - negative on error. > + */ > +int pci_update_device(const struct rte_pci_addr *addr); > + > +/** > * Unbind kernel driver for this device > * > * This function is private to EAL. > diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h > index 06508fa..5c2062c 100644 > --- a/lib/librte_eal/common/include/rte_pci.h > +++ b/lib/librte_eal/common/include/rte_pci.h > @@ -107,6 +107,9 @@ const char *pci_get_sysfs_path(void); > /** Nb. of values in PCI resource format. */ > #define PCI_RESOURCE_FMT_NVAL 3 > > +/** Default sysfs path for PCI device search. */ > +#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" > + Why adding SYSFS_PCI_DEVICES here? The pci_get_sysfs_path is used for this purpose. Again, a rebase issue? > /** > * A structure describing a PCI resource. > */ > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c > index f0215ee..8f3ef20 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c > @@ -417,6 +417,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, > return 0; > } > > +int > +pci_update_device(const struct rte_pci_addr *addr) > +{ > + char filename[PATH_MAX]; > + > + snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT, > + SYSFS_PCI_DEVICES, addr->domain, addr->bus, addr->devid, Use pci_get_sysfs_path here. > + addr->function); > + > + return pci_scan_one(filename, addr->domain, addr->bus, addr->devid, > + addr->function); > +} > + > /* > * split up a pci address into its constituent parts. > */ -- Jan Viktorin E-mail: Viktorin@RehiveTech.com System Architect Web: www.RehiveTech.com RehiveTech Brno, Czech Republic