From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0063.outbound.protection.outlook.com [104.47.41.63]) by dpdk.org (Postfix) with ESMTP id 18F424A59 for ; Sun, 4 Dec 2016 11:09:34 +0100 (CET) Received: from BN3PR0301CA0041.namprd03.prod.outlook.com (10.160.180.179) by DM2PR0301MB0749.namprd03.prod.outlook.com (10.160.97.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.9; Sun, 4 Dec 2016 10:09:32 +0000 Received: from BL2FFO11OLC002.protection.gbl (2a01:111:f400:7c09::134) by BN3PR0301CA0041.outlook.office365.com (2a01:111:e400:4000::51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.734.8 via Frontend Transport; Sun, 4 Dec 2016 10:09:31 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; 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 BL2FFO11OLC002.mail.protection.outlook.com (10.173.161.186) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.734.4 via Frontend Transport; Sun, 4 Dec 2016 10:09:31 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:669; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uB4A8pKG019825; Sun, 4 Dec 2016 03:09:28 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Sun, 4 Dec 2016 15:41:27 +0530 Message-ID: <1480846288-2517-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131253197718108763; (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)(336004)(339900001)(199003)(189002)(7846002)(305945005)(5890100001)(2950100002)(97736004)(36756003)(76176999)(2906002)(4326007)(626004)(69596002)(105606002)(6916009)(575784001)(81166006)(8676002)(8936002)(2351001)(8666005)(81156014)(5660300001)(85426001)(110136003)(356003)(50226002)(106466001)(47776003)(5003940100001)(77096006)(39410400001)(39400400001)(86362001)(39380400001)(38730400001)(33646002)(39450400002)(104016004)(68736007)(189998001)(50986999)(48376002)(50466002)(92566002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0749; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC002; 1:lCNWReMNBWsH8HP0wpdlVOihOCrnfyMs2XgtlPtWC27pmlOrZb7MpjTaWAHTPznwevpb2qn/f+zI6EoDeEg6K9w4Kl2xSz4ncddtJZ2yUDS3Sijechb/CVDOPUtkHBYDvFhwA2B/NbwiATD6m4MNPijggX++XfUqihoMRNhhXnCYntfTCOCmD7fFtGlDqkAaA2m5TT7UTnEOH+NB9i/8KJbXsp5Wu1qpXWMKAm3xkaBroU+XFOJRlRMChYgDkn0TCkOJoT9MbtzMbPedXkvzqTJWkaiF5WwWLTWouQiS3oadZM/a1Z9DCApu1j11JfmwUpyb60IsX1Z6mZolZO0Uvr3nZd84JVXbezsdSuSmxxlafjlnyzGsCHXEvcBHdboDilKxWYFHCYufQ1j+vdriAGG8945AMNIhtBxVdsWI7itcWT9q+x8REFMBOqpc9NHEXVI6BnMCMiGO7DAbEGONDNxZnr7Cv6NExs2oiTdQSgfX1qfkwQXC49QNtEL+44x4OJoyF/yL2sP+URoahq/KPAh0pnlHcxsTX1G45KljyqMX8QZojYdUP2w+sKaEU2/GLkkmer4FTNhmWcUZu97gSRFHvmih62t34Ho1QPbJkgEVOvartp7KOj9DwwoDlH4iXIOkp9p6B/w+aW7nc6zuEp79wYnatgToGQ0riYrt1tWry7XEijPlzOB/JvJtnNmf9C2klxIZrdBu4O9FYfUsMqwG2l4w3GKKzILnh8i3uvo= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: a262dbe5-393f-4d3d-d8fc-08d41c2da413 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0301MB0749; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0749; 3:Ei3kNi1FGwsFu3QKvJc2/iEsKM8l7Aa111SmOTNHwSpP7roWFuEKybc1PtPh/0KMU2zNzV/OqJii79jGXf00L2JlSP+z6rSZqjjtAAhumqSeQzLKEbc8PwKn/RtLvMv0JSRzryzGHhMxSc1r2xCDUMF34Ei43JnJJJwPChE8CutUR3KhY3v3HlAo77w/mnxj17d3oBbfPfRusG2V5RUmqjMw5WWoFx55QnKLq2g+sf58YyKcJJF9OeML9TvAmzQ76fxpuplEuEMvtknGzW0wfFEeBjG9n9d7hC2XCwJRPswSBM8AT72ADqcGGojGAhxDeOfIgGovrnmwQzoWDyeUUgIYYZI2eGKWOrTWKPD4GB3dpfgM2WsS7HHD8q2lDGzy; 25:naMksMs0ptklByZA831E04SFLou5C4i3IL9L2N4lliASt4lXPx8+IuqnBupn9MdXSGoH4EyO48Bcu2TGmMPGNEDLmVapxxV45ck/HFTJxLgblB0R5I8Nwj2mivKS703H2BVsEBMOQdiwwnCddqisH6k1PjzRagIza4Hv1FzRhdYQpydKk3wOxCH129mJoLC/miGKjnYVMm4t4Wl6KpCwcJANrde4uwDyH7IVzXufcHO+StYttqa3eEzASVFQe7UJmnizw7JVCeNsDTBeYImV0qeRPZzp+hvmpvr1BNqvM94rPsyuc0Sy71CyBrGVgzIu/42TXqugolCrVxYHuzVZrfEQyGr+IWORhKaPg0LZH2Qe/sJy9ynVhMfNS0Ck/g+Kw3x83yStEIVB8t/PN+HQGMJNBDcHFG6SEHMdzQEkKkJf8FTjQqvt02s5iAMp3W4wBx5wk0IQgLU1PytrKAXAjQ== X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0749; 31:KNasS0FrPE5QX+3lrGRWbyoCH4KFtjed/UUstK+yRC5m5EjPBwTMoWF4m5jVWW1+1rD7HERvC0pASOBjuNsirOpavFU7NaQQivJxlaifUi5ep1VBvvr5Of2a9Az9PDL/vTHP/YNoEYvUsd8OT0EyrHy7FCU0/aZlJP+t3D30b6Le31LFM8hMkS5PGSxY/ASLtqL1xDTej0NICtOLk3xhvO3xKaojf+P3OKF5Vu2hv8G8DGenlv0jhmDB/lAIW/5FX6IFSKwMdroTW9m2FO/Rsg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13017025)(13015025)(13024025)(13018025)(13023025)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6096035)(20161123556025)(20161123561025)(20161123563025)(20161123565025)(20161123559025); SRVR:DM2PR0301MB0749; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0749; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0749; 4:ogPtE/wjkI1/HYbIAdiHjlbG0AYScevDyZfFzv67nmk/MmobNGtNtVZ/jaqJfvaz1JYBE5HmetQCL1kgt/2XJNgmWaOlKZaKLSL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ad06OrwOdwrjuPxjQL46zjQT8X4ooSVbO+51C?= =?us-ascii?Q?XJDZjC/JqD0jOx5UDN+QoyQBAtxdGqjOHcWyW3G2MbDrNbMCxjIQEg3hqGuZ?= =?us-ascii?Q?fupLk+3KjSFi8ZH8BTWfBF+r/ISWFOCcg3kMizxX2?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0749; 6:Io9oVnh3zPkw9n5ajkyHTGUEOYbZ9DbMNROFg8P4qmX6KnMVQX1/w2EuRxFxhXVuUZ9i6WnlGd4+NaOCoPf3HhFWumZeVE3qIF3XDLve+QbHNaLlzUXSiYUr0OcgsBUIZyTKfpP9nLhC7mBkI3SZEdKameBN95MxIlIvGyKIgeFhMKbHnaqUVWfkpGL2QL9TN7USfFhQrvOeV/uTcXyQzHworDlK/FjksQthWz8FKSU/H1AYrNvKWMgE33OIPmJKncdl4CQvdL5ULlPm1DlGkbANCBu4Hr6bWmvrnkBgLQyZIsAJEubSljiONWFqheANye4LBUnCageikP1+BWFDPMKlOXHIz1s4NBLU6kv+FDrcb6AWIGgVADib8PPyLGHCONsbDsQqS9zIfXG0ObtjRVr47eTniYrKA9x/LXVXCSyrDCbC/6l0Tv+v1sO/lexn; 5:BsdPhn344kjYVYMToJ7ei1w3fkTtuU015pcQ4oXtbaKqcfKF5piaY432CHGhTGyJke7fLt6Te9s2+gCfAXUy5TwckI3vBli5cPbKMoBHj4LNHE1yN7ICXSOSUY5OGAbCskHOH2rD0HY7DwR4pzMr44c3JOlZT+jygpSrx7BYhIN8bYIYySZ/MRTYKSolJgoD; 24:X+R5E3q6S0cUkc8WctSQnOL4M51smtM8hiFDK8NW6zfO929JGJGJ/VfToiTBmC0/f8xsLHgT3nRJ63xASJxxl17VkZ5OJXrw75CB/AWpk14= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0749; 7:ubF5q0rllAjRqGmuk3tP9YAkuC91DjyGvh6WUnBWI1H30gNpz0lKjO5JWWf7MiZMXkGywRR0LCevEsy5bW6KAZbSfHyIK9ka0FvPSHTwrNWXja9MvLNm8FZKVwhLNYOCqj6ynn6aB9sdLcn/Ibn5nmB4bZWeoMvqASc3KOR95QfJo5p66Am+HPPqrz3wtrMWhktM/VoZI8Ixtm/hDruPfN1Hvcft5JGyHgSB/4hwWLPwT0BNbVb3J7cz+n1Xjq3YQvTlelhXq7cEwCUvGFNrf9wah6m9JsvfgLJ2ecLQX1t+cCo9o/y5yxMTPQ7QrKYm/Oko3JXe1GvycQVlsEjwt7I+MWjXxxXa759+VVemCgk2jWs6Ykh/S2rtYthT/1tfE+ragd0NmhM+nntlE0DD8AxY+x1sZnm+3+Ccb33G5VxFaN7HTgLMCQ3TEVUKQtewnq4YGLIZmm9/dLnRJIiKGg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2016 10:09:31.5612 (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: DM2PR0301MB0749 Subject: [dpdk-dev] [PATCH 12/13] eal: enable PCI bus X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Dec 2016 10:09:34 -0000 Register a PCI bus with Scan/match and probe callbacks. Necessary changes in EAL layer for enabling bus interfaces. PCI devices and drivers now reside within the Bus object. Removing PCI init and probe from rte_eal_init now that bus performs these functions. Signed-off-by: Shreyansh Jain --- lib/librte_eal/bsdapp/eal/eal.c | 7 -- lib/librte_eal/bsdapp/eal/eal_pci.c | 42 +++++++--- lib/librte_eal/common/eal_common_bus.c | 5 +- lib/librte_eal/common/eal_common_pci.c | 137 ++++++++++++++++++++++++++------ lib/librte_eal/common/eal_private.h | 4 +- lib/librte_eal/common/include/rte_bus.h | 5 ++ lib/librte_eal/common/include/rte_pci.h | 3 + lib/librte_eal/linuxapp/eal/eal.c | 7 -- lib/librte_eal/linuxapp/eal/eal_pci.c | 43 +++++++--- 9 files changed, 189 insertions(+), 64 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 30afc6b..79d82d4 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv) if (rte_eal_timer_init() < 0) rte_panic("Cannot init HPET or TSC timers\n"); - if (rte_eal_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - eal_check_mem_on_local_socket(); if (eal_plugins_init() < 0) @@ -616,10 +613,6 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); - /* Probe & Initialize PCI devices */ - if (rte_eal_pci_probe()) - rte_panic("Cannot probe PCI\n"); - if (rte_eal_bus_probe()) rte_panic("Cannot probe devices\n"); diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 10b234e..ab04408 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -249,7 +250,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, } static int -pci_scan_one(int dev_pci_fd, struct pci_conf *conf) +pci_scan_one(struct rte_bus *bus, int dev_pci_fd, struct pci_conf *conf) { struct rte_pci_device *dev; struct pci_bar_io bar; @@ -322,19 +323,23 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) } /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&pci_device_list)) { - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + if (TAILQ_EMPTY(&bus->device_list)) { + rte_eal_bus_add_device(bus, &dev->device); } else { struct rte_pci_device *dev2 = NULL; + struct rte_device *r_dev2; int ret; - TAILQ_FOREACH(dev2, &pci_device_list, next) { + TAILQ_FOREACH(r_dev2, &bus->device_list, next) { + dev2 = container_of(r_dev2, struct rte_pci_device, + device); ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); if (ret > 0) continue; else if (ret < 0) { - TAILQ_INSERT_BEFORE(dev2, dev, next); + rte_eal_bus_insert_device(bus, &dev2->device, + &dev->device); return 0; } else { /* already registered */ dev2->kdrv = dev->kdrv; @@ -346,7 +351,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) return 0; } } - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + rte_eal_bus_add_device(bus, &dev->device); } return 0; @@ -361,7 +366,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf) * list. Call pci_scan_one() for each pci entry found. */ int -rte_eal_pci_scan(struct rte_bus *bus __rte_unused) +rte_eal_pci_scan(struct rte_bus *bus) { int fd; unsigned dev_count = 0; @@ -374,6 +379,10 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) .matches = &matches[0], }; + /* for debug purposes, PCI can be disabled */ + if (internal_config.no_pci) + return 0; + fd = open("/dev/pci", O_RDONLY); if (fd < 0) { RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); @@ -389,7 +398,7 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) } for (i = 0; i < conf_io.num_matches; i++) - if (pci_scan_one(fd, &matches[i]) < 0) + if (pci_scan_one(bus, fd, &matches[i]) < 0) goto error; dev_count += conf_io.num_matches; @@ -407,9 +416,9 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused) } int -pci_update_device(const struct rte_pci_addr *addr) +pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr) { - int fd; + int fd = -1; struct pci_conf matches[2]; struct pci_match_conf match = { .pc_sel = { @@ -427,6 +436,9 @@ pci_update_device(const struct rte_pci_addr *addr) .matches = &matches[0], }; + if (!bus) + goto error; + fd = open("/dev/pci", O_RDONLY); if (fd < 0) { RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); @@ -442,7 +454,7 @@ pci_update_device(const struct rte_pci_addr *addr) if (conf_io.num_matches != 1) goto error; - if (pci_scan_one(fd, &matches[0]) < 0) + if (pci_scan_one(bus, fd, &matches[0]) < 0) goto error; close(fd); @@ -682,3 +694,11 @@ rte_eal_pci_init(void) } return 0; } + +struct rte_bus pci_bus = { + .scan = rte_eal_pci_scan, + .match = rte_eal_pci_match_default, + .probe = rte_eal_pci_probe_default, +}; + +RTE_REGISTER_BUS(pci, pci_bus); diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 469abac..52bf051 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -196,7 +196,7 @@ rte_eal_bus_scan(void) } static int -perform_probe(struct rte_bus *bus __rte_unused, struct rte_driver *driver, +perform_probe(struct rte_bus *bus, struct rte_driver *driver, struct rte_device *device) { int ret; @@ -208,7 +208,7 @@ perform_probe(struct rte_bus *bus __rte_unused, struct rte_driver *driver, return 0; } - ret = driver->probe(driver, device); + ret = bus->probe(driver, device); if (ret < 0) /* One of the probes failed */ RTE_LOG(ERR, EAL, "Probe failed for (%s).\n", driver->name); @@ -234,6 +234,7 @@ rte_eal_bus_probe(void) TAILQ_FOREACH(driver, &bus->driver_list, next) { ret = bus->match(driver, device); if (!ret) { + device->driver = driver; ret = perform_probe(bus, driver, device); if (ret < 0) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index ba84ccb..4093746 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -230,15 +231,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, return 1; } - /* The device is not blacklisted; Check if driver supports it */ - ret = rte_eal_pci_match_default(driver, device); - if (ret) { - /* Match of device and driver failed */ - RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n", - driver->name); - return 1; - } - RTE_LOG(INFO, EAL, " probe driver: %x:%x %s\n", dev->id.vendor_id, dev->id.device_id, dr->driver.name); @@ -322,19 +314,24 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr, * failed, return 1 if no driver is found for this device. */ static int -pci_probe_all_drivers(struct rte_pci_device *dev) +pci_probe_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) { struct rte_pci_driver *dr = NULL; + struct rte_driver *r_dr = NULL; int rc = 0; if (dev == NULL) return -1; + if (!bus) + return -1; + /* Check if a driver is already loaded */ if (dev->driver != NULL) return 0; - TAILQ_FOREACH(dr, &pci_driver_list, next) { + TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + dr = container_of(r_dr, struct rte_pci_driver, driver); rc = rte_eal_pci_probe_one_driver(dr, dev); if (rc < 0) /* negative value is an error */ @@ -353,15 +350,20 @@ pci_probe_all_drivers(struct rte_pci_device *dev) * failed, return 1 if no driver is found for this device. */ static int -pci_detach_all_drivers(struct rte_pci_device *dev) +pci_detach_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev) { struct rte_pci_driver *dr = NULL; + struct rte_driver *r_dr = NULL; int rc = 0; if (dev == NULL) return -1; - TAILQ_FOREACH(dr, &pci_driver_list, next) { + if (!bus) + return -1; + + TAILQ_FOREACH(r_dr, &bus->driver_list, next) { + dr = container_of(r_dr, struct rte_pci_driver, driver); rc = rte_eal_pci_detach_dev(dr, dev); if (rc < 0) /* negative value is an error */ @@ -382,22 +384,31 @@ int rte_eal_pci_probe_one(const struct rte_pci_addr *addr) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; int ret = 0; if (addr == NULL) return -1; + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return -1; + } + /* update current pci device in global list, kernel bindings might have * changed since last time we looked at it. */ - if (pci_update_device(addr) < 0) + if (pci_update_device(bus, addr) < 0) goto err_return; - TAILQ_FOREACH(dev, &pci_device_list, next) { + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; - ret = pci_probe_all_drivers(dev); + ret = pci_probe_all_drivers(bus, dev); if (ret) goto err_return; return 0; @@ -418,20 +429,29 @@ int rte_eal_pci_detach(const struct rte_pci_addr *addr) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; int ret = 0; if (addr == NULL) return -1; - TAILQ_FOREACH(dev, &pci_device_list, next) { + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus is not registered\n"); + return -1; + } + + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); if (rte_eal_compare_pci_addr(&dev->addr, addr)) continue; - ret = pci_detach_all_drivers(dev); + ret = pci_detach_all_drivers(bus, dev); if (ret < 0) goto err_return; - TAILQ_REMOVE(&pci_device_list, dev, next); + rte_eal_bus_remove_device(r_dev); free(dev); return 0; } @@ -469,10 +489,10 @@ rte_eal_pci_probe(void) /* probe all or only whitelisted devices */ if (probe_all) - ret = pci_probe_all_drivers(dev); + ret = pci_probe_all_drivers(NULL, dev); else if (devargs != NULL && devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) - ret = pci_probe_all_drivers(dev); + ret = pci_probe_all_drivers(NULL, dev); if (ret < 0) rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT " cannot be used\n", dev->addr.domain, dev->addr.bus, @@ -482,6 +502,44 @@ rte_eal_pci_probe(void) return 0; } +int +rte_eal_pci_probe_default(struct rte_driver *driver, struct rte_device *device) +{ + int ret = 0; + struct rte_devargs *devargs; + struct rte_pci_device *pci_dev; + struct rte_pci_driver *pci_drv; + + if (!driver || !device) + return -1; + + pci_dev = container_of(device, struct rte_pci_device, device); + pci_drv = container_of(driver, struct rte_pci_driver, driver); + + ret = rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI); + if (ret != 0) { + /* set devargs in PCI structure */ + devargs = pci_devargs_lookup(pci_dev); + if (devargs != NULL && + devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) { + pci_dev->device.devargs = devargs; + } else { + /* Ignore the device */ + return 0; + } + } + + ret = rte_eal_pci_probe_one_driver(pci_drv, pci_dev); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Requested device " PCI_PRI_FMT + " cannot be used\n", pci_dev->addr.domain, + pci_dev->addr.bus, pci_dev->addr.devid, + pci_dev->addr.function); + return ret; + } + return 0; +} + /* dump one device */ static int pci_dump_one_device(FILE *f, struct rte_pci_device *dev) @@ -507,8 +565,17 @@ void rte_eal_pci_dump(FILE *f) { struct rte_pci_device *dev = NULL; + struct rte_device *r_dev = NULL; + struct rte_bus *bus; - TAILQ_FOREACH(dev, &pci_device_list, next) { + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + TAILQ_FOREACH(r_dev, &bus->device_list, next) { + dev = container_of(r_dev, struct rte_pci_device, device); pci_dump_one_device(f, dev); } } @@ -517,14 +584,32 @@ rte_eal_pci_dump(FILE *f) void rte_eal_pci_register(struct rte_pci_driver *driver) { - TAILQ_INSERT_TAIL(&pci_driver_list, driver, next); - rte_eal_driver_register(&driver->driver); + struct rte_bus *bus; + + RTE_VERIFY(driver); + + bus = rte_eal_get_bus("pci"); + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + rte_eal_bus_add_driver(bus, &driver->driver); } /* unregister a driver */ void rte_eal_pci_unregister(struct rte_pci_driver *driver) { - rte_eal_driver_unregister(&driver->driver); - TAILQ_REMOVE(&pci_driver_list, driver, next); + struct rte_bus *bus; + + RTE_VERIFY(driver); + + bus = driver->driver.bus; + if (!bus) { + RTE_LOG(ERR, EAL, "PCI Bus not registered\n"); + return; + } + + rte_eal_bus_remove_driver(&driver->driver); } diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 9e7d8f6..e006d95 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -126,13 +126,15 @@ struct rte_pci_device; * * This function is private to EAL. * + * @param bus + * The PCI bus on which device is connected * @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); +int pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr); /** * Unbind kernel driver for this device diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 9bd8650..e8db5b4 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -102,6 +102,10 @@ typedef int (*bus_scan_t)(struct rte_bus *bus); */ typedef int (*bus_match_t)(struct rte_driver *drv, struct rte_device *dev); +/** TODO + */ +typedef int (*bus_probe_t)(struct rte_driver *drv, struct rte_device *dev); + struct rte_bus { TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */ struct rte_driver_list driver_list; @@ -112,6 +116,7 @@ struct rte_bus { bus_scan_t scan; /**< Scan for devices attached to bus */ bus_match_t match; /**< Match device with drivers associated with the bus */ + bus_probe_t probe; /**< TODO */ }; /** @internal diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 2a5f766..c0a0c6a 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -371,6 +371,9 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, */ int rte_eal_pci_scan(struct rte_bus *bus); +int +rte_eal_pci_probe_default(struct rte_driver *driver, struct rte_device *device); + /** * Match the PCI Driver and Device using the ID Table * diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 01d0cee..ff92de2 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv) if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) rte_panic("Cannot init logs\n"); - if (rte_eal_pci_init() < 0) - rte_panic("Cannot init PCI\n"); - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) rte_panic("Cannot init VFIO\n"); @@ -887,10 +884,6 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); - /* Probe & Initialize PCI devices */ - if (rte_eal_pci_probe()) - rte_panic("Cannot probe PCI\n"); - if (rte_eal_bus_probe()) rte_panic("Cannot probe devices\n"); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index cbd25df..de4ed86 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -267,7 +268,8 @@ pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev) /* Scan one pci sysfs entry, and fill the devices list from it. */ static int -pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) +pci_scan_one(struct rte_bus *bus, const char *dirname, + const struct rte_pci_addr *addr) { char filename[PATH_MAX]; unsigned long tmp; @@ -385,20 +387,24 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) dev->kdrv = RTE_KDRV_NONE; /* device is valid, add in list (sorted) */ - if (TAILQ_EMPTY(&pci_device_list)) { + if (TAILQ_EMPTY(&bus->device_list)) { rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + rte_eal_bus_add_device(bus, &dev->device); } else { struct rte_pci_device *dev2; + struct rte_device *r_dev2; int ret; - TAILQ_FOREACH(dev2, &pci_device_list, next) { + TAILQ_FOREACH(r_dev2, &bus->device_list, next) { + dev2 = container_of(r_dev2, struct rte_pci_device, + device); ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr); if (ret > 0) continue; if (ret < 0) { - TAILQ_INSERT_BEFORE(dev2, dev, next); + rte_eal_bus_insert_device(bus, &dev2->device, + &dev->device); rte_eal_device_insert(&dev->device); } else { /* already registered */ dev2->kdrv = dev->kdrv; @@ -410,14 +416,14 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) return 0; } rte_eal_device_insert(&dev->device); - TAILQ_INSERT_TAIL(&pci_device_list, dev, next); + rte_eal_bus_add_device(bus, &dev->device); } return 0; } int -pci_update_device(const struct rte_pci_addr *addr) +pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr) { char filename[PATH_MAX]; @@ -425,7 +431,7 @@ pci_update_device(const struct rte_pci_addr *addr) pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid, addr->function); - return pci_scan_one(filename, addr); + return pci_scan_one(bus, filename, addr); } /* @@ -479,13 +485,22 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr) * list */ int -rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused) +rte_eal_pci_scan(struct rte_bus *bus_p) { struct dirent *e; DIR *dir; char dirname[PATH_MAX]; struct rte_pci_addr addr; + if (!bus_p) { + RTE_LOG(ERR, EAL, "PCI Bus is not registered\n"); + return -1; + } + + /* for debug purposes, PCI can be disabled */ + if (internal_config.no_pci) + return 0; + dir = opendir(pci_get_sysfs_path()); if (dir == NULL) { RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n", @@ -504,7 +519,7 @@ rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused) snprintf(dirname, sizeof(dirname), "%s/%s", pci_get_sysfs_path(), e->d_name); - if (pci_scan_one(dirname, &addr) < 0) + if (pci_scan_one(bus_p, dirname, &addr) < 0) goto error; } closedir(dir); @@ -765,3 +780,11 @@ rte_eal_pci_init(void) return 0; } + +struct rte_bus pci_bus = { + .scan = rte_eal_pci_scan, + .match = rte_eal_pci_match_default, + .probe = rte_eal_pci_probe_default, +}; + +RTE_REGISTER_BUS(pci, pci_bus); -- 2.7.4