From patchwork Thu Feb 2 22:33:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wiles, Keith" X-Patchwork-Id: 20136 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id BC1A769C6; Thu, 2 Feb 2017 23:34:28 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id B412B1150 for ; Thu, 2 Feb 2017 23:34:06 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP; 02 Feb 2017 14:34:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,326,1477983600"; d="scan'208";a="38993010" Received: from rkitson-mobl2.amr.corp.intel.com ([10.252.141.150]) by orsmga002.jf.intel.com with ESMTP; 02 Feb 2017 14:34:04 -0800 From: Keith Wiles To: dev@dpdk.org Cc: pascal.mazon@6wind.com Date: Thu, 2 Feb 2017 16:33:27 -0600 Message-Id: <20170202223330.39240-2-keith.wiles@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170202223330.39240-1-keith.wiles@intel.com> References: <20170202223330.39240-1-keith.wiles@intel.com> Subject: [dpdk-dev] [PATCH 2/5] net/tap: fix multi-queue support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Keith Wiles --- drivers/net/tap/rte_eth_tap.c | 93 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 3f179c3..9ed7a87 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -115,10 +115,9 @@ struct pmd_internals { * supplied name. */ static int -tun_alloc(char *name) +tun_alloc(char *name, uint16_t qid) { struct ifreq ifr; - unsigned int features; int fd; memset(&ifr, 0, sizeof(struct ifreq)); @@ -133,55 +132,57 @@ tun_alloc(char *name) goto error; } - /* Grab the TUN features to verify we can work */ - if (ioctl(fd, TUNGETFEATURES, &features) < 0) { - RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n"); - goto error; - } - RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features); + /* This can only be done once per interface */ + if (qid == 0) { + unsigned int features; + + /* Grab the TUN features to verify we can work */ + if (ioctl(fd, TUNGETFEATURES, &features) < 0) { + RTE_LOG(ERR, PMD, "Unable to get TUN/TAP features\n"); + goto error; + } + RTE_LOG(DEBUG, PMD, "TUN/TAP Features %08x\n", features); #ifdef IFF_MULTI_QUEUE - if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) { - RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n"); - goto error; - } else if ((features & IFF_ONE_QUEUE) && - (RTE_PMD_TAP_MAX_QUEUES == 1)) { - ifr.ifr_flags |= IFF_ONE_QUEUE; - RTE_LOG(DEBUG, PMD, "Single queue only support\n"); - } else { - ifr.ifr_flags |= IFF_MULTI_QUEUE; - RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n", - RTE_PMD_TAP_MAX_QUEUES); - } + if (!(features & IFF_MULTI_QUEUE) && (RTE_PMD_TAP_MAX_QUEUES > 1)) { + RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n"); + goto error; + } else if ((features & IFF_ONE_QUEUE) && + (RTE_PMD_TAP_MAX_QUEUES == 1)) { + ifr.ifr_flags |= IFF_ONE_QUEUE; + RTE_LOG(DEBUG, PMD, "Single queue only support\n"); + } else { + ifr.ifr_flags |= IFF_MULTI_QUEUE; + RTE_LOG(DEBUG, PMD, "Multi-queue support for %d queues\n", + RTE_PMD_TAP_MAX_QUEUES); + } #else - if (RTE_PMD_TAP_MAX_QUEUES > 1) { - RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n"); - goto error; - } else { - ifr.ifr_flags |= IFF_ONE_QUEUE; - RTE_LOG(DEBUG, PMD, "Single queue only support\n"); - } + if (RTE_PMD_TAP_MAX_QUEUES > 1) { + RTE_LOG(DEBUG, PMD, "TUN/TAP device only one queue\n"); + goto error; + } else { + ifr.ifr_flags |= IFF_ONE_QUEUE; + RTE_LOG(DEBUG, PMD, "Single queue only support\n"); + } #endif - /* Set the TUN/TAP configuration and get the name if needed */ - if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) { - RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n", - ifr.ifr_name); - perror("TUNSETIFF"); - goto error; - } + /* Set the TUN/TAP configuration and get the name if needed */ + if (ioctl(fd, TUNSETIFF, (void *)&ifr) < 0) { + RTE_LOG(ERR, PMD, "Unable to set TUNSETIFF for %s\n", + ifr.ifr_name); + perror("TUNSETIFF"); + goto error; + } - /* Always set the file descriptor to non-blocking */ - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - RTE_LOG(ERR, PMD, "Unable to set to nonblocking\n"); - perror("F_SETFL, NONBLOCK"); - goto error; + /* Always set the file descriptor to non-blocking */ + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { + RTE_LOG(WARNING, PMD, "Unable to set %s to nonblocking\n", + ifr.ifr_name); + perror("F_SETFL, NONBLOCK"); + goto error; + } } - /* If the name is different that new name as default */ - if (name && strcmp(name, ifr.ifr_name)) - snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s", ifr.ifr_name); - return fd; error: @@ -512,7 +513,7 @@ tap_setup_queue(struct rte_eth_dev *dev, if (fd < 0) { RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n", pmd->name, qid); - fd = tun_alloc(pmd->name); + fd = tun_alloc(pmd->name, qid); if (fd < 0) { RTE_LOG(ERR, PMD, "tun_alloc(%s) failed\n", pmd->name); return -1; @@ -711,7 +712,7 @@ eth_dev_tap_create(const char *name, char *tap_name) snprintf(dev->data->name, sizeof(dev->data->name), "%s", name); /* Create the first Tap device */ - fd = tun_alloc(tap_name); + fd = tun_alloc(tap_name, 0); if (fd < 0) { RTE_LOG(ERR, PMD, "tun_alloc() failed\n"); goto error_exit; @@ -739,6 +740,8 @@ eth_dev_tap_create(const char *name, char *tap_name) error_exit: RTE_PMD_DEBUG_TRACE("Unable to initialize %s\n", name); + if (fd > 0) + close(fd); rte_free(data); rte_free(pmd);