From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id 7089C5689 for ; Wed, 20 Apr 2016 13:44:36 +0200 (CEST) Received: by mail-wm0-f47.google.com with SMTP id u206so76784571wme.1 for ; Wed, 20 Apr 2016 04:44:36 -0700 (PDT) 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=AEadDgBmMlYXivw4Y7u73S/6SCKCZ27mMigT0jxx5+A=; b=fFhXoHQ3A8t+vfRtNHQZsdJfCUhLlfwXTPBhIJw2BEUtKvM5g0nCz5/GLVRvXvLqmR gLlDbIWodGrwPmsmG4RP1NyhQwz4rV+kn5BzR8b70lm82w92MJnTGgL9Xy5KR6pr7BPV rUuUYL8TER4hIzAFp9kooSeUdRjoxjAc04MuWDRF/HBTUv4IsobaIzFVCEUGWpwK+GTp VU0pLqYTDXBqXgKhVy08Z+tAlwXZO4vE5OxOYJhTpEtVxcMpSV82TQ63YR4lUVZXw7h7 t9KjFMExWQE7oYuIz2OtYR7U1HuCons0C3q2RzA8WBJFzkOgRJRgImwg29PvBuNTey9a TGjg== 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=AEadDgBmMlYXivw4Y7u73S/6SCKCZ27mMigT0jxx5+A=; b=lohGj3kaqte92QsFnk0ulJ++1cFXSHmkyGAiH/trfHUuy79h5G/0ULB5EvlX/rlrYT XBrlsrImFgLSxXRcR6WaCo+y/OnSiY0xWcI53TPJhiiQHfu1nzXldgL1OzLCQtDyoqi9 /sV/noOusY2+uMAELmiUr6gaz7mgAyehvZjEHg9u+bvLHqE2IoSWes2ATjrAzfKk+hM/ 82vUQpp+T2vuFeO/MsQsb3+/rCM7tvFq0vNzHnTyw1UMXzMcqvhBEK4iAQx0R2ufM2PF QSejwN5q1OBuyjpwe48Unn2n29aeWb/MgZDKJ8SNs27SgEptFC9Q6uf7XopiQyfDoKaz gZkQ== X-Gm-Message-State: AOPr4FUK01d8jn8Vo8O2yyjVIKOn7nr/UUjVTEctWFpkywS7xFoffcGRBMYuRDfhSbwHHW6I X-Received: by 10.194.21.65 with SMTP id t1mr8353974wje.12.1461152676247; Wed, 20 Apr 2016 04:44:36 -0700 (PDT) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id m6sm5195708wje.21.2016.04.20.04.44.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2016 04:44:35 -0700 (PDT) From: David Marchand To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, viktorin@rehivetech.com Date: Wed, 20 Apr 2016 13:44:13 +0200 Message-Id: <1461152657-19969-14-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461152657-19969-1-git-send-email-david.marchand@6wind.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1461152657-19969-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 13/17] pci: add a helper to update 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: Wed, 20 Apr 2016 11:44:36 -0000 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 --- 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 cd8e8d3..85e49f6 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -401,6 +401,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_private.h b/lib/librte_eal/common/eal_private.h index 855fd25..81816a6 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; /** + * 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/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 3fc82b0..61ac21f 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_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, + 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