Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv
@ 2020-01-26 18:45 Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 1/4] shared/sec: add function add_memif Yasufumi Ogawa
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Yasufumi Ogawa @ 2020-01-26 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

This series of update is to add features for adding or deleting memif
PMD while running to spp_primary and spp_nfv.

Yasufumi Ogawa (4):
  shared/sec: add function add_memif
  spp_primary: enable to add and del memif
  spp_nfv: enable to add and del memif
  cli: add completion for adding memif

 src/cli/spp_common.py           |  2 +-
 src/nfv/commands.h              | 10 +++++
 src/primary/main.c              | 11 +++++
 src/shared/secondary/add_port.c | 76 +++++++++++++++++++++++++++++++++
 src/shared/secondary/add_port.h | 20 +++++++++
 5 files changed, 118 insertions(+), 1 deletion(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH 1/4] shared/sec: add function add_memif
  2020-01-26 18:45 [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv Yasufumi Ogawa
@ 2020-01-26 18:45 ` Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 2/4] spp_primary: enable to add and del memif Yasufumi Ogawa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Yasufumi Ogawa @ 2020-01-26 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

Memif PMD is attached only when launching spp_primary via `--vdev`
option, and cannot attach while running SPP. This update is add_memif()
for adding memif PMD dynamically after launching from not only
spp_primary but also other processes.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/shared/secondary/add_port.c | 76 +++++++++++++++++++++++++++++++++
 src/shared/secondary/add_port.h | 20 +++++++++
 2 files changed, 96 insertions(+)

diff --git a/src/shared/secondary/add_port.c b/src/shared/secondary/add_port.c
index d845250..652ef69 100644
--- a/src/shared/secondary/add_port.c
+++ b/src/shared/secondary/add_port.c
@@ -46,6 +46,14 @@ get_pcap_pmd_name(int id)
 	return buffer;
 }
 
+static inline const char *
+get_memif_pmd_name(int id)
+{
+	static char buffer[sizeof(MEMIF_PMD_DEV_NAME) + 2];
+	snprintf(buffer, sizeof(buffer) - 1, MEMIF_PMD_DEV_NAME, id);
+	return buffer;
+}
+
 static inline const char *
 get_null_pmd_name(int id)
 {
@@ -310,6 +318,74 @@ add_pcap_pmd(int index)
 	return pcap_pmd_port_id;
 }
 
+int
+add_memif_pmd(int index)
+{
+	struct rte_eth_conf port_conf = {
+			.rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN }
+	};
+
+	struct rte_mempool *mp;
+	const char *name;
+	char devargs[64];
+	char sock_fn[32];
+	uint16_t memif_pmd_port_id;
+	uint16_t nr_queues = 1;
+
+	int ret;
+
+	memset(devargs, '\0', sizeof(devargs));
+	memset(sock_fn, '\0', sizeof(sock_fn));
+
+	mp = rte_mempool_lookup(PKTMBUF_POOL_NAME);
+	if (mp == NULL)
+		rte_exit(EXIT_FAILURE, "Cannon get mempool for mbuf\n");
+
+	name = get_memif_pmd_name(index);
+	sprintf(devargs, "%s,id=%d,role=%s,socket=%s",
+			name, index, MEMIF_ROLE, MEMIF_SOCK);
+	RTE_LOG(DEBUG, SHARED, "Devargs for memif: '%s'.\n", devargs);
+	ret = dev_attach_by_devargs(devargs, &memif_pmd_port_id);
+	if (ret < 0)
+		return ret;
+
+	ret = rte_eth_dev_configure(
+			memif_pmd_port_id, nr_queues, nr_queues,
+			&port_conf);
+	if (ret < 0)
+		return ret;
+
+	/* Allocate and set up 1 RX queue per Ethernet port. */
+	uint16_t q;
+	for (q = 0; q < nr_queues; q++) {
+		ret = rte_eth_rx_queue_setup(
+				memif_pmd_port_id, q, NR_DESCS,
+				rte_eth_dev_socket_id(
+					memif_pmd_port_id), NULL, mp);
+		if (ret < 0)
+			return ret;
+	}
+
+	/* Allocate and set up 1 TX queue per Ethernet port. */
+	for (q = 0; q < nr_queues; q++) {
+		ret = rte_eth_tx_queue_setup(
+				memif_pmd_port_id, q, NR_DESCS,
+				rte_eth_dev_socket_id(
+					memif_pmd_port_id),
+				NULL);
+		if (ret < 0)
+			return ret;
+	}
+
+	ret = rte_eth_dev_start(memif_pmd_port_id);
+	if (ret < 0)
+		return ret;
+
+	RTE_LOG(DEBUG, SHARED, "memif port id %d\n", memif_pmd_port_id);
+
+	return memif_pmd_port_id;
+}
+
 int
 add_null_pmd(int index)
 {
diff --git a/src/shared/secondary/add_port.h b/src/shared/secondary/add_port.h
index a75b28b..d686f20 100644
--- a/src/shared/secondary/add_port.h
+++ b/src/shared/secondary/add_port.h
@@ -13,11 +13,20 @@
 #define VHOST_BACKEND_NAME "spp_vhost%u"
 
 #define PCAP_PMD_DEV_NAME "eth_pcap%u"
+#define MEMIF_PMD_DEV_NAME "net_memif%u"
 #define NULL_PMD_DEV_NAME "eth_null%u"
 
 #define PCAP_IFACE_RX "/tmp/spp-rx%d.pcap"
 #define PCAP_IFACE_TX "/tmp/spp-tx%d.pcap"
 
+/**
+ * SPP provides memif for other processes as "master" role and via socket
+ * file "/tmp/spp-memif.sock". Details of memif is described in here.
+ * https://doc.dpdk.org/guides/nics/memif.html
+ */
+#define MEMIF_ROLE "master"
+#define MEMIF_SOCK "/tmp/spp-memif.sock"
+
 #define RTE_LOGTYPE_SHARED RTE_LOGTYPE_USER1
 
 /**
@@ -77,6 +86,17 @@ add_vhost_pmd(int index);
 int
 add_pcap_pmd(int index);
 
+/**
+ * Create a memif PMD with given ID.
+ *
+ * @param port_id
+ *   ID of the next possible valid port.
+ * @return
+ *   Unique port ID
+ */
+int
+add_memif_pmd(int index);
+
 /**
  * Create a null PMD with given ID.
  *
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH 2/4] spp_primary: enable to add and del memif
  2020-01-26 18:45 [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 1/4] shared/sec: add function add_memif Yasufumi Ogawa
@ 2020-01-26 18:45 ` Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 3/4] spp_nfv: " Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 4/4] cli: add completion for adding memif Yasufumi Ogawa
  3 siblings, 0 replies; 5+ messages in thread
