From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0069.outbound.protection.outlook.com [104.47.41.69]) by dpdk.org (Postfix) with ESMTP id A5FFF8DAC for ; Tue, 20 Sep 2016 14:42:44 +0200 (CEST) Received: from BN6PR03CA0030.namprd03.prod.outlook.com (10.175.124.16) by BN6PR03MB2435.namprd03.prod.outlook.com (10.168.223.13) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.629.8; Tue, 20 Sep 2016 12:42:43 +0000 Received: from BN1AFFO11OLC004.protection.gbl (2a01:111:f400:7c10::129) by BN6PR03CA0030.outlook.office365.com (2603:10b6:404:10c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.609.9 via Frontend Transport; Tue, 20 Sep 2016 12:42:43 +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 BN1AFFO11OLC004.mail.protection.outlook.com (10.58.53.75) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Tue, 20 Sep 2016 12:42:43 +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 u8KCexsf006559; Tue, 20 Sep 2016 05:42:40 -0700 From: Shreyansh Jain To: CC: , David Marchand , , Thomas Monjalon , Shreyansh Jain Date: Tue, 20 Sep 2016 18:11:25 +0530 Message-ID: <1474375296-26078-14-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474375296-26078-1-git-send-email-shreyansh.jain@nxp.com> References: <1466510566-9240-1-git-send-email-shreyansh.jain@nxp.com> <1474375296-26078-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131188489635365569; (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)(97736004)(50226002)(11100500001)(92566002)(87936001)(68736007)(5890100001)(36756003)(19580405001)(19580395003)(2950100001)(586003)(4326007)(105606002)(104016004)(85426001)(106466001)(229853001)(5003940100001)(2351001)(77096005)(2906002)(305945005)(626004)(7846002)(5660300001)(8936002)(48376002)(47776003)(86362001)(50986999)(76176999)(110136003)(8676002)(81156014)(189998001)(50466002)(33646002)(8666005)(81166006)(356003)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2435; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11OLC004; 1:EEmABDir5QQqnAvYSj8wduNUeWuTqtjYlhyQrQY5mDHczTATJJ77Fg1g10KiU+uMOwgnIle1mWLKYfP4gqNlxOgpLGIrmipUPjzDW1lDp7HEjmIxc562hFa+a576fN3Ex8w1DuC+3dbGBBJ451qU0wH9yxmdmWOQaMBEKsuGgCK2KD/wmd3LW8mtXlP4v4aZq6a4EDCoNXPQVVTU6OZls/L2Lz8H4AbRhy7bn60i93jIjmPifBqPJiHnyJGUMMB+tGVxEdKlTKXbNb3yJbtgJXYXKEPh4Nzuc5gC8X6URN01YG42Xkc3XBzhCga7cD6QGOa8qBa3oXib+olhfpWhSCH2Qtts8YG1pG0aeceo5FEi30oDXu1miRdu34E4eLU4eeitVFAOgvxgaacMHHPemdxPY6dasIJ4oLGa3HVps30Q6aHiQRRxKSgjhmjKbrp4fpBwrsyTVDMbINwX9391pfT1k3WRhVnqk+tVXlLa1xlmRkSl2HCxzIlMc8x9BO/a2yH2ZCaAHFjXmoXj3KSzFjHzXHFdadlLBGkDRo8g1jc2Emcqi4DpE20+jbiz3YEJ1d0aTuJlwgwXeMew2sS2QjxppOH7cGa9om5Ij2Seq6Rfo0U0OUlj21ZpVTATshxhI33ODIIYB92jnVRgquBPon7ygs7bnIJhyYV97Y2ckpk2GFV368JDibTPC8m2XxsExfOCeLECtDwvw3wd15f0U5QM5ExbuQP6/4oPB++/nYs= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: e95d53f7-fe5c-4290-a164-08d3e1539dca X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2435; 2:6q/SsryaUPZ9J6xmEXPTs1EpejSnebgXx/IgT3uX5ynnj72hyJ6fsLlN+oEqZuaQwvs5FafXMGemT6r+nMkV53Ai/+CVUuHViNI6fnNvfw9daSisAXdb3ydGPVBdzD+Jsxm+0lP0ovcUw0nyAlVVYdRosjYmB8FTgNwrqrEaRohEw5+rO9xr6GcknAlhjPlS; 3:3180TXPJe4A1AW5qjmlVzqMk+7jA6f1t1tH3FQsb154ec7/7+cB7Brn8xsqqdPqcO05RZtBaaZZDXbRpGsvTvZqMH4W/ciqIbvJk63s7j5XQaqv9tLouIgZi8tCPcphWrI2QztgOFtDDLXMEJUX3a/T+PRMGv0yZbRCtLnaywkcNwLOKjLBm5b0Arioc6fE8aPyPnjs0VYnG2B5Lh46Ohm0bRH2xHWfagPzu00RKDO4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN6PR03MB2435; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2435; 25:zRZ32xRiE8dp4cbemNbUNflu7KJAq4EqWz34dxirA/44x2eE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30o7IDuSdCFGupgc9wEREyzXxJHlN6Un4Ru0c+igj/A4pxzK1JRVjysrU1QqmsfcB0WxJbn3Hj5Sqa9DAKHY0P7F3hFqZKrFq/1ui4pZbZBXSSeLP4Ph1Ch0Km9gFs8x+CADyyvhwjgdL2P9bwv9fgyiN82Kaw2flO/w5MHzjrONgDce+YFOOEB9tKIvc00SzmpwBA2OUzzMxosIYt9wrNQuuwwfW3jx+SHd6dYMagwJPMJ67jwcjo3/mk+pDyIRerYKRmlhkKTGIYDrQcoM+nebpo98xqqE3YPyFXC/gvYsNNnhMnOdXci79YW1764BsQ5HJ4ZnrkaqRcMVYfblK0PhzADDhd0LYsGEcVjzSBftGszFRHNaznZPFkxHmUW3v5Djm8PfZ3EOaa+X6QEKoy/qYL9j1U8ukUQ7kluCuK1hICV/RNpcb4QlzUAeMAcnkX0yfNcILpwhyJsJtrSxpe7sUeqFKeSTqR2eBUA6on59ZV7mbozME59iAhh0XCv1leuN0rgZldlVSw1uvq9uQyKzcg== 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)(13017025)(13024025)(13015025)(13023025)(13018025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:BN6PR03MB2435; BCL:0; PCL:0; RULEID:(400006); SRVR:BN6PR03MB2435; X-Forefront-PRVS: 0071BFA85B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2435; 23:eZBHGgBNJrr1enAlNalcOcREJM9bK32/Ad4BeRQvT?= =?us-ascii?Q?15JIJnzAqHm8TmLlu5gMiZN5ZVQ3g623dgjxhx0leoNx6A+QEzqEZa5Axxrz?= =?us-ascii?Q?R/5jA1pC9I6kxjx1LSNFuVoT4iQzPex5cDQnf4F2cq7s5ly3kDmSPcjGHggh?= =?us-ascii?Q?DE12u/hD7LRZXopwSbPJVRUtmGWTBHV586cFPzas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FmzHS3gESa63+yMyN3+Qm1GeZG8/m7TwH+9mOM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2016 12:42:43.3337 (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: BN6PR03MB2435 Subject: [dpdk-dev] [PATCH v11 13/24] 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, 20 Sep 2016 12:42:45 -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 11329cf..4f54952 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -71,6 +71,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 */ @@ -215,6 +216,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; } @@ -346,27 +348,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) { @@ -412,34 +393,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; @@ -464,124 +417,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; } @@ -589,7 +467,6 @@ err: int rte_eth_dev_detach(uint8_t port_id, char *name) { - struct rte_pci_addr addr; int ret = -1; if (name == NULL) { @@ -597,33 +474,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