From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com
 [209.85.128.173]) by dpdk.org (Postfix) with ESMTP id 056CED1F7
 for <dev@dpdk.org>; Tue, 11 Apr 2017 17:45:08 +0200 (CEST)
Received: by mail-wr0-f173.google.com with SMTP id l28so748170wre.0
 for <dev@dpdk.org>; Tue, 11 Apr 2017 08:45:08 -0700 (PDT)
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
 :in-reply-to:references;
 bh=yJFl6/WiMjZYNUyv591FZj9WvHsv0x5kaU8fgprLTkI=;
 b=W1LpajClL1NMRTGnxeEq4sb5WnzylDBCq4d/NIHkWjOxJFV+zIPNwgsve9huH2B4aR
 6KNAGRh6pSgG3enhKjSLiL5CVznhD41MC4fn32/qIFrOr6Bm4mYqUiVeAHoM/gJmK8AY
 tHSPXGMclUe1qAT3/EMhcKfFbIMT21SyjJqIUojFRWKFOoCVnOnFRlWz6C0MuWTS1RSl
 WaCUYjQkywL9z5sZzelYthoprA1ECps6JXiO2PO+UbrEE7NNJ/Aw2ZafiUhh1/u25c11
 i1Bk9dc0naTwlpE+EtOKQiGgdztGXuhasnLWJGvZnBdhjJIHX4bJ78lJCJAyjId1Ak9k
 VT5w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references:in-reply-to:references;
 bh=yJFl6/WiMjZYNUyv591FZj9WvHsv0x5kaU8fgprLTkI=;
 b=L7TGEWa/NAOl4cV0M8nIeemVdhDyHzbDgGG27G2pmW6Mh2//SWz4sTYqQBWiFOXi8u
 mCpsSeVwsr3aDCFCtugobavqQXr5nLyhFJTUeB2hgZhY+14Rcoh7V6KG1B93t0KddB6M
 xxIGeKvvi497QLBCFgMHXcrVCU9JYwFaeLz7KLzqJexmLBNhtXL1koFxAscqXWhWyM7w
 hMWaoeHSr9zAk9LAI5nFmjOGACpOIp+Ak9lVVAH22xm1B3LX+7Mgi7K8OyXbncQw5wLp
 5BcCOFcqMX0vlKQuWbMwuXGOJCv1hTiivzMuq9Kzw1gOe4JRzdfaoMtiKVn96yAha/op
 ZncQ==
X-Gm-Message-State: AN3rC/6cqQFWrVvEItOiZLYPRoCHvcCC/oEiwKus2lfVhBNvbPXdjQA/7z8lGt1yR2y8OYP7
X-Received: by 10.223.181.131 with SMTP id c3mr678786wre.61.1491925508715;
 Tue, 11 Apr 2017 08:45:08 -0700 (PDT)
Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com.
 [62.23.145.78])
 by smtp.gmail.com with ESMTPSA id u63sm2933738wmu.22.2017.04.11.08.45.07
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 11 Apr 2017 08:45:08 -0700 (PDT)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Jan Blunck <jblunck@infradead.org>
Date: Tue, 11 Apr 2017 17:44:12 +0200
Message-Id: <ffabc17ddaa025904ddf43aa665ba4ab6c137f6c.1491924900.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.1.4
In-Reply-To: <cover.1491924900.git.gaetan.rivet@6wind.com>
References: <1488794430-25179-1-git-send-email-jblunck@infradead.org>
 <cover.1491924900.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1491924900.git.gaetan.rivet@6wind.com>
References: <cover.1491924900.git.gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH v2 05/42] net/tap: use ethdev allocation helper
	for virtual devices
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 11 Apr 2017 15:45:09 -0000

From: Jan Blunck <jblunck@infradead.org>

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/tap/rte_eth_tap.c | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 698e14b..206a0d6 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -36,6 +36,7 @@
 #include <rte_common.h>
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_vdev.h>
 #include <rte_kvargs.h>
@@ -1131,12 +1132,13 @@ tap_kernel_support(struct pmd_internals *pmd)
 }
 
 static int
-eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
+eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
+		   char *remote_iface)
 {
 	int numa_node = rte_socket_id();
-	struct rte_eth_dev *dev = NULL;
-	struct pmd_internals *pmd = NULL;
-	struct rte_eth_dev_data *data = NULL;
+	struct rte_eth_dev *dev;
+	struct pmd_internals *pmd;
+	struct rte_eth_dev_data *data;
 	int i;
 
 	RTE_LOG(DEBUG, PMD, "  TAP device on numa %u\n", rte_socket_id());
@@ -1147,22 +1149,14 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 		goto error_exit;
 	}
 
-	pmd = rte_zmalloc_socket(tap_name, sizeof(*pmd), 0, numa_node);
-	if (!pmd) {
-		RTE_LOG(ERR, PMD, "TAP Unable to allocate internal struct\n");
-		goto error_exit;
-	}
-
-	/* name in allocation and data->name must be consistent */
-	snprintf(data->name, sizeof(data->name), "%s", name);
-	dev = rte_eth_dev_allocate(name);
+	dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd));
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
 		goto error_exit;
 	}
 
+	pmd = dev->data->dev_private;
 	snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name);
-
 	pmd->nb_queues = RTE_PMD_TAP_MAX_QUEUES;
 
 	pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -1174,13 +1168,11 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 	}
 
 	/* Setup some default values */
+	rte_memcpy(data, dev->data, sizeof(*data));
 	data->dev_private = pmd;
-	data->port_id = dev->data->port_id;
-	data->mtu = dev->data->mtu;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE | RTE_ETH_DEV_INTR_LSC;
-	data->kdrv = RTE_KDRV_NONE;
-	data->drv_name = pmd_tap_drv.driver.name;
 	data->numa_node = numa_node;
+	data->drv_name = pmd_tap_drv.driver.name;
 
 	data->dev_link = pmd_link;
 	data->mac_addrs = &pmd->eth_addr;
@@ -1189,7 +1181,6 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 
 	dev->data = data;
 	dev->dev_ops = &ops;
-	dev->driver = NULL;
 	dev->rx_pkt_burst = pmd_rx_burst;
 	dev->tx_pkt_burst = pmd_tx_burst;
 
@@ -1236,13 +1227,10 @@ eth_dev_tap_create(const char *name, char *tap_name, char *remote_iface)
 	return 0;
 
 error_exit:
-	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n", name);
+	RTE_LOG(DEBUG, PMD, "TAP Unable to initialize %s\n",
+		rte_vdev_device_name(vdev));
 
 	rte_free(data);
-	rte_free(pmd);
-
-	rte_eth_dev_release_port(dev);
-
 	return -EINVAL;
 }
 
@@ -1343,7 +1331,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
 	RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n",
 		name, tap_name);
 
-	ret = eth_dev_tap_create(name, tap_name, remote_iface);
+	ret = eth_dev_tap_create(dev, tap_name, remote_iface);
 
 leave:
 	if (ret == -1) {
-- 
2.1.4