From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-eopbgr690047.outbound.protection.outlook.com [40.107.69.47]) by dpdk.org (Postfix) with ESMTP id 07787C4A0 for ; Wed, 22 Jun 2016 11:06:48 +0200 (CEST) Received: from DM2PR03CA0037.namprd03.prod.outlook.com (10.141.96.36) by BY2PR0301MB1624.namprd03.prod.outlook.com (10.163.28.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Wed, 22 Jun 2016 09:06:47 +0000 Received: from BL2FFO11FD009.protection.gbl (2a01:111:f400:7c09::166) by DM2PR03CA0037.outlook.office365.com (2a01:111:e400:2428::36) 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; Wed, 22 Jun 2016 09:06:47 +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 BL2FFO11FD009.mail.protection.outlook.com (10.173.161.15) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Wed, 22 Jun 2016 09:06:46 +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 u5M9663m022009; Wed, 22 Jun 2016 02:06:44 -0700 From: Shreyansh Jain To: CC: , Date: Wed, 22 Jun 2016 14:36:32 +0530 Message-ID: <1466586396-22618-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466586396-22618-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1466586396-22618-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131110600065248102; (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)(1110001)(1109001)(339900001)(189002)(199003)(4326007)(2950100001)(189998001)(15650500001)(5003940100001)(104016004)(68736007)(6806005)(19580395003)(19580405001)(33646002)(2906002)(110136002)(77096005)(50226002)(586003)(8936002)(69596002)(97736004)(85426001)(86362001)(81166006)(47776003)(8676002)(2351001)(229853001)(105606002)(48376002)(7846002)(106466001)(50466002)(81156014)(356003)(575784001)(11100500001)(36756003)(76176999)(92566002)(50986999)(87936001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB1624; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD009; 1:SyXsKalQHBXj5Ii3JOAmeI3XbFvLYwCXJIA0IwJlxYQ3Nsievi6XIaVBXW+rnHek5n+cXhgvSBIUhVWMVxt1JliEdnZ5XbklZ8NyfYBrTDAiGw0KYCFAkliq5ihpOFaA6aF+c0X09ZzV04OE5ovIV6F46HCwtEJUQRSpQguTcxwTIkhxXpth/P6F9+fyZ0U40SccXt7md05Feh0Mi/6+knT/DrvQgRbUMx+InUkIWSzOVlsXuJ/z9edoUqTui3AisWW1xHCDVweE3b9YM7veKPUdRWnYqgnfMA1Ka3bbRyh6OWrnT4E6e86ad8zCA8g8PdxkI8wLLxlwSIlQ7EdPhdy6jTcUWSkps5oWV6B0PgB7JrYfs7iZAorPJROtVuajj+AK+SNrUcY9ew54YMQjsp7RZlKY+lV5Q5gT3ioMxecMw6o2YpsJg949qA1NwFdk6xXIapszp/i0gI1TCGD4r4xmtCqTZrOC7jEc9lb0m2wwNy0uL/YSxOCI74Dlvuyb0f1CBphIjb+rXaTaS+DU1F4X8PgcEi86Fakvh0gaCU3zTLOEg+UOKiJerWrmAXxf/qkxq8Nsmq8HCMIiWFf+iA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 5a306967-4a60-4519-0a05-08d39a7c89a2 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1624; 2:ar8uyV2PucqpGwhygFC4pHJTrDDwVHxlloLZhWCvIdZRtd5AVa7uoYIfxG1wfvpTM/voa+/rv/+uqlWpsz7qPUKObJYKgJa6f3uUxlIqFFgz+XywRsad6wVNL58GKd5urXeEpHH35nc4NXh9PIHctqX0rblyzy0VyjOU/GVS4oo4QLogrDZ1QYVtxK3feqbo; 3:ljV/f+kw4R+KqocVSnln1Dz30ibeRcHOiUzpqwUYNWggJWmwuan7mMBNmuYSVWdd5KOBbe0lbMVn7XO0oZ+NEAKBU7XGNjMMOGR9PwCY2egqY7ufTFnkcMddGOuw+vIxZfOiNDUhjpScbBrnAcLmi1Q8oz6BXgJLeP/kynXlSWeOijHF2ORzD2gmk/J2QOJCCLcZZfd4drA0pCxmSw6Sbv00prOFcZfSH5LieJaZLQ0=; 25:rYGzjKAdsIP+QRS2jXEXSDomcRK14tVVqBfkoeeaT5UAictMgyN8OWrMZ1R+IxUZb/PqSsPzvHGYfL4DCCJmPZdrL4iQPTXzImm8rkHgtJJByebYjHH3Ms+GwHhuDWnhBdl/RDI/X9ejvHMFAIEU64TitlOIIBpjXqMytWv1fqd6OxiQLSqjdYua5Y7v2DPM8tXWlWKVdSAvwdn2t6kE/105RSxTr+A7mC5ZaPZioCGqq3f9XYTJJy7l2zY4H1SRGGCLNo5wS4R6d9iEgP00NAK/issfX6IvrMq8Msc7NhtQWYWh2qAyYzp5kbkFEQCAQn4FVbCMNEZGpaTptK/gEgeLIW++Bvv7QvQmN65Xk8c1i3BWKLzEHDh07AVX9jeg2xxU55pwcXk8BJIWAulHLfC+LDBXi/7xZkZIvsxe0MQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1624; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(13024025)(13018025)(13017025)(13023025)(13015025)(3002001)(10201501046)(6055026); SRVR:BY2PR0301MB1624; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB1624; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1624; 4:3r7ulQdRspeyNxS2X1W6+KG816dDkqxF5iL6kswIj/71Vmb9tiqRiAVtfKm5Jm6uPJ9R87+RcfuVhQs0gv/E3H4kl8AQENGfNxNQAbjSFTK+jEX5TBYKkiGz79RYthOyzsa6o76ZnoGqH1Z167Q0GWSHJ9wbS3OmWSDbZOQXf3w+oJzDPjsKVFBisfEaz8NLIoyNT1LoTIhs4o2OnSizkoXBHpnwu59FzWS8E4jmCULT5FCJKiE8h2VOyZTfmEFoBcKhy5Ux3hdKYZa5o3BxSNpUpgab+7x3u5WUe7wZ72t3O+gTevwKm7euSIaluIrEOhACVrOGa1AKcN/2j+BPqhmqbJd5OExZlTXYn2qOIxyGqjkbWS5z3DkvyxhmnJWViNIk1QRmaIcvCh9Li9BUCvqpyM0B4K41ifPqqhlp93Y6dMsRRdsLmSMr7n9gdWkvXxE5TKB7mMjbpv3juRcavqGzxWLJLnuKb99E70Vzv3lVF+Inrv/pKJnFTQtubWqlO1SAWeK+428fPGXK1zU3fA== X-Forefront-PRVS: 0981815F2F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1624; 23:bQAe5WtpAZp8mgze+FdEkAnfONgrtFEaonHtloZ?= =?us-ascii?Q?y8eFj2gu6lEwVqlAKYPcn3e3t41nmDbRpMkWO+87tENe29TYWgke2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8+12n97jug0gBqn/RCqFu0hnN9WfkK/RkXovyktbK26NZj0ov8vAEnPcal5DtxKxQrlrOXvPSvDV3uMlHdxwIP0IdvSUXFaHlyu3Xp+NPwXIDUk3Oz4UQ== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2016 09:06:46.2752 (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: BY2PR0301MB1624 Subject: [dpdk-dev] [PATCH v5 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, 22 Jun 2016 09:06:48 -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