From: Yasufumi Ogawa @ 2020-01-26 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

This update is to enable spp_primary to add and del while running.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/primary/main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/primary/main.c b/src/primary/main.c
index 15152a0..d3828e8 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -831,6 +831,11 @@ add_port(char *p_type, int p_id)
 		port_id_list[cnt].port_id = p_id;
 		port_id_list[cnt].type = PCAP;
 
+	} else if (!strcmp(p_type, "memif")) {
+		res = add_memif_pmd(p_id);
+		port_id_list[cnt].port_id = p_id;
+		port_id_list[cnt].type = MEMIF;
+
 	} else if (!strcmp(p_type, "nullpmd")) {
 		res = add_null_pmd(p_id);
 		port_id_list[cnt].port_id = p_id;
@@ -906,6 +911,12 @@ del_port(char *p_type, int p_id)
 			return -1;
 		dev_detach_by_port_id(dev_id);
 
+	} else if (!strcmp(p_type, "memif")) {
+		dev_id = find_ethdev_id(p_id, MEMIF);
+		if (dev_id == PORT_RESET)
+			return -1;
+		dev_detach_by_port_id(dev_id);
+
 	} else if (!strcmp(p_type, "nullpmd")) {
 		dev_id = find_ethdev_id(p_id, NULLPMD);
 		if (dev_id == PORT_RESET)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH 3/4] spp_nfv: enable to add and del memif
  2020-01-26 18:45 [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 1/4] shared/sec: add function add_memif Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 2/4] spp_primary: enable to add and del memif Yasufumi Ogawa
@ 2020-01-26 18:45 ` Yasufumi Ogawa
  2020-01-26 18:45 ` [spp] [PATCH 4/4] cli: add completion for adding memif Yasufumi Ogawa
  3 siblings, 0 replies; 5+ messages in thread
From: Yasufumi Ogawa @ 2020-01-26 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

This update is to enable spp_nfv to add and del while running.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/nfv/commands.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index 7e50c8c..e5b25be 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -41,6 +41,12 @@ do_del(char *p_type, int p_id)
 			return -1;
 		dev_detach_by_port_id(port_id);
 
+	} else if (!strcmp(p_type, "memif")) {
+		port_id = find_port_id(p_id, MEMIF);
+		if (port_id == PORT_RESET)
+			return -1;
+		dev_detach_by_port_id(port_id);
+
 	} else if (!strcmp(p_type, "nullpmd")) {
 		port_id = find_port_id(p_id, NULLPMD);
 		if (port_id == PORT_RESET)
@@ -78,6 +84,10 @@ do_add(char *p_type, int p_id)
 		type = PCAP;
 		res = add_pcap_pmd(p_id);
 
+	} else if (!strcmp(p_type, "memif")) {
+		type = MEMIF;
+		res = add_memif_pmd(p_id);
+
 	} else if (!strcmp(p_type, "nullpmd")) {
 		type = NULLPMD;
 		res = add_null_pmd(p_id);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [spp] [PATCH 4/4] cli: add completion for adding memif
  2020-01-26 18:45 [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv Yasufumi Ogawa
                   ` (2 preceding siblings ...)
  2020-01-26 18:45 ` [spp] [PATCH 3/4] spp_nfv: " Yasufumi Ogawa
@ 2020-01-26 18:45 ` Yasufumi Ogawa
  3 siblings, 0 replies; 5+ messages in thread
From: Yasufumi Ogawa @ 2020-01-26 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

This update is to add `memif` to the list of port types for completion.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/spp_common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cli/spp_common.py b/src/cli/spp_common.py
index 947a2fa..a3108fa 100644
--- a/src/cli/spp_common.py
+++ b/src/cli/spp_common.py
@@ -6,7 +6,7 @@ import logging
 import os
 
 # Type definitions.
-PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
+PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'memif', 'nullpmd']
 SEC_TYPES = ['nfv', 'vf', 'mirror', 'pcap']
 
 # Setup logger object
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-01-26 18:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-26 18:45 [spp] [PATCH 0/4] Add memif allocation for spp_primary adn spp_nfv Yasufumi Ogawa
2020-01-26 18:45 ` [spp] [PATCH 1/4] shared/sec: add function add_memif Yasufumi Ogawa
2020-01-26 18:45 ` [spp] [PATCH 2/4] spp_primary: enable to add and del memif Yasufumi Ogawa
2020-01-26 18:45 ` [spp] [PATCH 3/4] spp_nfv: " Yasufumi Ogawa
2020-01-26 18:45 ` [spp] [PATCH 4/4] cli: add completion for adding memif Yasufumi Ogawa

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).