Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH] shared/sec: parse port type while init ports
@ 2019-07-18  5:00 yasufum.o
  0 siblings, 0 replies; 2+ messages in thread
From: yasufum.o @ 2019-07-18  5:00 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

As previous patch, fix registering ports on host as phy type even if
it is added with `--vdev` option.

This patch is to fix parsing ports defined in init_host_port_info()
which is called from spp_vf and spp_mirror. Spp_pcap is still not fixed
yet.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/nfv/main.c                                |  2 +-
 .../spp_worker_th/cmd_res_formatter.c         |  2 +-
 .../secondary/spp_worker_th/cmd_utils.c       | 64 +++++++++++++------
 .../secondary/spp_worker_th/cmd_utils.h       |  9 ++-
 4 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/src/nfv/main.c b/src/nfv/main.c
index eb25d13..c0126a4 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -253,7 +253,7 @@ main(int argc, char *argv[])
 		rte_eth_dev_get_name_by_port(i, dev_name);
 		ret = parse_dev_name(dev_name, &port_type, &port_id);
 		if (ret < 0)
-			RTE_LOG(ERR, SPP_NFV, "Failed to parse dev_name.");
+			RTE_LOG(ERR, SPP_NFV, "Failed to parse dev_name.\n");
 		if (port_type == PHY) {
 			port_id = nof_phy_port;
 			nof_phy_port++;
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index 00d9466..de7acaf 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -202,7 +202,7 @@ get_ethdev_port_id(enum port_type iface_type, int iface_no)
 	sppwk_get_mng_data(&iface_info, NULL, NULL, NULL, NULL, NULL);
 	switch (iface_type) {
 	case PHY:
-		return iface_info->nic[iface_no].ethdev_port_id;
+		return iface_info->phy[iface_no].ethdev_port_id;
 	case RING:
 		return iface_info->ring[iface_no].ethdev_port_id;
 	case VHOST:
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.c b/src/shared/secondary/spp_worker_th/cmd_utils.c
index e77dbe7..7797a71 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.c
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.c
@@ -158,7 +158,7 @@ get_sppwk_port(enum port_type iface_type, int iface_no)
 
 	switch (iface_type) {
 	case PHY:
-		return &iface_info->nic[iface_no];
+		return &iface_info->phy[iface_no];
 	case VHOST:
 		return &iface_info->vhost[iface_no];
 	case RING:
@@ -231,7 +231,7 @@ log_interface_info(const struct iface_info *iface_info)
 			iface_info->nof_vhosts,
 			iface_info->nof_rings);
 	for (cnt = 0; cnt < RTE_MAX_ETHPORTS; cnt++) {
-		port = &iface_info->nic[cnt];
+		port = &iface_info->phy[cnt];
 		if (port->iface_type == UNDEF)
 			continue;
 
@@ -357,10 +357,10 @@ init_iface_info(void)
 	struct iface_info *p_iface_info = g_mng_data.p_iface_info;
 	memset(p_iface_info, 0x00, sizeof(struct iface_info));
 	for (port_cnt = 0; port_cnt < RTE_MAX_ETHPORTS; port_cnt++) {
-		p_iface_info->nic[port_cnt].iface_type = UNDEF;
-		p_iface_info->nic[port_cnt].iface_no = port_cnt;
-		p_iface_info->nic[port_cnt].ethdev_port_id = -1;
-		p_iface_info->nic[port_cnt].cls_attrs.vlantag.vid =
+		p_iface_info->phy[port_cnt].iface_type = UNDEF;
+		p_iface_info->phy[port_cnt].iface_no = port_cnt;
+		p_iface_info->phy[port_cnt].ethdev_port_id = -1;
+		p_iface_info->phy[port_cnt].cls_attrs.vlantag.vid =
 			ETH_VLAN_ID_MAX;
 		p_iface_info->vhost[port_cnt].iface_type = UNDEF;
 		p_iface_info->vhost[port_cnt].iface_no = port_cnt;
@@ -404,21 +404,48 @@ init_core_info(void)
 	memset(g_mng_data.p_change_core, 0x00, sizeof(int)*RTE_MAX_LCORE);
 }
 
-/* Setup port info of port on host */
+/* Initialize mng data of ports on host */
 static int
-set_nic_interface(void)
+init_host_port_info(void)
 {
-	int nic_cnt = 0;
+	int port_type, port_id;
+	int i, ret;
+	int nof_phys = 0;
+	char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 };
 	struct iface_info *p_iface_info = g_mng_data.p_iface_info;
 
-	/* NIC Setting */
-	p_iface_info->nof_phys = rte_eth_dev_count_avail();
-	if (p_iface_info->nof_phys > RTE_MAX_ETHPORTS)
-		p_iface_info->nof_phys = RTE_MAX_ETHPORTS;
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (!rte_eth_dev_is_valid_port(i))
+			continue;
+
+		rte_eth_dev_get_name_by_port(i, dev_name);
+		ret = parse_dev_name(dev_name, &port_type, &port_id);
+		if (ret < 0)
+			RTE_LOG(ERR, APP, "Failed to parse dev_name.\n");
 
-	for (nic_cnt = 0; nic_cnt < p_iface_info->nof_phys; nic_cnt++) {
-		p_iface_info->nic[nic_cnt].iface_type   = PHY;
-		p_iface_info->nic[nic_cnt].ethdev_port_id = nic_cnt;
+		if (port_type == PHY) {
+			port_id = nof_phys;
+			nof_phys++;
+		}
+
+		switch (port_type) {
+		case PHY:
+			p_iface_info->phy[port_id].iface_type = port_type;
+			p_iface_info->phy[port_id].ethdev_port_id = port_id;
+			break;
+		case VHOST:
+			p_iface_info->vhost[port_id].iface_type = port_type;
+			p_iface_info->vhost[port_id].ethdev_port_id = port_id;
+			break;
+		case RING:
+			p_iface_info->ring[port_id].iface_type = port_type;
+			p_iface_info->ring[port_id].ethdev_port_id = port_id;
+			break;
+		default:
+			RTE_LOG(ERR, APP, "Unsupported port on host, "
+				"type:%d, id:%d.\n",
+				port_type, port_id);
+		}
 	}
 
 	return SPP_RET_OK;
@@ -433,10 +460,9 @@ init_mng_data(void)
 	init_core_info();
 	init_component_info();
 
-	int ret_nic = set_nic_interface();
-	if (unlikely(ret_nic != SPP_RET_OK))
+	int ret = init_host_port_info();
+	if (unlikely(ret != SPP_RET_OK))
 		return SPP_RET_NG;
-
 	return SPP_RET_OK;
 }
 
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h
index 6578cb8..e1775b2 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.h
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.h
@@ -193,11 +193,18 @@ struct sppwk_comp_info {
 };
 
 /* Manage number of interfaces  and port information as global variable. */
+/**
+ * TODO(yasufum) confirm why nof_phys, nof_vhosts and nof_rings are required
+ * not used in anywhere.
+ *
+ * TODO(yasufum) confirm why having arrays of types. it seems OK having
+ * just one array.
+ */
 struct iface_info {
 	int nof_phys;    /* Number of phy ports */
 	int nof_vhosts;  /* Number of vhost ports */
 	int nof_rings;   /* Number of ring ports */
-	struct sppwk_port_info nic[RTE_MAX_ETHPORTS];
+	struct sppwk_port_info phy[RTE_MAX_ETHPORTS];
 	struct sppwk_port_info vhost[RTE_MAX_ETHPORTS];
 	struct sppwk_port_info ring[RTE_MAX_ETHPORTS];
 };
-- 
2.17.1


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

* [spp] [PATCH] shared/sec: parse port type while init ports
@ 2019-07-17  8:39 yasufum.o
  0 siblings, 0 replies; 2+ messages in thread
From: yasufum.o @ 2019-07-17  8:39 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

As previous patch, fix registering ports on host as phy type even if
it is added with `--vdev` option.

This patch is to fix parsing ports defined in init_host_port_info()
which is called from spp_vf and spp_mirror. Spp_pcap is still not fixed
yet.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/nfv/main.c                                |  2 +-
 .../spp_worker_th/cmd_res_formatter.c         |  2 +-
 .../secondary/spp_worker_th/cmd_utils.c       | 64 +++++++++++++------
 .../secondary/spp_worker_th/cmd_utils.h       |  9 ++-
 4 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/src/nfv/main.c b/src/nfv/main.c
index eb25d13..c0126a4 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -253,7 +253,7 @@ main(int argc, char *argv[])
 		rte_eth_dev_get_name_by_port(i, dev_name);
 		ret = parse_dev_name(dev_name, &port_type, &port_id);
 		if (ret < 0)
-			RTE_LOG(ERR, SPP_NFV, "Failed to parse dev_name.");
+			RTE_LOG(ERR, SPP_NFV, "Failed to parse dev_name.\n");
 		if (port_type == PHY) {
 			port_id = nof_phy_port;
 			nof_phy_port++;
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index 00d9466..de7acaf 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -202,7 +202,7 @@ get_ethdev_port_id(enum port_type iface_type, int iface_no)
 	sppwk_get_mng_data(&iface_info, NULL, NULL, NULL, NULL, NULL);
 	switch (iface_type) {
 	case PHY:
-		return iface_info->nic[iface_no].ethdev_port_id;
+		return iface_info->phy[iface_no].ethdev_port_id;
 	case RING:
 		return iface_info->ring[iface_no].ethdev_port_id;
 	case VHOST:
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.c b/src/shared/secondary/spp_worker_th/cmd_utils.c
index e77dbe7..7797a71 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.c
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.c
@@ -158,7 +158,7 @@ get_sppwk_port(enum port_type iface_type, int iface_no)
 
 	switch (iface_type) {
 	case PHY:
-		return &iface_info->nic[iface_no];
+		return &iface_info->phy[iface_no];
 	case VHOST:
 		return &iface_info->vhost[iface_no];
 	case RING:
@@ -231,7 +231,7 @@ log_interface_info(const struct iface_info *iface_info)
 			iface_info->nof_vhosts,
 			iface_info->nof_rings);
 	for (cnt = 0; cnt < RTE_MAX_ETHPORTS; cnt++) {
-		port = &iface_info->nic[cnt];
+		port = &iface_info->phy[cnt];
 		if (port->iface_type == UNDEF)
 			continue;
 
@@ -357,10 +357,10 @@ init_iface_info(void)
 	struct iface_info *p_iface_info = g_mng_data.p_iface_info;
 	memset(p_iface_info, 0x00, sizeof(struct iface_info));
 	for (port_cnt = 0; port_cnt < RTE_MAX_ETHPORTS; port_cnt++) {
-		p_iface_info->nic[port_cnt].iface_type = UNDEF;
-		p_iface_info->nic[port_cnt].iface_no = port_cnt;
-		p_iface_info->nic[port_cnt].ethdev_port_id = -1;
-		p_iface_info->nic[port_cnt].cls_attrs.vlantag.vid =
+		p_iface_info->phy[port_cnt].iface_type = UNDEF;
+		p_iface_info->phy[port_cnt].iface_no = port_cnt;
+		p_iface_info->phy[port_cnt].ethdev_port_id = -1;
+		p_iface_info->phy[port_cnt].cls_attrs.vlantag.vid =
 			ETH_VLAN_ID_MAX;
 		p_iface_info->vhost[port_cnt].iface_type = UNDEF;
 		p_iface_info->vhost[port_cnt].iface_no = port_cnt;
@@ -404,21 +404,48 @@ init_core_info(void)
 	memset(g_mng_data.p_change_core, 0x00, sizeof(int)*RTE_MAX_LCORE);
 }
 
-/* Setup port info of port on host */
+/* Initialize mng data of ports on host */
 static int
-set_nic_interface(void)
+init_host_port_info(void)
 {
-	int nic_cnt = 0;
+	int port_type, port_id;
+	int i, ret;
+	int nof_phys = 0;
+	char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 };
 	struct iface_info *p_iface_info = g_mng_data.p_iface_info;
 
-	/* NIC Setting */
-	p_iface_info->nof_phys = rte_eth_dev_count_avail();
-	if (p_iface_info->nof_phys > RTE_MAX_ETHPORTS)
-		p_iface_info->nof_phys = RTE_MAX_ETHPORTS;
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (!rte_eth_dev_is_valid_port(i))
+			continue;
+
+		rte_eth_dev_get_name_by_port(i, dev_name);
+		ret = parse_dev_name(dev_name, &port_type, &port_id);
+		if (ret < 0)
+			RTE_LOG(ERR, APP, "Failed to parse dev_name.\n");
 
-	for (nic_cnt = 0; nic_cnt < p_iface_info->nof_phys; nic_cnt++) {
-		p_iface_info->nic[nic_cnt].iface_type   = PHY;
-		p_iface_info->nic[nic_cnt].ethdev_port_id = nic_cnt;
+		if (port_type == PHY) {
+			port_id = nof_phys;
+			nof_phys++;
+		}
+
+		switch (port_type) {
+		case PHY:
+			p_iface_info->phy[port_id].iface_type = port_type;
+			p_iface_info->phy[port_id].ethdev_port_id = port_id;
+			break;
+		case VHOST:
+			p_iface_info->vhost[port_id].iface_type = port_type;
+			p_iface_info->vhost[port_id].ethdev_port_id = port_id;
+			break;
+		case RING:
+			p_iface_info->ring[port_id].iface_type = port_type;
+			p_iface_info->ring[port_id].ethdev_port_id = port_id;
+			break;
+		default:
+			RTE_LOG(ERR, APP, "Unsupported port on host, "
+				"type:%d, id:%d.\n",
+				port_type, port_id);
+		}
 	}
 
 	return SPP_RET_OK;
@@ -433,10 +460,9 @@ init_mng_data(void)
 	init_core_info();
 	init_component_info();
 
-	int ret_nic = set_nic_interface();
-	if (unlikely(ret_nic != SPP_RET_OK))
+	int ret = init_host_port_info();
+	if (unlikely(ret != SPP_RET_OK))
 		return SPP_RET_NG;
-
 	return SPP_RET_OK;
 }
 
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h
index 6578cb8..e1775b2 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.h
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.h
@@ -193,11 +193,18 @@ struct sppwk_comp_info {
 };
 
 /* Manage number of interfaces  and port information as global variable. */
+/**
+ * TODO(yasufum) confirm why nof_phys, nof_vhosts and nof_rings are required
+ * not used in anywhere.
+ *
+ * TODO(yasufum) confirm why having arrays of types. it seems OK having
+ * just one array.
+ */
 struct iface_info {
 	int nof_phys;    /* Number of phy ports */
 	int nof_vhosts;  /* Number of vhost ports */
 	int nof_rings;   /* Number of ring ports */
-	struct sppwk_port_info nic[RTE_MAX_ETHPORTS];
+	struct sppwk_port_info phy[RTE_MAX_ETHPORTS];
 	struct sppwk_port_info vhost[RTE_MAX_ETHPORTS];
 	struct sppwk_port_info ring[RTE_MAX_ETHPORTS];
 };
-- 
2.17.1


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

end of thread, other threads:[~2019-07-18  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18  5:00 [spp] [PATCH] shared/sec: parse port type while init ports yasufum.o
  -- strict thread matches above, loose matches on Subject: below --
2019-07-17  8:39 yasufum.o

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