From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46])
 by dpdk.org (Postfix) with ESMTP id A0728D272
 for <dev@dpdk.org>; Tue, 11 Apr 2017 17:45:15 +0200 (CEST)
Received: by mail-wm0-f46.google.com with SMTP id w204so14462337wmd.1
 for <dev@dpdk.org>; Tue, 11 Apr 2017 08:45:15 -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=T9DI+vk9DjVAkYbVAtJcoV/8hWg+vSR7XmXTn9nWP5Y=;
 b=s+6kfdvDM7P49bEA/ca8v1dThrHOX7oVAVg5xLnRkozSrrjPB7WEf3llAfvOPTGhKa
 GGnJH1DHW8Bu+UHRkoY3n4XXQprJxeMiVCq8Jx0tJxJMXtgkg+9KIW8QYzgxxHVlLJRt
 zM1uEDnbZFCsObff+kLSZpikt+IZ5VFMQbauA0PQiCDbhmRZtKmZ8uUERLm46acv9PLz
 Msz1/3qsR6umbd4kh0JxqmMxa0x2PLypgUSCs8DIJpTq0fqHUNH+vpd6TeGsbOuJ41fb
 YdSgkIVpfa8B50gtlthTpRJm15TKjJ6nzdOfpWpMUJCPAhXrekVWc/uD7iY8LfW7Dd5h
 rbiQ==
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=T9DI+vk9DjVAkYbVAtJcoV/8hWg+vSR7XmXTn9nWP5Y=;
 b=NmPHwSMVj5dgKfsjlv+MeSxoz+75PMnyl2DKWqhr5nFZV7uD1AopyvR61uym/5Aqz0
 PcbcaVJG+d69IFc4CubotKK8HF1LEKBWqN+jLQvVVO+nDsy7w8mhqDCVXLD9AHo+NXa4
 WbpxZ5h2QSN4AU9a2jr3Ai/wDmqwMdExn+zRmmw+BG6CIOVPpi7v8Zkl0X7ueUFiMzaS
 W5uwmY0AlzDKr1q5X3N7Dh0dUw7FGeMUZN71eco0LaUNDFy7WYqUBC0IOZX4giE7bkqT
 YxuSMQplg5Xro2otS2xPjiRlMQsjSe+3oIVsSwe20l6EZwdGg7uDEWqL+CXiylDyklHM
 ecgA==
X-Gm-Message-State: AN3rC/5MdRD97biXJrGqLkjyQqdhlLfNSKiXjf3MWiQKJYvbg1fui/rxeCvysOm/ICbcLozZ
X-Received: by 10.28.220.193 with SMTP id t184mr13118106wmg.63.1491925515090; 
 Tue, 11 Apr 2017 08:45:15 -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.14
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 11 Apr 2017 08:45:14 -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:18 +0200
Message-Id: <d0b88a7f4df18b705b8ec031b57e4aee77241180.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 11/42] net/null: 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:16 -0000

From: Jan Blunck <jblunck@infradead.org>

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/null/rte_eth_null.c | 50 ++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 863fcc7..abf3ec7 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -33,6 +33,7 @@
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_vdev.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
 #include <rte_vdev.h>
@@ -477,8 +478,7 @@ static const struct eth_dev_ops ops = {
 static struct rte_vdev_driver pmd_null_drv;
 
 static int
-eth_dev_null_create(const char *name,
-		const unsigned numa_node,
+eth_dev_null_create(struct rte_vdev_device *dev,
 		unsigned packet_size,
 		unsigned packet_copy)
 {
@@ -495,27 +495,25 @@ eth_dev_null_create(const char *name,
 		0xBE, 0xAC, 0x01, 0xFA
 	};
 
-	if (name == NULL)
-		return -EINVAL;
+	if (dev->device.numa_node == SOCKET_ID_ANY)
+		dev->device.numa_node = rte_socket_id();
 
 	RTE_LOG(INFO, PMD, "Creating null ethdev on numa socket %u\n",
-			numa_node);
+		dev->device.numa_node);
 
 	/* now do all data allocation - for eth_dev structure, dummy pci driver
 	 * and internal (private) data
 	 */
-	data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-	if (data == NULL)
-		goto error;
-
-	internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node);
-	if (internals == NULL)
-		goto error;
+	data = rte_zmalloc_socket(rte_vdev_device_name(dev), sizeof(*data), 0,
+		dev->device.numa_node);
+	if (!data)
+		return -ENOMEM;
 
-	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocate(name);
-	if (eth_dev == NULL)
-		goto error;
+	eth_dev = rte_eth_vdev_allocate(dev, sizeof(*internals));
+	if (!eth_dev) {
+		rte_free(data);
+		return -ENOMEM;
+	}
 
 	/* now put it all together
 	 * - store queue data in internals,
@@ -526,6 +524,7 @@ eth_dev_null_create(const char *name,
 	/* NOTE: we'll replace the data element, of originally allocated eth_dev
 	 * so the nulls are local per-process */
 
+	internals = eth_dev->data->dev_private;
 	internals->packet_size = packet_size;
 	internals->packet_copy = packet_copy;
 	internals->port_id = eth_dev->data->port_id;
@@ -535,22 +534,16 @@ eth_dev_null_create(const char *name,
 
 	rte_memcpy(internals->rss_key, default_rss_key, 40);
 
-	data->dev_private = internals;
-	data->port_id = eth_dev->data->port_id;
+	rte_memcpy(data, eth_dev->data, sizeof(*data));
 	data->nb_rx_queues = (uint16_t)nb_rx_queues;
 	data->nb_tx_queues = (uint16_t)nb_tx_queues;
 	data->dev_link = pmd_link;
 	data->mac_addrs = &eth_addr;
-	strncpy(data->name, eth_dev->data->name, strlen(eth_dev->data->name));
 
 	eth_dev->data = data;
 	eth_dev->dev_ops = &ops;
 
-	eth_dev->driver = NULL;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
-	data->kdrv = RTE_KDRV_NONE;
-	data->drv_name = pmd_null_drv.driver.name;
-	data->numa_node = numa_node;
 
 	/* finally assign rx and tx ops */
 	if (packet_copy) {
@@ -562,12 +555,6 @@ eth_dev_null_create(const char *name,
 	}
 
 	return 0;
-
-error:
-	rte_free(data);
-	rte_free(internals);
-
-	return -1;
 }
 
 static inline int
@@ -608,7 +595,6 @@ static int
 rte_pmd_null_probe(struct rte_vdev_device *dev)
 {
 	const char *name, *params;
-	unsigned numa_node;
 	unsigned packet_size = default_packet_size;
 	unsigned packet_copy = default_packet_copy;
 	struct rte_kvargs *kvlist = NULL;
@@ -621,8 +607,6 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
 	params = rte_vdev_device_args(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name);
 
-	numa_node = rte_socket_id();
-
 	if (params != NULL) {
 		kvlist = rte_kvargs_parse(params, valid_arguments);
 		if (kvlist == NULL)
@@ -651,7 +635,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
 			"packet copy is %s\n", packet_size,
 			packet_copy ? "enabled" : "disabled");
 
-	ret = eth_dev_null_create(name, numa_node, packet_size, packet_copy);
+	ret = eth_dev_null_create(dev, packet_size, packet_copy);
 
 free_kvlist:
 	if (kvlist)
-- 
2.1.4