From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0069.outbound.protection.outlook.com [104.47.32.69]) by dpdk.org (Postfix) with ESMTP id 7DBA05686 for ; Tue, 12 Jul 2016 08:01:33 +0200 (CEST) Received: from BN3PR0301CA0053.namprd03.prod.outlook.com (10.160.152.149) by CY1PR0301MB1993.namprd03.prod.outlook.com (10.164.2.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16; Tue, 12 Jul 2016 06:01:31 +0000 Received: from BN1AFFO11FD050.protection.gbl (2a01:111:f400:7c10::182) by BN3PR0301CA0053.outlook.office365.com (2a01:111:e400:401e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.14 via Frontend Transport; Tue, 12 Jul 2016 06:01:32 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD050.mail.protection.outlook.com (10.58.53.65) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Tue, 12 Jul 2016 06:01:31 +0000 Received: from Tophie.ap.freescale.net (Tophie.ap.freescale.net [10.232.14.199]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u6C60qWl006202; Mon, 11 Jul 2016 23:01:29 -0700 From: Shreyansh Jain To: CC: , , Date: Tue, 12 Jul 2016 11:31:18 +0530 Message-ID: <1468303282-2806-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468303282-2806-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1468303282-2806-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131127768917368141; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(47776003)(76176999)(85426001)(19580395003)(50986999)(68736007)(305945005)(189998001)(19580405001)(575784001)(86362001)(15650500001)(87936001)(105606002)(97736004)(6806005)(106466001)(104016004)(2950100001)(33646002)(110136002)(50226002)(2351001)(229853001)(8936002)(356003)(92566002)(5003940100001)(50466002)(4326007)(48376002)(36756003)(7846002)(8676002)(2906002)(81156014)(81166006)(77096005)(586003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB1993; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD050; 1:78d0lI46j6NSfIcUf8oFJU1P6Yc6m+8g3sRNGpYkqTf+RYLoB1GIl9Zr0891TTABUrg4mOar2frh1095QQjGz7byBGSkIN5qMh2zDWEjlPaEtXWmDmPe7/qku9kiPiX7bpmKaEX+w9yP1vF+J+2IKAfdmo1AmwBoxlkZX01dD7wfiScc+WODVAqsX9a9T6zTAO10jGa49UtxTmW5CceQAMb7pOp82COoGP0BDxCMSVYO4YoN/5ziwxFb4VScD6ydh9AjSVXT8Acwl0AFfdfbNJ9Lmb9OEPYD7ScpbwPRihJXo0eb8QojOb8PXRk1uRkWgF0MXbdc/Ap96kOvjXSnP4rB/JOyxXJZdzOsn0C8PnrhVv/H+MEXUoNJJpl9g/jvASViiIE31bw00hkziLrTdOSXOHmSE8Np8ZYiOjRTVyfs5ShvPW2F/l96dJDxcxdrT0shCUO89wgr7wHSXE+6/YwIiFfNB+HPU1qDreVNrlJkBLxlgdVGTIj3+F/5N+mLCiAxsLtYaVxgbeZaVGQMaf4SEFiSOP84T1H6dxuLHbur4s+90p7+dCH95L+MxrCnN0++5ovaelTr+p/Od62crm2YzXxyYLcEP32tJOFRLvTaleYRx8K4Dav+Mxc1wbzq MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: fb96cead-9d28-4e70-fbee-08d3aa19f8f6 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1993; 2:loXGhBH369uafE/SEfxWpMuHMIPE2EMydvUqziqsH9VU50cehiPIyV1OXc1ny4ALFOfQD3u4B9vdiFMHAlPhKPwr656wri+FNLY0jlyjHo5We+utut9yN81SHnxeX8QHmHJYGGGRhTrhvnr0TRjMw3HSP8lcBwG8zzunkZOjQ8SKdS5dgsLeuQbbjarSsVUG; 3:+5fmOTR3oDEWbsv3EkG38RjhxJo+crcjgrlJLQzsinqwGO9+iVMSfItl1rY1cHgWjBRk9wiuE6xhOeGta8fdkSlTBfio4gH/+WTmFr2Lf5UCN7J11geuzDALh0kkRm41maPr/9400NDsbtWxnhsRvX1EEWRFSLFd5iWdVImWKZTe5E7HyVocctnq91SbaU8P2A7KTwrFugCxaI2J2IGQ49L1H5zUKy09k/SICGBAgKg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1993; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1993; 25:s8o2kCT7XhCT8M649YGvuJGFTOHzm30VaZbLdFe3v7bQTCWFSVOj2LPO7OCYcM274ZrwypdJIgYcsYnaDHiWY+IR3gNekONcP01tVwIdHH4HyJLoB6uwo7aE9VT72zW3g8LVxqtEg1i3lwSXeLd8bKMQCNKaJWJKL6tYCInRakpg2uAB8sScUj1tSHh1b309xlk1dXwNyZy54KAg0aSNS54yDINsEnwzenjx2V2Ko/dz5IGT0MHCEjQ+0bFfK7iM0I6ydh+g/pkt4VWuW2Ii2BHz9HY4LOlBXJu+QfFpN6Bd/T3v2tkWopyCr1asIopQBUKEL1NgszxxEUhVqC+yuwBSkhQxR79Vixm//FikTH+xO72dbqaJWRvuPguOQXElB7rV1uuyxi0ev+stb9bp0mAGPDVQcngEX+D1QSYAIgzPmMUYb7OxLKHN9BdtlMT9vhLj8bK/usvBrrkgQneD1xCr19ssOQ6bLDpT3+4NM4K9/THZ0IeNSIw5ZVhn/Jandt5vtGP33YKTQ9Zx0j50CqFBI3VM9UvqNMQ81Ws+6sxtf4IRrKcCUOUBSMRSqOhbVfhl/hWOE2QDPOuQgb7i1FyIH73zejN3P1yCHcEvueKnoTeSin9HB54mwHfjWNrLYvYIwRQXQbQN4/W0BuVa4MEm+FqrC98gtYRsWD6do2gi/Wo+Wh9lKNmd5z4DVGizDxWoEHkalK8XCubWk+IKj+4D7dfTfDmhb5k/dgj55CI=; 31:kHFP4PZe+6tL94JE0KLITZvK4L09f8mn8uwOUxUHGpS1y0lop0fo+tRo7N1NE0AW3aD1FcjuxN7tajn4yYo8AAYuMHjbsrUevJZPk9gKIr0Nq4iA84aH2zToTSB4RqZxBOs29FPTicfQcpWFwXawdGW3LMqYUHghw557Pj+yoxfcpSeBExqCq4hTWj4FcMbW7kKBNcR2J01PqIuc/QmqPA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13015025)(13017025)(13018025)(13024025)(13023025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:CY1PR0301MB1993; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB1993; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1993; 4:9qWmPMvITUUxgyeo0NVw8ceDkdwWRrb8mRnjlqSeOllTSSGNCa1/0DTH2UW7vM4o+3khBC2jcbloOMAjuxUsfx8hhennbpdwFCPvNDWzbqEuezeXPybfBjecKjSb9rPg3FmFcDCdVfksnr/ozvXDxXHNszolIBgzYUSPmuEa6t8qpvn5GZ3ntHQw2jbNOXBLZ3dKSAewZz+uAjX3AKKK6W7knEO/9glcJ//OYonuVIW0vfyDI2MLhloHL4L7OmTvCa94pyn6VYVuiyeg5bL14xQLhiwNUM0YfgRcKzH9tl92q1IeK/KrSHiOS+h9TyE4UrE6ddcNbi8wtM4ewzaqcmFCJ/9TmYNa37bjfthO71hg7HqeXEEBZBA32GIZTAOL9to4MqzCn1kT3KLO3XTGkBBnhUxS0CG1gSL5vmWaPbtHnG+ckGM4CEXE61dmx2vB7S0TX8US9KnQYaL8KOuQBu/mXvNpsOro0j1875UxnUW1YDzg/ibtGpprdx3WkdCsKpyDqP5RvdMqD1bSrh9vjQ== X-Forefront-PRVS: 0001227049 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB1993; 23:98xAfko3N2sPMHotEkN5dgP/xIeGf2huVi7Mmf/?= =?us-ascii?Q?J3TRBx2hCWYHbu+zo1mPq4zbQYTGNOwuywPDETiFYqUsN1z8GJb2dlVVPWUH?= =?us-ascii?Q?01AjdBohFFBX4m97oogKCOfar5oiwxkHZ3i1EctAdUnicH/EnJTiV+qLU4b3?= =?us-ascii?Q?YzLuN3D0peATFCFRE/E8PFf55yb1/iSfq5FtkRoe4N38t0wF5rD/3MAV8lUb?= =?us-ascii?Q?HdwqZFLsGB3KyNFiYgaWmbAs9lTnvZri2MQchkPGVjAXdjpkCdB+LFBXlr9L?= =?us-ascii?Q?KiAXjmBYysyttl0lM5VVuvh2XI3QcPbJbKU8dBnrTQHhB7rVgkC/P5AZaMcX?= =?us-ascii?Q?NWtdl1zoGiJ9TXkoslwGSyC9OSy4Od6YkwI/JzHf/LMl03r98Mr5lZT5OLfa?= =?us-ascii?Q?rziEbTG458YRTw7YBUIMb4Mg2KRjL29FiRB+qtO4IX0Elyb872drqSnqbBR7?= =?us-ascii?Q?xkGkOBTTXwr3M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wrpU5e+64VZTF7cTAj6Cd+YRVPqGULQdn1+nRDQBrNCSFqLRpAWd7g9lsB7Ij8c5cOlcbv0fVVlfErCflVppBOTsjc=; 5:VERHOdpIcU43dY3lT33ZZCkstyJGLcwXUTQHYQbkqCfWwVw4ugAaK2h5xqE72nORlgx70tju+dhLDVlqjTkbHjkZ8XXTsr31rubzmcYuZigS3LWmihoDo/u1bEONnlfPXQtJHprPJMim9yk+U3wOamw8+8iflVE+7U1d/PepKjY=; 24:WBrQtxAVnEtuNwmjps3MzmbK6Rxm/v8/RSCDvjnxKFE1FnU+74TmrCH0HTXMNM3TewbuW1l33YDWi6OZMrCra0UPmB7cltull09isBhrLro=; 7:v4RtAsBzm/piDO1u/ie1QDzrlpw27iuNUZEXpDbqwM16+dhkM3kgz8a9BXYXvXhvluH14ylbkLPk7wSnXbk/ABQ5WGt+JQAO27/lMu+QmBfM70lpGTPyyQiT9gLIis8b45El7I4JKI1qrhPI/HqVoHRzAznTfVbWa07pUjOEdnKh0EDqiTatgR9dvwUR0d73H3+q46avpUuqAIv3tmsb0M0Z4NOfIicJKqYPMUdtZilZqXPwQuFUFgN2K+E6ysqD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2016 06:01:31.5496 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1993 Subject: [dpdk-dev] [PATCH v6 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, 12 Jul 2016 06:01:34 -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 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" - 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" + /** * 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, + 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