DPDK patches and discussions
 help / color / mirror / Atom feed
From: Paul Atkins <patkins@brocade.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 1/3] null: add a new arg to allow users to specify ether address
Date: Fri, 29 Jan 2016 16:18:11 +0000	[thread overview]
Message-ID: <1454084293-5722-2-git-send-email-patkins@brocade.com> (raw)
In-Reply-To: <1454084293-5722-1-git-send-email-patkins@brocade.com>

Add a new argument to the null driver to allow the user to
specify the ether address to be used instead of the default
which is all zeroes. This also allows the user to specify
an address per device instead of them all using the same
default one.

Signed-off-by: Paul Atkins <patkins@brocade.com>
---
 drivers/net/null/rte_eth_null.c |   59 +++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 77fc988..9483d6a 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -41,15 +41,21 @@
 
 #include "rte_eth_null.h"
 
+#include <cmdline_parse.h>
+#include <cmdline_parse_etheraddr.h>
+
 #define ETH_NULL_PACKET_SIZE_ARG	"size"
 #define ETH_NULL_PACKET_COPY_ARG	"copy"
+#define ETH_NULL_ETH_ADDR_ARG		"eth_addr"
 
 static unsigned default_packet_size = 64;
 static unsigned default_packet_copy;
+static struct ether_addr default_eth_addr = { .addr_bytes = {0} };
 
 static const char *valid_arguments[] = {
 	ETH_NULL_PACKET_SIZE_ARG,
 	ETH_NULL_PACKET_COPY_ARG,
+	ETH_NULL_ETH_ADDR_ARG,
 	NULL
 };
 
@@ -69,6 +75,7 @@ struct null_queue {
 struct pmd_internals {
 	unsigned packet_size;
 	unsigned packet_copy;
+	struct ether_addr eth_addr;
 	unsigned numa_node;
 
 	unsigned nb_rx_queues;
@@ -89,8 +96,6 @@ struct pmd_internals {
 	uint8_t rss_key[40];                /**< 40-byte hash key. */
 };
 
-
-static struct ether_addr eth_addr = { .addr_bytes = {0} };
 static const char *drivername = "Null PMD";
 static struct rte_eth_link pmd_link = {
 	.link_speed = 10000,
@@ -485,11 +490,12 @@ static const struct eth_dev_ops ops = {
 	.rss_hash_conf_get = eth_rss_hash_conf_get
 };
 
-int
-eth_dev_null_create(const char *name,
-		const unsigned numa_node,
-		unsigned packet_size,
-		unsigned packet_copy)
+static int
+eth_dev_null_create_internal(const char *name,
+			     const unsigned numa_node,
+			     unsigned packet_size,
+			     unsigned packet_copy,
+			     struct ether_addr eth_addr)
 {
 	const unsigned nb_rx_queues = 1;
 	const unsigned nb_tx_queues = 1;
@@ -539,6 +545,7 @@ eth_dev_null_create(const char *name,
 	internals->nb_tx_queues = nb_tx_queues;
 	internals->packet_size = packet_size;
 	internals->packet_copy = packet_copy;
+	internals->eth_addr = eth_addr;
 	internals->numa_node = numa_node;
 
 	internals->flow_type_rss_offloads =  ETH_RSS_PROTO_MASK;
@@ -551,7 +558,7 @@ eth_dev_null_create(const char *name,
 	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;
+	data->mac_addrs = &internals->eth_addr;
 	strncpy(data->name, eth_dev->data->name, strlen(eth_dev->data->name));
 
 	eth_dev->data = data;
@@ -583,6 +590,16 @@ error:
 	return -1;
 }
 
+int
+eth_dev_null_create(const char *name,
+		const unsigned numa_node,
+		unsigned packet_size,
+		unsigned packet_copy)
+{
+	return eth_dev_null_create_internal(name, numa_node, packet_size,
+					    packet_copy, default_eth_addr);
+}
+
 static inline int
 get_packet_size_arg(const char *key __rte_unused,
 		const char *value, void *extra_args)
@@ -617,12 +634,24 @@ get_packet_copy_arg(const char *key __rte_unused,
 	return 0;
 }
 
+static inline int
+get_eth_addr_arg(const char *key __rte_unused,
+		 const char *value, void *extra_args)
+{
+	if (value == NULL || extra_args == NULL)
+		return -EINVAL;
+
+	return cmdline_parse_etheraddr(NULL, value, extra_args,
+				       sizeof(struct ether_addr));
+}
+
 static int
 rte_pmd_null_devinit(const char *name, const char *params)
 {
 	unsigned numa_node;
 	unsigned packet_size = default_packet_size;
 	unsigned packet_copy = default_packet_copy;
+	struct ether_addr eth_addr = default_eth_addr;
 	struct rte_kvargs *kvlist = NULL;
 	int ret;
 
@@ -639,7 +668,6 @@ rte_pmd_null_devinit(const char *name, const char *params)
 			return -1;
 
 		if (rte_kvargs_count(kvlist, ETH_NULL_PACKET_SIZE_ARG) == 1) {
-
 			ret = rte_kvargs_process(kvlist,
 					ETH_NULL_PACKET_SIZE_ARG,
 					&get_packet_size_arg, &packet_size);
@@ -648,20 +676,29 @@ rte_pmd_null_devinit(const char *name, const char *params)
 		}
 
 		if (rte_kvargs_count(kvlist, ETH_NULL_PACKET_COPY_ARG) == 1) {
-
 			ret = rte_kvargs_process(kvlist,
 					ETH_NULL_PACKET_COPY_ARG,
 					&get_packet_copy_arg, &packet_copy);
 			if (ret < 0)
 				goto free_kvlist;
 		}
+
+		if (rte_kvargs_count(kvlist, ETH_NULL_ETH_ADDR_ARG) == 1) {
+			ret = rte_kvargs_process(kvlist,
+						 ETH_NULL_ETH_ADDR_ARG,
+						 &get_eth_addr_arg, &eth_addr);
+			if (ret < 0)
+				goto free_kvlist;
+		}
+
 	}
 
 	RTE_LOG(INFO, PMD, "Configure pmd_null: packet size is %d, "
 			"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_internal(name, numa_node, packet_size,
+					   packet_copy, eth_addr);
 
 free_kvlist:
 	if (kvlist)
-- 
1.7.10.4

  reply	other threads:[~2016-01-29 16:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29 16:18 [dpdk-dev] [PATCH 0/3] null driver improvements for testability Paul Atkins
2016-01-29 16:18 ` Paul Atkins [this message]
2016-01-29 16:18 ` [dpdk-dev] [PATCH 2/3] null: add rings to allow user to provide the mbufs for rx/tx Paul Atkins
2016-01-29 16:18 ` [dpdk-dev] [PATCH 3/3] null: add xstats to provide the number of rx polls Paul Atkins
2016-01-29 16:31 ` [dpdk-dev] [PATCH 0/3] null driver improvements for testability Thomas Monjalon
2016-01-29 16:47   ` Paul Atkins
2016-02-17 17:23     ` Bruce Richardson
2016-02-18 12:19       ` Paul Atkins
2016-02-23 15:21         ` Bruce Richardson
2016-02-23 15:24           ` Paul Atkins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454084293-5722-2-git-send-email-patkins@brocade.com \
    --to=patkins@brocade.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).