From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0064.outbound.protection.outlook.com [104.47.33.64]) by dpdk.org (Postfix) with ESMTP id 27E128E89 for ; Wed, 7 Sep 2016 16:10:09 +0200 (CEST) Received: from BY2PR03CA073.namprd03.prod.outlook.com (10.141.249.46) by SN1PR0301MB2015.namprd03.prod.outlook.com (10.163.225.158) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9; Wed, 7 Sep 2016 14:10:05 +0000 Received: from BN1AFFO11FD029.protection.gbl (2a01:111:f400:7c10::192) by BY2PR03CA073.outlook.office365.com (2a01:111:e400:2c5d::46) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9 via Frontend Transport; Wed, 7 Sep 2016 14:10:05 +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 BN1AFFO11FD029.mail.protection.outlook.com (10.58.52.184) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Wed, 7 Sep 2016 14:10:04 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u87E8BCw013556; Wed, 7 Sep 2016 07:10:02 -0700 From: Shreyansh Jain To: CC: , Shreyansh Jain , "David Marchand" Date: Wed, 7 Sep 2016 19:38:05 +0530 Message-ID: <1473257297-7221-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473257297-7221-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1473257297-7221-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131177310051344100; (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)(189002)(199003)(33646002)(5890100001)(50466002)(19580405001)(76176999)(47776003)(50986999)(2950100001)(48376002)(2351001)(19580395003)(106466001)(229853001)(105606002)(2906002)(36756003)(11100500001)(189998001)(4326007)(86362001)(586003)(92566002)(626004)(104016004)(5003940100001)(356003)(97736004)(68736007)(8936002)(8676002)(5660300001)(81166006)(81156014)(110136002)(305945005)(77096005)(8666005)(85426001)(50226002)(7846002)(87936001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR0301MB2015; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD029; 1:cqUwIGB00I4p0kSQgcpIou8KLuRFi+4UllYugXWg7i/q4DJ5mWuwXEroYq2RzaShWEh7xO025b19HzbU9No3DhoD7ZhU/uX9pnfWe9YfbHEXUu0JsRkc0Rph32heehq3xTiIWtQyrF5nErWhs3Ad9QP1UXzXDfKzH9Td2h19Ucben4V6/c5gLa1mgsCHWPbLG3fTrZCWan0pjUCgcbPab4Pql5iwioJjaEXTb5fLcmLHUELYK22DTuiR7tJWAxjyzHkI4sPnhtA8UMNnlWZTzqnxC3PhWA4+7wT23SqNc8RXYEuhSYFpcKM+LIQMdrFBVvdlLJQey7dRmZkHWcB3puuWxpNWxns9YHDSSE/wiAsTxyorV4i4AJmzwJmWsClfmldIcbHx6yfqnHdufcRgM0yWHfH56cx7A3JsPGfbCXLsT6hd18P4JHvFUOr0xGlxyTZMxp3lzD4v74s8gI0ORsv4Re8yMoeNYxlubkxcX2V4obUumJci3JppbJ6aO4ON9D+FMQBN0ijsobUjHP8tsvaW01kjH07mFtP6iv/l6BxcLDSXArRKmpbOyJQeBs7I8H129rH3EJ56Bd5ciYfZ8BHvWRVwZcivxhfKmxWBSF5NsiXIW8j4EU4spgPWJlGx MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6e0393ac-b022-4390-3d83-08d3d728aaa8 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2015; 2:sy5MZK1r1Yd4YD95ZQtF7RYs8JjktPQfNwOrKRUS+TqUJe0/2r6dW3nV4QeXK1WIFiAf6Vp0gYIO/hZUQZxnemMUTwV3KV7DCcOF9zMfWOTpcrztCBeoB0CHZpOqogWqKo9t+BOX3jdUwhUsaMgVof1G1Kq8xHNEDm56uPxvNWK0/F1InNFKbvJ0j6U4DmFb; 3:wUc8J8MAZGv/A1o+PtsTkCMN69ByoQ2ZFkaF5APkp6HspyDauvtvm7d1XyMyzXN1g8uQiS3RrX5daN5CDIOpt9sTRWNGP1ACIxbdCzifpd0x8MAo2p2Kqwk0ANrncotGmE8QnGBaePolj7k9aEymFJcOJxx0Nn7KFCrJYrIbZyUFQx2wKDh1Ss0DpjCcNicFPqb6SvpUbyNRWOaFU9+lyYWVe0aT6nVqE24UnXYb+jo= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB2015; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2015; 25:aewYugmaeQk1R9BtXT3dQg6/LNVTLcFRBVtsEulonyNsPmi37Z3vKB3ixcy9dOkn8fSME2ncoGgfUJAd0drq8jaCcazKJBMv24BG0mj257FW8dmZ76+N5WDmhwTS0YvMH1Jr4YOTN9yeTvzIbAvrfjv380OeA8mOkb9igDIgiKX0OKNltzo9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WmZ/gwNE5avb3Heb91reGPybmKJE8WVSfQM/R7N7IwWsSQALA0u4Iwr/JhaqQDMvUaZNIJVYa215ZPk3/ibERa2HdMIvOsVMy5CQCNBuOjIP22aNIy4QjpiDXzZrTTSkFZdGcn4lpAFQcCWxE9HUv6+6wZvXnra9+0wMOMxQlWAiqvgeiRD+Q7DUui7HhPX5vfiWGCLs65+nawFV+H0KfSSUzUUF2+GFJ6LqLNoSeQwn9dOhfuY15A7VggzAP1bboht+oEvRYjBXV1J3YvcvadCDW23RF0wELFSzWDk8PGWbrRVCIrZNzfokVY9eqLvZfdTAzMm+giPsI1W4vACgxsl0T3GSWCdCJ+wO5Z2xsdBHbL4Kv7sDRen76ne2wdstQrojRg/wuOmujl02Y5i2zyb//e/wEH/lqm8bhA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(13017025)(13023025)(13024025)(13018025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:SN1PR0301MB2015; BCL:0; PCL:0; RULEID:(400006); SRVR:SN1PR0301MB2015; X-Forefront-PRVS: 0058ABBBC7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0301MB2015; 23:dDbIlsyv7a5D1ZzuBFZE2+xl1ZGlxk4X1iru7BZ?= =?us-ascii?Q?wpAkkG/YUacK57RyjnQ0s3MwpBNhFv0dUjF1VeXvZdR9MNe1KndhV+DF0Q8N?= =?us-ascii?Q?k7HtMjaQ7wq/UIJOqMF68INnoS19OR2kXe0IXrhmIdN2OwcpNgRAJ+DwVrtr?= =?us-ascii?Q?hJrajNa3EYcZuA1Ns+qTbSeNYyA0evaz7v/tOcLCjZHcTujdxZp/V4Enmh9e?= =?us-ascii?Q?42i3lUeSLn0R0Cf6+fO+yt3LZWGXzv/J6sVQZUNDQnuVDR9Yukw87/b2+CvI?= =?us-ascii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/bcK5LnJayNAromCyvfCiqo?= =?us-ascii?Q?gXM2CfQZAF1Gtv0NeuSCOyxRneLMug6rVwpef?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2015; 6:us9sncigTKxheiEk7PcChbfEKRG6L0tsTK5YHeGfZ0R5OXAkJtx2n1Uzgar95M951Utr+J7ReIHmf2ahHhm0KtF9iahtQbWcawM9TrednG68/HYg8Qz+kjtw0QFxt8WZOIj3J9nB3gwZhd/oCpy1LX+6TmtRdwRjOAaPGn7NaGT/p7mLlxkD4Gw6py/s+dQk/Sb5skOxSaE3+Hn4hJ38qjRmtj4LevBSu9GNDhfLa8erhYe6TpQpnYNW6O/wWaOd/yGffMG3IIzkR2FrU9UvmfdvODg//Ua0UApycLyMIUE=; 5:x6saAXA9/NOtUIOmE3UiTer9hJP0LVT2Xdv0ZIwW9ZVt0QvCnycl4m97hPTG3O32xe2/GjGtupVmHmGexF3K5Ce85JkPsALawRtDRmJAQtZkAyr4l8duWgxS0NpdA5E89SwheKimAx8W8Hbt30MSygoqJSouNsaap0WkEf4DBNs=; 24:43twaHePimoLY4LdYq1p7dtx7x78N9ZvfF9IlSvXuvnZYNBDk1bSHkN0Y3BAudbOStrvOjvIU4ssspT357wlrBGqtIISrvo7WIxqzAI4y+8=; 7:5RuHm56xtbBfn0b1oaMaLxsdHVml5Iscp0VgqN79beixN2CSGdg8pXzXFuxGpw6cs/d3qXzC/6E4SfASFP2E0vfhl5LKZiqsPsrOlsrkH0zmwK8kvPEM4AQXjaYvjLwttWQaGqRQG9QYdhEhOPbtRnKnNNmjIAahak0LgBuDymjLh+4ZWO5L81Z42dx40Va/5N5fS7oOifJAxouVXvgA7DQ8ZnsgUWq33Vk6FH5AKfZ9sGmGKddWEmWQi4cz1pKL SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2016 14:10:04.9160 (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: SN1PR0301MB2015 Subject: [dpdk-dev] [PATCH v9 13/25] ethdev: convert to eal hotplug 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, 07 Sep 2016 14:10:09 -0000 Remove bus logic from ethdev hotplug by using eal for this. Current api is preserved: - the last port that has been created is tracked to return it to the application when attaching, - the internal device name is reused when detaching. We can not get rid of ethdev hotplug yet since we still need some mechanism to inform applications of port creation/removal to substitute for ethdev hotplug api. dev_type field in struct rte_eth_dev and rte_eth_dev_allocate are kept as is, but this information is not needed anymore and is removed in the following commit. Signed-off-by: David Marchand Signed-off-by: Shreyansh Jain --- lib/librte_ether/rte_ethdev.c | 208 +++++++----------------------------------- 1 file changed, 34 insertions(+), 174 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index fdeac86..86c9d1a 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -72,6 +72,7 @@ static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; static struct rte_eth_dev_data *rte_eth_dev_data; +static uint8_t eth_dev_last_created_port; static uint8_t nb_ports; /* spinlock for eth device callbacks */ @@ -216,6 +217,7 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type) eth_dev->data->port_id = port_id; eth_dev->attached = DEV_ATTACHED; eth_dev->dev_type = type; + eth_dev_last_created_port = port_id; nb_ports++; return eth_dev; } @@ -347,27 +349,6 @@ rte_eth_dev_count(void) return nb_ports; } -static enum rte_eth_dev_type -rte_eth_dev_get_device_type(uint8_t port_id) -{ - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, RTE_ETH_DEV_UNKNOWN); - return rte_eth_devices[port_id].dev_type; -} - -static int -rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr) -{ - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); - - if (addr == NULL) { - RTE_PMD_DEBUG_TRACE("Null pointer is specified\n"); - return -EINVAL; - } - - *addr = rte_eth_devices[port_id].pci_dev->addr; - return 0; -} - int rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) { @@ -413,34 +394,6 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) } static int -rte_eth_dev_get_port_by_addr(const struct rte_pci_addr *addr, uint8_t *port_id) -{ - int i; - struct rte_pci_device *pci_dev = NULL; - - if (addr == NULL) { - RTE_PMD_DEBUG_TRACE("Null pointer is specified\n"); - return -EINVAL; - } - - *port_id = RTE_MAX_ETHPORTS; - - for (i = 0; i < RTE_MAX_ETHPORTS; i++) { - - pci_dev = rte_eth_devices[i].pci_dev; - - if (pci_dev && - !rte_eal_compare_pci_addr(&pci_dev->addr, addr)) { - - *port_id = i; - - return 0; - } - } - return -ENODEV; -} - -static int rte_eth_dev_is_detachable(uint8_t port_id) { uint32_t dev_flags; @@ -465,124 +418,46 @@ rte_eth_dev_is_detachable(uint8_t port_id) return 1; } -/* attach the new physical device, then store port_id of the device */ -static int -rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id) -{ - /* Invoke probe func of the driver can handle the new device. */ - if (rte_eal_pci_probe_one(addr)) - goto err; - - if (rte_eth_dev_get_port_by_addr(addr, port_id)) - goto err; - - return 0; -err: - return -1; -} - -/* detach the new physical device, then store pci_addr of the device */ -static int -rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr) -{ - struct rte_pci_addr freed_addr; - struct rte_pci_addr vp; - - /* get pci address by port id */ - if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr)) - goto err; - - /* Zeroed pci addr means the port comes from virtual device */ - vp.domain = vp.bus = vp.devid = vp.function = 0; - if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0) - goto err; - - /* invoke devuninit func of the pci driver, - * also remove the device from pci_device_list */ - if (rte_eal_pci_detach(&freed_addr)) - goto err; - - *addr = freed_addr; - return 0; -err: - return -1; -} - -/* attach the new virtual device, then store port_id of the device */ -static int -rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id) -{ - char *name = NULL, *args = NULL; - int ret = -1; - - /* parse vdevargs, then retrieve device name and args */ - if (rte_eal_parse_devargs_str(vdevargs, &name, &args)) - goto end; - - /* walk around dev_driver_list to find the driver of the device, - * then invoke probe function of the driver. - * rte_eal_vdev_init() updates port_id allocated after - * initialization. - */ - if (rte_eal_vdev_init(name, args)) - goto end; - - if (rte_eth_dev_get_port_by_name(name, port_id)) - goto end; - - ret = 0; -end: - free(name); - free(args); - - return ret; -} - -/* detach the new virtual device, then store the name of the device */ -static int -rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname) -{ - char name[RTE_ETH_NAME_MAX_LEN]; - - /* get device name by port id */ - if (rte_eth_dev_get_name_by_port(port_id, name)) - goto err; - /* walk around dev_driver_list to find the driver of the device, - * then invoke uninit function of the driver */ - if (rte_eal_vdev_uninit(name)) - goto err; - - strncpy(vdevname, name, sizeof(name)); - return 0; -err: - return -1; -} - /* attach the new device, then store port_id of the device */ int rte_eth_dev_attach(const char *devargs, uint8_t *port_id) { - struct rte_pci_addr addr; int ret = -1; + int current = eth_dev_last_created_port; + char *name = NULL; + char *args = NULL; if ((devargs == NULL) || (port_id == NULL)) { ret = -EINVAL; goto err; } - if (eal_parse_pci_DomBDF(devargs, &addr) == 0) { - ret = rte_eth_dev_attach_pdev(&addr, port_id); - if (ret < 0) - goto err; - } else { - ret = rte_eth_dev_attach_vdev(devargs, port_id); - if (ret < 0) - goto err; + /* parse devargs, then retrieve device name and args */ + if (rte_eal_parse_devargs_str(devargs, &name, &args)) + goto err; + + ret = rte_eal_dev_attach(name, args); + if (ret < 0) + goto err; + + /* no point looking at eth_dev_last_created_port if no port exists */ + if (!nb_ports) { + RTE_LOG(ERR, EAL, "No ports founds for device (%s)\n", name); + ret = -1; + goto err; + } + /* if nothing happened, there is a bug here, since some driver told us + * it did attach a device, but did not create a port */ + if (current == eth_dev_last_created_port) { + ret = -1; + goto err; } + *port_id = eth_dev_last_created_port; + ret = 0; - return 0; err: - RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n"); + free(name); + free(args); return ret; } @@ -590,7 +465,6 @@ err: int rte_eth_dev_detach(uint8_t port_id, char *name) { - struct rte_pci_addr addr; int ret = -1; if (name == NULL) { @@ -598,33 +472,19 @@ rte_eth_dev_detach(uint8_t port_id, char *name) goto err; } - /* check whether the driver supports detach feature, or not */ + /* FIXME: move this to eal, once device flags are relocated there */ if (rte_eth_dev_is_detachable(port_id)) goto err; - if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) { - ret = rte_eth_dev_get_addr_by_port(port_id, &addr); - if (ret < 0) - goto err; - - ret = rte_eth_dev_detach_pdev(port_id, &addr); - if (ret < 0) - goto err; - - snprintf(name, RTE_ETH_NAME_MAX_LEN, - "%04x:%02x:%02x.%d", - addr.domain, addr.bus, - addr.devid, addr.function); - } else { - ret = rte_eth_dev_detach_vdev(port_id, name); - if (ret < 0) - goto err; - } + snprintf(name, sizeof(rte_eth_devices[port_id].data->name), + "%s", rte_eth_devices[port_id].data->name); + ret = rte_eal_dev_detach(name); + if (ret < 0) + goto err; return 0; err: - RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n"); return ret; } -- 2.7.4