From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-eopbgr690083.outbound.protection.outlook.com [40.107.69.83]) by dpdk.org (Postfix) with ESMTP id B4977C334 for ; Tue, 21 Jun 2016 14:03:12 +0200 (CEST) Received: from DM2PR03CA0048.namprd03.prod.outlook.com (10.141.96.47) by BLUPR0301MB1617.namprd03.prod.outlook.com (10.162.214.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Tue, 21 Jun 2016 12:03:11 +0000 Received: from BL2FFO11FD041.protection.gbl (2a01:111:f400:7c09::169) by DM2PR03CA0048.outlook.office365.com (2a01:111:e400:2428::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12 via Frontend Transport; Tue, 21 Jun 2016 12:03:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD041.mail.protection.outlook.com (10.173.161.137) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 12:03:10 +0000 Received: from Tophie.ap.freescale.net (Tophie.ap.freescale.net [10.232.14.199]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u5LC2TDU004076; Tue, 21 Jun 2016 05:03:08 -0700 From: Shreyansh Jain To: CC: , Date: Tue, 21 Jun 2016 17:32:42 +0530 Message-ID: <1466510566-9240-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131109841910537827; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(11100500001)(2950100001)(50226002)(50466002)(8676002)(106466001)(36756003)(15650500001)(2906002)(48376002)(47776003)(356003)(4326007)(81166006)(8936002)(81156014)(19580395003)(575784001)(19580405001)(76176999)(6806005)(229853001)(97736004)(33646002)(87936001)(105606002)(189998001)(69596002)(86362001)(50986999)(104016004)(7846002)(77096005)(68736007)(2351001)(5003940100001)(92566002)(85426001)(110136002)(586003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0301MB1617; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD041; 1:lab1O9o7PomeU3USiyHl/7qrKAkQghtvjAUwjUPA5EDJiJm7zDXjRJ+tdOQ0I7jbtfltsCZPEoDlTfTQNVXYIbwyf0130ijMHnvYc/GMBuPMV279zLBQW4QXQXmG+55iaz+AHEXotFf1TKmHXTeRg8NmM1RtY7TcobObgnUmmm2rXr6vpSMgz2BOLgEBrg2fIPn7xX3xSUYlVwOh2qjfyviNocUrK2frEr464HujfhOHv0ulu0AqTcpSVHc4Hvklc0p2sYImRxKmY0P5RsSZG8h6Lfy7s11MRdXuz01FVykGtuYNOcMB549ovgD16G3lEchIwcry0HLhNWKdm54G3fzq3b0/Nv+CQW4+54tqcqe5+XTlTIwOoOV8NQl17xs5vLtoppd8PTI4mXfXu/cadNRTqv40amu4r2QUjrWzhCTIPViU500YdsdUgm+5pnwAivedF2aq2sv8Fy92xTjilABkqr9OIVxz5OtBA5jdX/opP2cxQLQg9t5vmQTdA8vee84ZsAfgPzkiOx9y3guLzUdjEwVsn4kRx0P9Tm+P7URMhr42C2+K3W0S+h+mhU7DNIzgs/GJ8gC919lezBZYDA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 9258ea27-0cbd-4477-9e63-08d399cc0419 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB1617; 2:u0F2VjhUIGlQckkmgRYDbXhhdJrvi3bqVaWMtF0X1n6OG77ksjmz5YfgYWjJyn0yEhLUjo7Aww/F5M4Cygqt89d5baqMAhE5D7/DB54oiKY/UchMAZXaJlTJUXccUOpaDZ+nBlMwxLCO4j0ZdJR51xi8zMJLuSZ70Dc3bUtDanxPG5wcOAkbf82xVF8P4MPg; 3:nrhR1/Xc/x7Y5tjcy/p+nGzKnZTG9fW/zoUq2BAIjWiJwHuk8Xjxm59xEVdPX2CbswQCXnduGFhNxdExPtjJxBnPvU9IZa7Eopr4B7hUyE1mViBqHqj29zYMknpxtkVdr5wkxtR5oI4bEXeOB+RWYNE+eTF45UwkStNC5BsseqnQCszPKWF+9FZ8+B/xtS4Lkm1P0sHJGfrXU1LM6oSXWaB2w8FOmb0htynvZ6fogM8= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0301MB1617; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB1617; 25:Ha0uzmWi71a8Y4W/GM6O/83fBRsuK9Erwp1r5m1OyMWPW0/GwFbqWds5Y6ibDD/xnVy+yw7pyljn0bd2uZY0offxbzd+hryOA0Ro9WrITZohrNS6p2dwg3V/zYgmcbT07X/mABfyy8PN6zRSyhybzpxolEYlXLfTMua/CKymiM1/frXpIRnlnB9ucnK9dOJNco1ZkAqgcMQI4ZTiVvPKSjDt6TyRSZtUSss0eUmvPYshRjVkXJKdCjDLqp6AYUvmsooYD7ber9CcLcEWAjjzhubiHyLv5mO6H5Hh3O6p94MA92Ledv4ys36cmtaH0KdviMdB0ddDnnIRhtpkmeDgk1tbFsC+JHBdgUFmM4//bkQYclAZXubh18cZy+r3QgFvxFdZDQKU/0vC9WaC6YDcBxZkpeYFptkoONsz02c/pYIAfgK9RY450FKWzSzfwuhrS+QmE9phD/AbcpiWqkUebaex6LD39K1gBu4f3RNdl2+d3o11KvYxA98NalrEziDbXANcG0Z689LxeZrMYq/mLmNYPhB2b8YQQGHKCKPbJMZE/lWCeO05eWn3wZQUmntHg9csJay6v6V8waaTOknQWPY/YB5N861vWVII8r2gKyGIgxRyfk/M3mzDpGDvIzwuT0x+qvvTXAgZbDKhVtARHiLjJ64D/fD7HijZg6IPuU/eXvUS2dBzhlEpA5hQ3SgrGZyb9kNh/7P3eA16N/MVd9ctkgr+hRusLn2gJeCYhrE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13017025)(13023025)(5005006)(13024025)(13018025)(13015025)(8121501046)(10201501046)(3002001)(6055026); SRVR:BLUPR0301MB1617; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR0301MB1617; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB1617; 4:aE2aLbJikp2SaennscnhsalvAuoVlRxsh/cuauLDoHVrah8OTh8G7q2c8gAfxa1cEVJRhpj/ugEmsWWQQghWO23uhyG+QJsj75vsw32dMWlfnHq6ai1NWTTo6QQl+akHg/PjCYCBq9vRHTujlJaLPltWSOkLrnIZF53XTgwQdVXyY2DE+BUmDd6BtUp6n+wk775yAgjfp/E031B/el7CgDcr7kLBL6Yl31IvR0jJaMRF7hL7mxPNtE7wwwwcWoqkn0rv3SH6WNInJw0kAez0NEmqqaL5FetUkSEwpW08jKSKhr7rl1gomW1RKiokqwonvNDR9p3YWqKrz2kgVElN/3cVKKTiJpnu1ey9ui2N1V3W3KK5AY3+7epwHNqX/Xd5cGHzjZLUjNFkQDH7kXoeGvZOuurEZqYGa3BpJYwwglhLK5sQcf9DdkWoNpzVcyzw+ZEezR2iFDvsHCXkmgIwAbcogCFFGJTiORKpt1nluXZP1EsshnNCewDWFRH2GDMXfwla9AmJ6AQT+QMkE6N7Sg== X-Forefront-PRVS: 098076C36C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0301MB1617; 23:lKxD/vK7VXe/+gcWiSnr1YLlnFhNKQ4XGqr1zvz?= =?us-ascii?Q?VubD5KX9OAZmouPWwWslT3sjY/2h1M51tD+k0B4zGwloOMarV8ftFLiD8/+h?= =?us-ascii?Q?YyVTXOyRnQYxFtNiDqwIdKSqnCUAs3w0XEVY7Yp+pFly8bF5eu/nG+5mK+wX?= =?us-ascii?Q?c6l2f+S0E6RCqqCV60CJBOX6TdtNy6nwOCUkJA7NeJpjbE9MKH7Z45punpR5?= =?us-ascii?Q?vRL4RpPNWpCFtFqVBgC/+2lGfP4H1skMI9RE9jlWbwa5UcqAH8viEcWKpjPM?= =?us-ascii?Q?TJpewti0BopZXmSINXUZXAVUlmH7yB2ZvFsE1/N7/nTr5YFTcSxlkev/yCdk?= =?us-ascii?Q?ZHM4o5WkmBC+FQ7iA8wl/uY/3TAVb8bW8/HgpDjACHoaIjbgIZ9/shAw6cEr?= =?us-ascii?Q?qZe/d7nej4UsEbazcWvwv14rumHurDt6Q9ATbJ4UGoz0YNxG4fiTzUIMMPom?= =?us-ascii?Q?O/vvptXxalM8NF1GegN0UeqPvBLtHd4vAyBVl1Bzj7lYlTNB88G05PW4e1ux?= =?us-ascii?Q?qDRIkX5LbOJLrc6c+2gDNIdPw34bwWTh5snXpX3IVyzwDhL0iRMn1v23Vxtq?= =?us-ascii?Q?eJfE4zmI2EI8StWouMllgt+G21lTF9lRAimO+AUg+cfdUztOetTiAgVg9ZLP?= =?us-ascii?Q?vHtwdCLPGBf56B0P6PHnoppuO/5Z8nN0O/WWSjFskMGn41aFU6u16JKAeNwD?= =?us-ascii?Q?SwTkhzD5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WsWgcGh0bnup+6caeEskc=; 24:i/6qF2hEwrKp/h9cDhIklrWE1ehteOkbkzVqzYDwx5sdT3IiKhGDWpLVOukC3UZwiqpL4z1cFvVp1VZuyoDvY/jXJWp7tPHXzttw7+7nU0E=; 7:QV0Cii8PGNagltCFWWtcm2QJQow2bzJvDEz4ZDkLdLUvQHGpR5W8Cvow/MTEa6c7yFBVJkeN6RpJ80PIcPJ9EJ6FCtkVluH7zVMkJFri2SP2vYA+KAuEPXxwj+ZUbaNBOFRXLYcFVmSdC64ClCPLPbk18NhAXP7CkJcN4gD3jDsBokYaP2ro7yilVgIPvgq+SgJYqkUUqQCp+5iUm2xNR9+G5kzeAhA1cLxlH0ZrEQ/iH419lGSHkT7/zFKbkv+H SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 12:03:10.8353 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0301MB1617 Subject: [dpdk-dev] [PATCH v4 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: Tue, 21 Jun 2016 12:03:13 -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 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 880483d..013c953 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 fee4aa5..dfd0a8c 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" - 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 1666a55..eed6b56 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" + /** * 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 bfc410f..0a368c5 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, + addr->function); + + return pci_scan_one(filename, addr->domain, addr->bus, addr->devid, + addr->function); +} + /* * split up a pci address into its constituent parts. */ -- 2.7.4