From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0084.outbound.protection.outlook.com [157.56.111.84]) by dpdk.org (Postfix) with ESMTP id EF664C362 for ; Tue, 21 Jun 2016 14:03:18 +0200 (CEST) Received: from BN3PR0301CA0075.namprd03.prod.outlook.com (10.160.152.171) by BN3PR03MB2372.namprd03.prod.outlook.com (10.166.75.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Tue, 21 Jun 2016 12:03:17 +0000 Received: from BL2FFO11FD017.protection.gbl (2a01:111:f400:7c09::179) by BN3PR0301CA0075.outlook.office365.com (2a01:111:e400:401e::43) 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; Tue, 21 Jun 2016 12:03:17 +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 BL2FFO11FD017.mail.protection.outlook.com (10.173.161.35) with Microsoft SMTP Server (TLS) id 15.1.517.7 via Frontend Transport; Tue, 21 Jun 2016 12:03:16 +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 u5LC2TDX004076; Tue, 21 Jun 2016 05:03:14 -0700 From: Shreyansh Jain To: CC: , Date: Tue, 21 Jun 2016 17:32:45 +0530 Message-ID: <1466510566-9240-17-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> References: <1454076516-21591-1-git-send-email-david.marchand@6wind.com> <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131109841970805980; (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)(339900001)(199003)(189002)(110136002)(76176999)(19580395003)(189998001)(106466001)(8936002)(2351001)(50986999)(229853001)(105606002)(104016004)(2906002)(5890100001)(69596002)(356003)(8676002)(11100500001)(81156014)(68736007)(7846002)(50226002)(81166006)(6806005)(36756003)(5003940100001)(2950100001)(586003)(77096005)(86362001)(19580405001)(50466002)(33646002)(48376002)(47776003)(4326007)(87936001)(85426001)(92566002)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2372; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD017; 1:Lj5j4UzI/gwxtoJtB44D/6uzeGWuMYmPtQxDYZrKoSveJQZv/MIN4VLAC23RHYcVOXGsarVfdw14ep+l9EJd29MlHL8D9A+di/WV0q6DlRiURihcWIRtBLfwSYsRcRnbfzNqyxhrq11IVpo+++th/atfFmgpDomLT3BdSJPnVKdRG0m5pnTzdFugUeYjQT/Yv0Evn+ibG+YdwiA5nWFT4c6L6dnwJEldGEQKbtdQYKUdGxrGp4hMPZMgOgaIqXhlN1o0nq0od65FPLy0AHfOttk56Xkw8FJNvmdAW5uY7EL8cLUwo4P6v6lr8vtt0gFdyGpaoYtmz+HeCCR92c/lMUGumf4qkrMz2L+b/IdzTLT/YM2tDQA9ZjSCEVlpBigtpdJ1ST93GQGbFM+ozglHwsdwdADCfwEjRMy+/z6nac3N0xkO63sQiKcLa/RtsCt0EUDJs5YGUo3XwOQ85g1zAqCuWMUII4vdeyxvAuGaQdEl5e8kNDYgZQzk00+fUhOWzP6PLFOQ123pu+6OS2LSM44rN71lvp/4ZAIC974pDaMRTUAMI97tuJ32mbKaWez0d/OrUxVgqGX4WM3P0H044g== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 034eb9a8-f283-49e6-db7a-08d399cc07ae X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 2:PKfLHEBw2VfbxpNYBwH5rAOuhFmX2ATJ7Za7TaGLvIOuXU2XK8lnbOzAnuYmkFqqd9i9p9ktR0yPK6GRWUrGFA1rhWf5ZWI9ycMDv7cyKww3Ifhs6NOucPEKWrretJHrbUKNVlyoQU+IFRjBE95YDXwkYotufAcGf2sziaCEWyeWhvkgErqaEqThU91kyICT; 3:Zi38jvaYe3oKw/XlQ8OfRJ7JKZxv0Faq9RWU/ha3aYke/4Kr/x386oS94NJgEqlsT2N5J+B234jFYuVxjPjkf6uUEYtGuhH4L/bnveiy6ijjIdgb/IhWWWZXRjsc58/ex/5g7BGw7P1sPBIl3Hv1AS30zfsy8geEVdcnszWJruVGOc1Jn3hjoXNGg3kEcIdG0KkeaIbWzc7eLNxqBaAQkgXPgeApsA8qMeubC+MEj+4=; 25:2fFT+7ACEGzOYYho0qzxZxWdRENpAfj4gAbl5+kbJBP4Ehbntgy4fYgBZKqqn5cq/WTNxlsEy5GvWBd1jmk5es+Qgf+f9aB/tgKnZcpkWbBwAwfLTZDci2R70XQbTMUp8w04BQ51PNBckKWIXjALCEPuc+8Hh3KSbIyxnwzVAdyWHp3rhRsAT/Fg1Pgp/yJnyIssUY4tHFbxMClYHA/hXqNeRbzfkSdTssxFMHe5RBxBt8sQQkBpBaMk2M3jCMU/yl1QAcXD40kj+1NRzzvFDMUixHihTGmNuwvoImRdIuj0rBsZ3IRmGeO13A7Y0YpRASBTSDDU404lfD8pbGEG0j1zMc5CEsDE34IGHPY9caIE6WzhbQ/DvzIDIbBWvhhURx038MsrkZLeWzONSiV7JYy2iK1yfslMnEK7MIvQeWQ= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2372; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(278428928389397)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(13017025)(13024025)(13023025)(13015025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:BN3PR03MB2372; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2372; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2372; 4:zWlUoZfWb6WkrrrdZjNt6dvdN3ebkYU7NiIXU0IitcmyLIOOELAEarjavx+/gI9ld3I3IbyODzwysZYTT9By5TcYY00uU6aIFmNkeWN7G7PjLcybEe2k/E8LRprLsgdfdwni2LMpbxwAwNQNdnipEGS1NBkIaz/aYloVWJAZY4psyWKieA77KWGKKY5VemKcGDTQHX/8pWifLGgw+0A8MY6y+oRjZsc14CD5qvFTQdmZwOg7ySbw5gyh1ueDkLLkyHHhA58MW4mC9XDzgsYknPQiliv2LcmQ9LQsYcfNzi4UZHrUxwVUeQP/UmJmifDlVukSG1tfChKDazfMlyTD0UHIUtlPU8tVk4+ABNHMCfnqExtw6eZV25S1nQU0TtsYxGJYPOjDgJgdbNWR/3+5A93fL3JDjIDzvuHvwMWW58z19I2F+sB2seX0tIIH5QgvrKrTJztLoDbHN7Pnsa2nOoukV9f/c3e9FCpJCZzEE3eScULtpKPRLby6bLJdvdXgZKPSi2cCfKls2L0+bibW5YRoPVJIo9guf0dB3g+y3LomMicdsGnshiybXPf/xiYA X-Forefront-PRVS: 098076C36C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB2372; 23:mKQORYuX8uLT1wpnzJ70S0DlzsyY2wsXWPuPVcsmY?= =?us-ascii?Q?tNEY9zFN/KpiA71d/Jg4j2cpgmy1cupyoqgYn2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Dms7cIXY9OnEVkXfsTt1sp/hrObhUOxvbN0DLQ80Va SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2016 12:03:16.8465 (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: BN3PR03MB2372 Subject: [dpdk-dev] [PATCH v4 16/17] 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: Tue, 21 Jun 2016 12:03:19 -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 | 158 +++++++++--------------------------------- 1 file changed, 33 insertions(+), 125 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 6f2b169..28604ca 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; } @@ -465,124 +467,45 @@ 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) { + 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 +513,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 +520,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