From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 74AB2C6B8 for ; Fri, 29 Jan 2016 15:08:50 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id l66so56065144wml.0 for ; Fri, 29 Jan 2016 06:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OX+UfTIkUEsnsATRhWiC2MAjgoataaWQiX+8o0su2gU=; b=nu19J2CfsOeqVBKgyq0cAi7MV5YWQA2rhnyixCgDortiMvgVvJcoA7Ul/D9978L/2J 2NUMBXXrPKYbA1yMgfOiUS57131UWAJXbWqrdf7eeSKTyMNffaFm1VAcwra7GSbPHNYW z/T+Ui06KncqwWosRbpGR+hoc62vJxnwH2UASBqke0H8RXFkLnMvqgYw43AmvP7kfuHD rMOD9QauPV2p1hwJ6x3oBKR7QOTVdm2QvuRaXjEzFfwPbT+wTaMMg/x55WHWmaBZp9rT DoeTPNesWqvAk/EP/+iHSod5469udPTPsqTBkB9ReBYx99R7rRP3+14/sOWkBJFNq0lN hqeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OX+UfTIkUEsnsATRhWiC2MAjgoataaWQiX+8o0su2gU=; b=IQaQ+pwlkpCJ743oBTJ/MR+541KgukM6zTDrXQsacm24TwNgrPL2nIKHOt/rWYXUzI wWm0Zz6SPZig+EZAGg8caoJEgkzbdg/VctFccqSPPiw/Ei4KxS03RfEYAMbUKlOJTQXB 5kZJnuE72C+k8nKi/vDRGoObhQPSLOsWtFOjYiTwnnTsUqeY/P+Ub6oZJNYsOkYteYGd 4Wsccvv7M9NXZPyqJ+muMYWHHBYm5elP1y2L7yO7H+8+IANzHFU/mhpqDB5vxKqVNaBa y8R9KvtRt0Jy3yBP6Le4lXtiuPd54aEe2gxe5CdZZJtwfSXilBmQjlmbFX0VLay6z55I ZB9Q== X-Gm-Message-State: AG10YOSDRbZ5iseXerCe+DJSwd9k22DgekOrNss8/2bDTz6j+O48dCNFYKYjML9zbYXL7hMZ X-Received: by 10.194.112.41 with SMTP id in9mr9022023wjb.139.1454076530357; Fri, 29 Jan 2016 06:08:50 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id 67sm7669944wmp.20.2016.01.29.06.08.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Jan 2016 06:08:49 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 29 Jan 2016 15:08:35 +0100 Message-Id: <1454076516-21591-9-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH 8/9] pci: add a helper to refresh a device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2016 14:08:50 -0000 It will be used mainly for hotplug code. Signed-off-by: David Marchand --- lib/librte_eal/bsdapp/eal/eal_pci.c | 49 +++++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 13 ++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++++++++ 3 files changed, 75 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 4584522..5dd89e3 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -396,6 +396,55 @@ error: return -1; } +int +pci_refresh_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_private.h b/lib/librte_eal/common/eal_private.h index 072e672..ed1903f 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -155,6 +155,19 @@ struct rte_pci_driver; struct rte_pci_device; /** + * Refresh 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_refresh_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/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index a354f76..4fe8b60 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -393,6 +393,19 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus, return 0; } +int +pci_refresh_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, + addr->function); + + return pci_scan_one(filename, addr->domain, addr->bus, addr->devid, + addr->function); +} + /* * split up a pci address into its constituent parts. */ -- 1.9.1