From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0046.outbound.protection.outlook.com [104.47.38.46]) by dpdk.org (Postfix) with ESMTP id 807DE691A for ; Fri, 16 Sep 2016 06:32:46 +0200 (CEST) Received: from BN6PR03CA0029.namprd03.prod.outlook.com (10.175.124.15) by BLUPR0301MB2002.namprd03.prod.outlook.com (10.164.22.16) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.619.10; Fri, 16 Sep 2016 04:32:45 +0000 Received: from BN1AFFO11FD005.protection.gbl (2a01:111:f400:7c10::161) by BN6PR03CA0029.outlook.office365.com (2603:10b6:404:10c::15) 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; Fri, 16 Sep 2016 04:32:45 +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 BN1AFFO11FD005.mail.protection.outlook.com (10.58.52.65) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.619.6 via Frontend Transport; Fri, 16 Sep 2016 04:32:44 +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 u8G4Trfu029256; Thu, 15 Sep 2016 21:32:41 -0700 From: Shreyansh Jain To: CC: , David Marchand , , Thomas Monjalon , Shreyansh Jain Date: Fri, 16 Sep 2016 09:59:49 +0530 Message-ID: <1474000200-16705-15-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474000200-16705-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1474000200-16705-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131184739649064535; (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)(36756003)(85426001)(305945005)(81166006)(97736004)(8676002)(7846002)(189998001)(110136003)(11100500001)(81156014)(19580395003)(8666005)(87936001)(586003)(356003)(48376002)(47776003)(50466002)(5003940100001)(4326007)(575784001)(2906002)(86362001)(50986999)(76176999)(2950100001)(33646002)(19580405001)(8936002)(50226002)(626004)(77096005)(68736007)(5890100001)(2351001)(105606002)(229853001)(92566002)(5660300001)(106466001)(104016004)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0301MB2002; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD005; 1:w5/SiTW/Ah9DIkMZWFyRtjXCPFkht5lalaJsva7wHMUb5MjqvVpuRZwXyyMbb1tlZxbfipg9eM5nLcJvUdYSrKZuk7JopjyEuiYFT0rwwEbhneVlf8jmfQzBhCIar/KubUkZvBpYj+CTk7ZWAJ7M2T9sBWFQ22vJTVvt0cBm180gU6Qk/j6ELtiYGNaaa8KE0TEv1fmUMDaq7iO6tQ+d3LE1GuHN9Rd5lo/0O2eoAW3/+4FcVQglKNSPmImBzAEWwLrv06MnWzlvV8/WkcQrck7BlJUvxJrT519oUGExyU2MeKDe9RiiPqL2uV3MoSm+ExTV64xOMKAOvfdkQ0JLs1v17bqfi7CrpNMLrRgQmX0Mbr4KFf5RzSRMPCYpqiV9opEOSP5I1ZGzYC7bTbAWHOBYCgjAkYzasXQQ2qpVVV1udm2VSt15dZ3FEKli7jgy4RnMOBTnZ3lVOJC8hCnJMOl7zu6MEVGRQPam9PIL0tLdnORPO4jNOJ5l7n/TPsTJjFVOBEghC67CooecunCfG8HTzMp7FRuwXzA8wTbHyhEobfNst0dwmvOFS4gA06s67QGvB/LjmWKXTx9i6qD9YVVXPUyBISMDQLUYxVSnqKdyHerdbt/pXlYVYAc/8hMkLvIOOqO3lANKCwyC2WJUGJvwqcgpUca4j2l8GgmJmyACa8QZjlQhPq0kvEE6iqQhTXPDTpg4M3z4nTj/dsDD+TK/+YuyvhZoq2XvEQmMARw= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 2fd6e8ec-4e87-420f-acf6-08d3ddea8130 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2002; 2:QhD4LKaHCXYr70GgnA5JKnyQ2NmhaAxzFKxVezkkyIpRnECyMbpX0dGoak4n4ZIucPekqCAaAqGTHPZsApJabZKcJs5f6Lbumf02S0vHDxUd0G/sYD/0n9ScItOCcKLIYMx8F3OCB3sf+MqkwqoWa2PAn9oLFI9Nzy+seLcE3IMB7McEq3mXqDbA82gANy8N; 3:4613S79IJOz4/Rq7tWHFIdQKobnvp4dcWezV2mDveezgo7tt8qgdCYdFz1LSzfNoyQW20f43CNN9884jltdMX+MUsTecmzLklCZxyWajANK446noyE7dvaUSnx4/tq9P0JxYN/F0uszLf/G59WormVLLl1J5Jt8nATo0FcAAEkwfcFO6JyZPUXO/ZPXhmm0GhPT9PEDKKGvo5G3qOOL2Luc2hgQYu7wQ0Nx1NLvwnAk= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0301MB2002; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2002; 25:Bq7EyaWOWbqfZ4+TuUsYj0aSYc1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mN9VyQftqbSTx5q12Jgp0UnEymOdRZWprM+xl90KbZtzbiU9Bied1L8Cr3ivj0R53yotm0f4NSBwPuAN8R1SdhR0PA9VK7GvkNd/pKLgIrf3GUCdaos3Ku4HgmchPvvPpxebr1/+axhpgbc6x8p4yHk+hoOuwMvduTQkybwt3f0kLqgh3O4ahfXggLw1ZxcMdFKmHsveTmAiToUoiMjqyT0TnFK5IqoNrEFylRVlK0wc5v6XqJo8vSxzIU6D33pn9a056JLMo+JugMIEIeFJLMjUuOKpje1UuJlBG10rS3zZRUX6lU0qfeCaIDa/5IFaaF0lUn2aGQSnmxpobiNF6+Df4j/oNe5R/OyIqgV/Sbe98WHAh7OVdbYV3uK78t872P3wDF6zTVPtrarkxWWFNp88o3RBgAaXjTQ4GqOTx4OyBQN9zyWT/QtjCKga0aRr2XicVA6k4XS383D2h5yXvHekG+gYkO+GG80Y5LAxV94nPiqso0AL3fj1FHI+DXgQKlNvg2PbeJ+YfJqYAw+/mgxuGYfMLty3iQTeY0YiqIfbcqVHAmnODOpRoA== 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)(13018025)(8121501046)(5005006)(13017025)(13023025)(13024025)(10201501046)(3002001)(6055026); SRVR:BLUPR0301MB2002; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR0301MB2002; X-Forefront-PRVS: 0067A8BA2A X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0301MB2002; 23:CnEarjOZKI+NNmRkNRBAk/VmPpEv1pA7+VmDUVg?= =?us-ascii?Q?d5hN83HMFkeYg/5bCqZDdAB/n6QwLt0rq28+g5xKs1Dwg/cRcLo59X4kUzKF?= =?us-ascii?Q?wezGFfoEVjNq/P0mc+hxL66SBq+DKu0AhofHrHk1Uko0o/ZgtDSpGRK7QExE?= =?us-ascii?Q?L4LLLvuYPw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8BNnvgPKbjXBLNwbeyRfcHFNjDlYQvAI45LKI8fH5hOMWwyQkVjiIjq780Lp SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2016 04:32:44.7192 (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: BLUPR0301MB2002 Subject: [dpdk-dev] [PATCH v10 14/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, 16 Sep 2016 04:32:47 -0000 From: David Marchand 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 -- v10: - Update incorrect language of log message - Checkpatch issues fixed --- lib/librte_ether/rte_ethdev.c | 207 +++++++----------------------------------- 1 file changed, 35 insertions(+), 172 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 3ef5c84..bec0c2c 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,49 @@ 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) +/* attach the new device, then store port_id of the device */ +int +rte_eth_dev_attach(const char *devargs, uint8_t *port_id) { - /* Invoke probe func of the driver can handle the new device. */ - if (rte_eal_pci_probe_one(addr)) - goto err; + int ret = -1; + int current = eth_dev_last_created_port; + char *name = NULL; + char *args = NULL; - if (rte_eth_dev_get_port_by_addr(addr, port_id)) + if ((devargs == NULL) || (port_id == NULL)) { + ret = -EINVAL; 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)) + /* parse devargs, then retrieve device name and args */ + if (rte_eal_parse_devargs_str(devargs, &name, &args)) 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) + ret = rte_eal_dev_attach(name, args); + if (ret < 0) goto err; - /* invoke remove func of the pci driver, - * also remove the device from pci_device_list */ - if (rte_eal_pci_detach(&freed_addr)) + /* no point looking at eth_dev_last_created_port if no port exists */ + if (!nb_ports) { + RTE_LOG(ERR, EAL, "No ports found for device (%s)\n", name); + ret = -1; 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 nothing happened, there is a bug here, since some driver told us + * it did attach a device, but did not create a port. */ - 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; - - if ((devargs == NULL) || (port_id == NULL)) { - ret = -EINVAL; + if (current == eth_dev_last_created_port) { + ret = -1; 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; - } + *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 +468,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 +475,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