From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0050.outbound.protection.outlook.com [104.47.33.50]) by dpdk.org (Postfix) with ESMTP id 9C5D75A43 for ; Fri, 26 Aug 2016 15:58:05 +0200 (CEST) Received: from BY2PR03CA043.namprd03.prod.outlook.com (10.141.249.16) by BL2PR03MB1875.namprd03.prod.outlook.com (10.164.115.19) with Microsoft SMTP Server (TLS) id 15.1.403.16; Fri, 26 Aug 2016 13:58:03 +0000 Received: from BY2FFO11FD020.protection.gbl (2a01:111:f400:7c0c::190) by BY2PR03CA043.outlook.office365.com (2a01:111:e400:2c5d::16) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9 via Frontend Transport; Fri, 26 Aug 2016 13:57:59 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.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 BY2FFO11FD020.mail.protection.outlook.com (10.1.14.137) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Fri, 26 Aug 2016 13:58:00 +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 u7QDvHpo023630; Fri, 26 Aug 2016 06:57:57 -0700 From: Shreyansh Jain To: CC: , , , , Shreyansh Jain Date: Fri, 26 Aug 2016 19:26:51 +0530 Message-ID: <1472219823-29486-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472219823-29486-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1472219823-29486-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131166934803399661; (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)(104016004)(2950100001)(8936002)(68736007)(76176999)(87936001)(50986999)(2351001)(47776003)(50226002)(110136002)(36756003)(189998001)(50466002)(48376002)(229853001)(92566002)(85426001)(77096005)(97736004)(19580395003)(7846002)(106466001)(86362001)(356003)(305945005)(626004)(19580405001)(4326007)(5890100001)(5003940100001)(105606002)(8666005)(586003)(2906002)(8676002)(33646002)(81166006)(81156014)(5660300001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR03MB1875; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD020; 1:UFefbQIyzsfsH1pQkzs+zHKUG/cBsK3S4/eSNevXbfPxqqamyc5AYk1npmggXFnGBmXlxX/IItmj3t3Epw+KeDz6+UVyf9fCYMqbtLMIiARvhVywhCNvCBN8+Xg4XnEnIVK+f6OC4jxsIYbAVUtKdFupwQuwECCAZQmZyMynGVBw9XowTz3Xq3lwoplzElNQgcvImikqzv5NI7F/HMqcFsWZRqRsXc394v57Uo2tVtjOpGkjWfnNNMU05dH4EaxZK/0avANdHkli38oR0iTQukFkuWM4MrG6Prl8kkbysSCEC1LYLpDOG+FzHMdyypWKJq59e3RqYk27D1/6a9u43lF1Z36+V7qWMq1g8oENePT/I0NYe4SNRSqMe7h+TWX9fytXisMfXh29ZCFDoj+TAyJ29FrHaKova+xVodH8XLhZbbJf/RV0R3XSrOBLw0Q1NuImxuqlVrC4jcqvApAZH5zm4Z/FsvxcZm4PodP6b/Sjtyb7hBVDt4ZdGvz6ZO5x+mytL/e+a0tOrAPrY7mS+Yi00LukV/i1Ew7HSZwLX45ljvL/AYmEQq9MxnAd9opD63i/ipVPZtK/BHODp0AEJ5t9kHFlB1oz/+35L98tIcxGyZx8D5shOUYyajLsLeAvJcEntuRphR2jCkoc2NAjrJB9mzZ6owxy3Fu7h0MlNj9E/bsMFZ2pL7exB8Yb6jMg7jlVPagERqrqcw/MSwx3brGMAaRIDbv/sJJze5T6o8U= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: b3d7369c-2042-42ac-c3ed-08d3cdb8fdb2 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB1875; 2:454Ied+ZNZT0mW1QoKTjrcMAJ9vZtAtKY+tXizTsEwc67FuzpWE6Gl+HkiKZ/r3+zkB8IqjRz6U4v3gMZJA7bPaRgynvaO5zyJQgChBn51MN8Yob37t0XJ6LIW7FgUqB3GcGW/ZAT/8Jy2MGlc1GNjcH9fpar0QgYNlCo+/Tt+n6Lf93MzHHnwkBF+557hMF; 3:rkaExRaI4PUge95HPmWLw36hXijMm+xVTsallTiJo1ql8U+bRSAHn1aW+BRbZmGFCcnObCwZKVWQL8Ks8ZcAbPsEhKBmxSOJP5zlrqHZsm9LME2DrRLQxbVRVF4HCuNWXDKS67exT1xbH0Lld/Uu7FX/P1P4X0wCK+YJgDi0nnW2XgE39oAOBGeyv9fqkn2SNU+G02DBewvR7tUGF8DrS8Wn0EGAgrAbjgh7OnUqbps=; 25:pud5vJmxJdiy5rCRUUraGso/0FcEqqV5r48efrN+nO4qAgaJZIRlbaXOsm70uajmqECJILdSDHYKdjWyyB7T4EJnghXqU1xzNok76WddqgPid4nxXLwHWrN4sn2VYraGAoRLYhYbT0sLtXImLdJo6b+3F4G765PKu0UqbZsdkaEeFXc4KYrSg4H2HkgSG6reFb4T/NYc1pHiyPT+UHEyC99rVbrResXUU9vovL2kUvpgrqghgNNkqzR7XcwOcEC/ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB1875; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(278428928389397); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13015025)(13024025)(13023025)(13017025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BL2PR03MB1875; BCL:0; PCL:0; RULEID:(400006); SRVR:BL2PR03MB1875; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB1875; 4:e5PM9R7u/l8k+mcmxerX59mnOr3gBv8KkkkZvi7A50y3fea34xztG/dByfZsYAYp+WQWiWmHCYkuiI7EVYSxSP7g7JAehtRlQCxJdi/VlBSZqxItIC193a+HSdNoyQneqtIvtxEXcjHsK/8dymd42+Csoka/i8LHf9dm4HYYe9XrepkM2ZitDjoiibBDgkVx/pyjbRYhJGWmU4lDR2Dk0YY5qlGTtp86DLl7f+RTsDZzaAdWeXt91XTbJWMidtMb6cC/FZbnp3KueCZOe1E7bG1ebo4jBcP4Cx9WP+lLeBVqaGO5ZbytrIsdpqs2EbxihW7TpCzIiUUJlybJ8babJrnfq29u2DUeeVB839/cBxBTJ7CRPKXnn85IJpw4QOTr2THFpkevZotz+9za0NFMnP6q8JIiM4pSleUm4ag8kLpi+wJwNdjCfKnFxVL4LoRfMu3QBqZMzIZNK15evbb9qBzxfR3FbiiTl77kHoqVWQtuUutJ7bWoa82CPb9kkZuTkE0mpqPci99giKn2ES4wUUUQa6BYhjMGCeoCAKKs74J6SQRWfQITJr5YbNNigWf1 X-Forefront-PRVS: 00462943DE X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BL2PR03MB1875; 23:G2xSlhLoQ78NWMgPw/oQxh0hbvSxKiKMlfZYcVlLT?= =?us-ascii?Q?gX5jAeHrLE99moDHoV1iMPjJN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8rFlk6U+DCuhmu57MlMvDAFLQ1oEzpr76XqRv0V9PykofP4x82ZmhJDpn?= =?us-ascii?Q?Y+idkQO2Ih42TjDvS/1Ro0AG59ebU/4sLTgPYxX0zquPDNQJ2f66glSQdjVt?= =?us-ascii?Q?il+f2l1lobktR13mE2yLNE5NGn0QgwVds7BeGMv3vqEBYFr/NqUdBQFnCPbn?= =?us-ascii?Q?4m5FZJFVabTEcjGNT1CqFduv2DSTdlkeMcH5sxd29T6XLovNN1Bg+5rUVz+9?= =?us-ascii?Q?wsAO7VJFRon0YuTaw+GdCSa4RUZJbrXo8Ko?= X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB1875; 5:vsxs9ppFbN0fYykM9nZDIHkv8CnxPXso73ENoLoNG0lgAkBp7buEPwkvEBoZomja74IrkPpNdamIilqZKvGj/2rDFLiZObHZ4i0+uXQq6DRprQhOG6KDYmbILdiLzHan2PNTXr41Ug0cutRNuxkzgvBmfEZ/LlJ0TQu1maYdOX0=; 24:m4UQXEhefxSfdxItv3atjIp591kOBjShM/Uemk/XC7t2L+NKrQJ8CDzPQ9sUHYmeZgH+fil6ktDyKBGF/dKsto5wlQg4fRKjWBCU/wb9kJM= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2016 13:58:00.1371 (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: BL2PR03MB1875 Subject: [dpdk-dev] [PATCH v8 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: Fri, 26 Aug 2016 13:58:06 -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