From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id 1B94A91B0 for ; Fri, 22 Jan 2016 15:07:07 +0100 (CET) Received: by mail-wm0-f51.google.com with SMTP id n5so133888907wmn.0 for ; Fri, 22 Jan 2016 06:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xkMa9iIKRhNlwNgPu3CCq0FGiJUYZY+L+YhIZUEpssQ=; b=DoJ8jqLtqsrBNb0l72tZjxHFkKFFxe70i4MVQpL7dyahO5oWK7NTcmzZK47qZCETkv Az9LgN9JELafgcsJ8jUbN9xoicD8/QUj4RvArwvfQBs3LZIOQUx0DKUPbP3kkyVn5fsU JR7t7y/OnNZCfymxcYqzZbVdNUMjDBRhBk3vuo5OQJW164XANOF6DhATqeqHCqC45bZe 4h6n37AqEQelOcT6YDLhOjsE7E1yJGBQi1CjRsprty+4nqJsDA1U1qjY8OBdkjHYRl0L tg8IZGOEfPWNEFbOV6GVZcT5aH+0O0V4dbLyTmJoVluorquE/7ol62fEzx5srWbtnwRl /m8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xkMa9iIKRhNlwNgPu3CCq0FGiJUYZY+L+YhIZUEpssQ=; b=CaXviI9HrFVU656S8Hq9dmTkg5zWDq5k2TtJj6MHrxBJY1EjDMrjviZnVGc3pXkvie yb9NStlvWfcnz4KLywPEMnvcULpGCJY4zAMRrbUyCBCtOTqcEGankcDCVthAt9ja/ppA sdWOWTedJWNNd7GjJEqFI5BuwEUFh4b7aHdUipslwZcbuo89astAe1q5hZBH4jiIgbtG JSmG5zpNe/JvKktSyYrWzGjwSIEGT4r7zyH/smeuDtne2XI1rBnzUZ8A/qO4NZTKQKhW aVuKbrquaXiEZRTP/FnohHGFjxEHW0IUEHFVulXrMVPg4K8kHyM/uAtTeUaYKaB+sM/5 qjpw== X-Gm-Message-State: AG10YOTMuK5RScyUZS7qMiAfNrj9dCjaLJTq75lQN4a//Zpc6epq3aJmNQgVJsR3J2LLarZW X-Received: by 10.28.111.18 with SMTP id k18mr3595278wmc.86.1453471626965; Fri, 22 Jan 2016 06:07:06 -0800 (PST) Received: from gloops.dev.6wind.com (144.77.126.78.rev.sfr.net. [78.126.77.144]) by smtp.gmail.com with ESMTPSA id l194sm3107982wmb.14.2016.01.22.06.07.05 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jan 2016 06:07:06 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Fri, 22 Jan 2016 15:06:58 +0100 Message-Id: <1453471618-29722-3-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453471618-29722-1-git-send-email-david.marchand@6wind.com> References: <1453377431-25850-1-git-send-email-david.marchand@6wind.com> <1453471618-29722-1-git-send-email-david.marchand@6wind.com> Cc: viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v2 2/2] ethdev: move code to common place in 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, 22 Jan 2016 14:07:07 -0000 Move these error logs and checks on detach capabilities in a common place. Signed-off-by: David Marchand --- Changes since v1: - restore EINVAL error code for rte_eth_dev_(at|de)tach lib/librte_ether/rte_ethdev.c | 77 ++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index cab74e0..a45563d 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -514,7 +514,6 @@ rte_eth_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id) return 0; err: - RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n"); return -1; } @@ -525,10 +524,6 @@ 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; - /* check whether the driver supports detach feature, or not */ - if (rte_eth_dev_is_detachable(port_id)) - goto err; - /* get pci address by port id */ if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr)) goto err; @@ -546,7 +541,6 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr) *addr = freed_addr; return 0; err: - RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n"); return -1; } @@ -579,8 +573,6 @@ end: if (args) free(args); - if (ret < 0) - RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n"); return ret; } @@ -590,10 +582,6 @@ rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname) { char name[RTE_ETH_NAME_MAX_LEN]; - /* check whether the driver supports detach feature, or not */ - if (rte_eth_dev_is_detachable(port_id)) - goto err; - /* get device name by port id */ if (rte_eth_dev_get_name_by_port(port_id, name)) goto err; @@ -605,7 +593,6 @@ rte_eth_dev_detach_vdev(uint8_t port_id, char *vdevname) strncpy(vdevname, name, sizeof(name)); return 0; err: - RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n"); return -1; } @@ -614,14 +601,27 @@ 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)) - return -EINVAL; + if ((devargs == NULL) || (port_id == NULL)) { + ret = -EINVAL; + goto err; + } - if (eal_parse_pci_DomBDF(devargs, &addr) == 0) - return rte_eth_dev_attach_pdev(&addr, port_id); - else - return rte_eth_dev_attach_vdev(devargs, port_id); + 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; + } + + return 0; +err: + RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n"); + return ret; } /* detach the device, then store the name of the device */ @@ -629,26 +629,41 @@ int rte_eth_dev_detach(uint8_t port_id, char *name) { struct rte_pci_addr addr; - int ret; + int ret = -1; - if (name == NULL) - return -EINVAL; + if (name == NULL) { + ret = -EINVAL; + goto err; + } + + /* check whether the driver supports detach feature, or not */ + 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) - return ret; + goto err; ret = rte_eth_dev_detach_pdev(port_id, &addr); - if (ret == 0) - snprintf(name, RTE_ETH_NAME_MAX_LEN, - "%04x:%02x:%02x.%d", - addr.domain, addr.bus, - addr.devid, addr.function); + if (ret < 0) + goto err; - return ret; - } else - return rte_eth_dev_detach_vdev(port_id, name); + 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; + } + + return 0; + +err: + RTE_LOG(ERR, EAL, "Driver, cannot detach the device\n"); + return ret; } static int -- 1.9.1