From patchwork Thu Jun 16 14:06:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shreyansh Jain X-Patchwork-Id: 13929 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 7C944CBB2; Thu, 16 Jun 2016 16:07:21 +0200 (CEST) Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0088.outbound.protection.outlook.com [207.46.100.88]) by dpdk.org (Postfix) with ESMTP id 114C6CB4C for ; Thu, 16 Jun 2016 16:07:19 +0200 (CEST) Received: from BLUPR0301CA0013.namprd03.prod.outlook.com (10.162.113.151) by BN3PR03MB2371.namprd03.prod.outlook.com (10.166.75.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.517.8; Thu, 16 Jun 2016 14:07:16 +0000 Received: from BN1AFFO11FD037.protection.gbl (2a01:111:f400:7c10::151) by BLUPR0301CA0013.outlook.office365.com (2a01:111:e400:5259::23) 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; Thu, 16 Jun 2016 14:07:16 +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 BN1AFFO11FD037.mail.protection.outlook.com (10.58.52.241) with Microsoft SMTP Server (TLS) id 15.1.511.7 via Frontend Transport; Thu, 16 Jun 2016 14:07:09 +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 u5GE6XoE026530; Thu, 16 Jun 2016 07:07:04 -0700 From: Shreyansh Jain To: CC: , , David Marchand Date: Thu, 16 Jun 2016 19:36:47 +0530 Message-ID: <1466086011-11920-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466086011-11920-1-git-send-email-shreyansh.jain@nxp.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1466086011-11920-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131105596345089848; (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)(19580395003)(2950100001)(87936001)(5003940100001)(50226002)(36756003)(8936002)(4326007)(106466001)(105606002)(2351001)(68736007)(33646002)(19580405001)(11100500001)(15650500001)(229853001)(69596002)(104016004)(97736004)(77096005)(76176999)(6806005)(50986999)(110136002)(92566002)(189998001)(5008740100001)(356003)(50466002)(8676002)(47776003)(81166006)(81156014)(586003)(48376002)(86362001)(575784001)(2906002)(85426001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2371; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; CAT:NONE; LANG:en; CAT:NONE; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD037; 1:imKJi2L3AXjwhuX4Lrv2FEVJw2cTG/ZUmS05AyW8hfFgTm5rDaExY8tNbn0cvUwYHiV6l475O2zIqDu+QxlAfpk44j09rlXXDC7BmnNPlkZtR294xkiWw5Zd7yUwbjJ5hKBEWUcBAgkSgSu7Qsh7DIybOaFlyL+QiKxCx9uhCG+jI26EyaCh/zkfIpkVv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Ku2klj4l6cq9W12R6n/+OydsgmRHeJe7Ly7Z348YVuHAjGvSf8a+GWGnzukItGf2hJsJTVnx9MngIUihvA+ZXp0RxmqWtG2SeU8QAn6yyDvfRSSlvBmGUMsJ/W3VErRWW2WVIAe5i/KpHvs3ElCNruEhkIis1hfH2PXVUAUyZkPTgKPgNZetK+A8Z4lL+rQaiPuzK5RqB9FZOb4W67tVVxwzY827uw7NB22+8YJmPvOH2M9dr5lkUI1h3aTUzv3dZyzEwA7do/Y61ALWbP3UNpB17zi2x7w5YPsCdSQ/CFyZlcUA2xUQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2371; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(13023025)(13015025)(13024025)(13017025)(13018025)(3002001)(10201501046)(6055026); SRVR:BN3PR03MB2371; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2371; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2371; 4:d+ad1sihbRBXjqUNEmv0s/LXcJFT0LKYdFI3EhgQlf37lHXSjDlYgK8ENEc/D/ZEfUB3BP9Qvo50zbc7buGd+oCydwOq1F4vuwRsOzzHay8odmBm7/6zOoX+kJzaf4Dr7FAVZRTMkzBA4RZf31zgBKI5qmxznwHQc3T+Gz8uArG1rgY6Sj/4CNRQtNxjWjXKvHmWwWbVRHbD4km2tYIy5VGww3fGBuH9AwG9B5Tn4u/Gt8l9rW1aGOZAsrTMB7qNtljf9CGXVhy9eP2DIg2jfmdoC9ZyhMzz3s0h27k3e6bQXXDEWROYZvRz6dqUxpqh5YyxMNA933crmxsP27yGVpoKAMTBd6ECjPfkaP03lO9D0Ccn42VDqSTAazvrltlOZbLNWuX7z0UDhP9tWOjCrUGmDhclgsqqd4Ud9Ub22gxX45IbR4TREbxyVI9n/eRWiEOaIwQ7v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CR1Wbuv5oa6C5VG31J4XtDxdXtMRg9gMXBMdk8AUxBmq/kzWmNWJK6/DyTdOB9SQRYhXyEbmg=; 7:p+ZVll2ZQAQAmx23FxoS5w7plUdqLAT13m2hdunMzRgcf//3ZI/BQvtkXBelApE7bFDZ6bnonjPpuakQdWqWEc3Kk/hHauCeP/36lHjGSxqojTjTTyDlwX8TLMHYF3mulgNZqRgYkFdKo/AxzSkQeJqvPCQtnbnOBs1o0KJNLBX2PGfXU883zzx128rg+IDH58KoilBEsABICNr6j+BPMw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2016 14:07:09.7197 (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: BN3PR03MB2371 Subject: [dpdk-dev] [PATCH v3 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: David Marchand 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_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 5e8bd89..02d460a 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. */