Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 1/2] shared/sec: refactor public funcs of capability
Date: Mon,  1 Jul 2019 13:11:55 +0900	[thread overview]
Message-ID: <20190701041156.34004-2-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190701041156.34004-1-yasufum.o@gmail.com>

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

This update is to rename public functions `port_capability.c` and
`port_capability.h` for refactoring. It also includes revising
variables, structures or comments of them.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/mirror/mir_cmd_runner.c                   |  2 +-
 src/mirror/spp_mirror.c                       |  4 +-
 src/pcap/spp_pcap.c                           |  2 +-
 .../spp_worker_th/cmd_res_formatter.c         |  2 +-
 .../secondary/spp_worker_th/port_capability.c | 88 +++++++++++--------
 .../secondary/spp_worker_th/port_capability.h | 43 ++++-----
 src/vf/classifier_mac.c                       |  3 +-
 src/vf/forwarder.c                            |  3 +-
 src/vf/spp_vf.c                               |  2 +-
 src/vf/vf_cmd_runner.c                        |  2 +-
 10 files changed, 82 insertions(+), 69 deletions(-)

diff --git a/src/mirror/mir_cmd_runner.c b/src/mirror/mir_cmd_runner.c
index 7c9a240..3f90e9a 100644
--- a/src/mirror/mir_cmd_runner.c
+++ b/src/mirror/mir_cmd_runner.c
@@ -389,7 +389,7 @@ update_comp_info(struct sppwk_comp_info *p_comp_info, int *p_change_comp)
 			continue;
 
 		comp_info = (p_comp_info + cnt);
-		spp_port_ability_update(comp_info);
+		sppwk_update_port_dir(comp_info);
 
 		ret = update_mirror(comp_info);
 		RTE_LOG(DEBUG, MIR_CMD_RUNNER, "Update mirror.\n");
diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c
index 4c2b90c..37327c7 100644
--- a/src/mirror/spp_mirror.c
+++ b/src/mirror/spp_mirror.c
@@ -288,7 +288,7 @@ change_mirror_index(int id)
 	struct mirror_info *info = &g_mirror_info[id];
 	if (info->ref_index == info->upd_index) {
 	/* Change reference index of port ability. */
-		spp_port_ability_change_index(PORT_ABILITY_CHG_INDEX_REF, 0, 0);
+		sppwk_swap_two_sides(SPPWK_SWAP_REF, 0, 0);
 		info->ref_index = (info->upd_index+1) % TWO_SIDES;
 	}
 }
@@ -521,7 +521,7 @@ main(int argc, char *argv[])
 			break;
 
 		mirror_proc_init();
-		spp_port_ability_init();
+		sppwk_port_capability_init();
 
 		/* Setup connection for accepting commands from controller */
 		get_spp_ctl_ip(ctl_ip);
diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c
index e32c360..bcce13f 100644
--- a/src/pcap/spp_pcap.c
+++ b/src/pcap/spp_pcap.c
@@ -946,7 +946,7 @@ main(int argc, char *argv[])
 		if (unlikely(ret_mng != 0))
 			break;
 
-		spp_port_ability_init();
+		sppwk_port_capability_init();
 
 		/* Setup connection for accepting commands from controller */
 		get_spp_ctl_ip(ctl_ip);
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 2cc7d42..1485533 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -156,7 +156,7 @@ append_vlan_block(const char *name, char **output,
 		return SPP_RET_NG;
 	}
 
-	spp_port_ability_get_info(port_id, dir, &port_attrs);
+	sppwk_get_port_attrs(&port_attrs, port_id, dir);
 	for (i = 0; i < PORT_ABL_MAX; i++) {
 		switch (port_attrs[i].ops) {
 		case SPPWK_PORT_OPS_ADD_VLAN:
diff --git a/src/shared/secondary/spp_worker_th/port_capability.c b/src/shared/secondary/spp_worker_th/port_capability.c
index ce498fd..30c6e95 100644
--- a/src/shared/secondary/spp_worker_th/port_capability.c
+++ b/src/shared/secondary/spp_worker_th/port_capability.c
@@ -12,20 +12,35 @@
 #include "shared/secondary/return_codes.h"
 #include "ringlatencystats.h"
 
-/* Port ability management information */
-struct port_abl_info {
-	volatile int ref_index; /* Index to reference area. */
-	volatile int upd_index; /* Index to update area. */
+/**
+ * TODO(yasufum) This `port capability` is intended to be used mainly for VLAN
+ * features. However, other features, such as two sides structure of
+ * management info or port direction, are also included this capability.
+ * For the reason, SPP worker processes other spp_vf should include the
+ * capability even if it is not using VLAN. It is a bad design because of
+ * tightly coupled for dependency and it is so confusing.
+ *
+ * This problem should be fixed in a future update.
+ */
+
+/* Port capability management information used as a member of port_mng_info. */
+struct port_capabl_mng_info {
+	/* TODO(yasufum) rename ref_index and upd_index because flag. */
+	/* TODO(yasufum) consider to not use two flags for (0,1) and (1,0). */
+	volatile int ref_index; /* Flag to indicate using reference side. */
+	volatile int upd_index; /* Flag to indicate using update side. */
+
+	/* A set of attrs including sppwk_port_capability. */
+	/* TODO(yasufum) confirm why using PORT_ABL_MAX. */
 	struct sppwk_port_attrs port_attrs[TWO_SIDES][PORT_ABL_MAX];
-				/* Port attributes for spp_vf. */
 };
 
 /* Port ability port information */
 struct port_mng_info {
 	enum port_type iface_type;  /* Interface type (phy, vhost or so). */
 	int iface_no;  /* Interface number. */
-	struct port_abl_info rx;  /* Mng data of port ability for RX. */
-	struct port_abl_info tx;  /* Mng data of port ability for Tx. */
+	struct port_capabl_mng_info rx;  /* Mng data of capability for RX. */
+	struct port_capabl_mng_info tx;  /* Mng data of capability for Tx. */
 };
 
 /* Information for VLAN tag management. */
@@ -34,9 +49,9 @@ struct port_mng_info g_port_mng_info[RTE_MAX_ETHPORTS];
 /* TPID of VLAN. */
 static uint16_t g_vlan_tpid;
 
-/* Initialize port ability. */
+/* Initialize g_port_mng_info, and set ref side to 0 and update side to 1. */
 void
-spp_port_ability_init(void)
+sppwk_port_capability_init(void)
 {
 	int cnt = 0;
 	g_vlan_tpid = rte_cpu_to_be_16(ETHER_TYPE_VLAN);
@@ -49,13 +64,12 @@ spp_port_ability_init(void)
 	}
 }
 
-/* Get information of port ability. */
+/* Get port attributes of given ID and direction from g_port_mng_info. */
 void
-spp_port_ability_get_info(
-		int port_id, enum sppwk_port_dir dir,
-		struct sppwk_port_attrs **info)
+sppwk_get_port_attrs(struct sppwk_port_attrs **p_attrs,
+		int port_id, enum sppwk_port_dir dir)
 {
-	struct port_abl_info *mng = NULL;
+	struct port_capabl_mng_info *mng = NULL;
 
 	switch (dir) {
 	case SPPWK_PORT_DIR_RX:
@@ -68,7 +82,8 @@ spp_port_ability_get_info(
 		/* Not used. */
 		break;
 	}
-	*info = mng->port_attrs[mng->ref_index];
+
+	*p_attrs = mng->port_attrs[mng->ref_index];
 }
 
 /* Calculation and Setting of FCS. */
@@ -190,20 +205,21 @@ del_vlantag_all_packets(
 	return cnt;
 }
 
-/* Change index of management information. */
+/* Swap ref side and update side. */
+/* TODO(yasufum) add desc for this function. */
 void
-spp_port_ability_change_index(
-		enum port_ability_chg_index_type type,
+sppwk_swap_two_sides(
+		enum sppwk_swap_type swap_type,
 		int port_id, enum sppwk_port_dir dir)
 {
 	int cnt;
 	static int num_rx;
-	static int rx_list[RTE_MAX_ETHPORTS];
 	static int num_tx;
+	static int rx_list[RTE_MAX_ETHPORTS];
 	static int tx_list[RTE_MAX_ETHPORTS];
-	struct port_abl_info *mng = NULL;
+	struct port_capabl_mng_info *mng = NULL;
 
-	if (type == PORT_ABILITY_CHG_INDEX_UPD) {
+	if (swap_type == SPPWK_SWAP_UPD) {
 		switch (dir) {
 		case SPPWK_PORT_DIR_RX:
 			mng = &g_port_mng_info[port_id].rx;
@@ -227,14 +243,12 @@ spp_port_ability_change_index(
 		mng->ref_index = (mng->upd_index+1) % TWO_SIDES;
 		rx_list[cnt] = 0;
 	}
+
 	for (cnt = 0; cnt < num_tx; cnt++) {
 		mng = &g_port_mng_info[tx_list[cnt]].tx;
 		mng->ref_index = (mng->upd_index+1) % TWO_SIDES;
 		tx_list[cnt] = 0;
 	}
-
-	num_rx = 0;
-	num_tx = 0;
 }
 
 /* Set ability data of port ability. */
@@ -245,7 +259,7 @@ port_ability_set_ability(struct sppwk_port_info *port,
 	int in_cnt, out_cnt = 0;
 	int port_id = port->ethdev_port_id;
 	struct port_mng_info *port_mng = &g_port_mng_info[port_id];
-	struct port_abl_info *mng = NULL;
+	struct port_capabl_mng_info *mng = NULL;
 	struct sppwk_port_attrs *port_attrs_in = port->port_attrs;
 	struct sppwk_port_attrs *port_attrs_out = NULL;
 	struct sppwk_vlan_tag *tag = NULL;
@@ -290,24 +304,24 @@ port_ability_set_ability(struct sppwk_port_info *port,
 		out_cnt++;
 	}
 
-	spp_port_ability_change_index(PORT_ABILITY_CHG_INDEX_UPD,
-			port_id, dir);
+	sppwk_swap_two_sides(SPPWK_SWAP_UPD, port_id, dir);
 }
 
-/* Update port capability. */
+/* Update port direction of given component. */
 void
-spp_port_ability_update(const struct sppwk_comp_info *component)
+sppwk_update_port_dir(const struct sppwk_comp_info *comp)
 {
 	int cnt;
-	struct sppwk_port_info *port = NULL;
-	for (cnt = 0; cnt < component->nof_rx; cnt++) {
-		port = component->rx_ports[cnt];
-		port_ability_set_ability(port, SPPWK_PORT_DIR_RX);
+	struct sppwk_port_info *port_info = NULL;
+
+	for (cnt = 0; cnt < comp->nof_rx; cnt++) {
+		port_info = comp->rx_ports[cnt];
+		port_ability_set_ability(port_info, SPPWK_PORT_DIR_RX);
 	}
 
-	for (cnt = 0; cnt < component->nof_tx; cnt++) {
-		port = component->tx_ports[cnt];
-		port_ability_set_ability(port, SPPWK_PORT_DIR_TX);
+	for (cnt = 0; cnt < comp->nof_tx; cnt++) {
+		port_info = comp->tx_ports[cnt];
+		port_ability_set_ability(port_info, SPPWK_PORT_DIR_TX);
 	}
 }
 
@@ -334,7 +348,7 @@ port_ability_each_operation(uint16_t port_id,
 	int ok_pkts = nb_pkts;
 	struct sppwk_port_attrs *port_attrs = NULL;
 
-	spp_port_ability_get_info(port_id, dir, &port_attrs);
+	sppwk_get_port_attrs(&port_attrs, port_id, dir);
 	if (unlikely(port_attrs[0].ops == SPPWK_PORT_OPS_NONE))
 		return nb_pkts;
 
diff --git a/src/shared/secondary/spp_worker_th/port_capability.h b/src/shared/secondary/spp_worker_th/port_capability.h
index 5d2a38a..0593f10 100644
--- a/src/shared/secondary/spp_worker_th/port_capability.h
+++ b/src/shared/secondary/spp_worker_th/port_capability.h
@@ -17,45 +17,46 @@
 /** Calculate TCI of VLAN tag. */
 #define SPP_VLANTAG_CALC_TCI(id, pcp) (((pcp & 0x07) << 13) | (id & 0x0fff))
 
-/** Type for changing index. */
-enum port_ability_chg_index_type {
-	PORT_ABILITY_CHG_INDEX_REF,  /** To change index to reference area. */
-	PORT_ABILITY_CHG_INDEX_UPD,  /** To change index to update area. */
+/** Type for swaping sides . */
+enum sppwk_swap_type {
+	SPPWK_SWAP_REF,  /** Swap to reference area. */
+	SPPWK_SWAP_UPD,  /** Swap to update area. */
 };
 
-/** Initialize port ability. */
-void spp_port_ability_init(void);
+/**
+ * Initialize global variable g_port_mng_info, and set ref side to 0 and
+ * update side to 1.
+ */
+void sppwk_port_capability_init(void);
 
 /**
- * Get information of port ability.
+ * Get port attributes of given ID and direction from global g_port_mng_info.
  *
- * @param port_id Etherdev ID.
- * @param rxtx RX/TX ID of port_id.
- * @param info Port ability information.
+ * @param[in,out] p_attrs Port attributes.
+ * @param[in] port_id Etherdev ID.
+ * @param[in] dir Direction of teh port of sppwk_port_dir.
  */
-void spp_port_ability_get_info(
-		int port_id, enum sppwk_port_dir dir,
-		struct sppwk_port_attrs **info);
+void sppwk_get_port_attrs(
+		struct sppwk_port_attrs **p_attrs,
+		int port_id, enum sppwk_port_dir dir);
 
 /**
- * Change index of management information.
+ * Swap ref side and update side.
  *
  * @param port_id Etherdev ID.
  * @param rxtx RX/TX ID of port_id.
  * @param type Type for changing index.
  */
-void spp_port_ability_change_index(
-		enum port_ability_chg_index_type type,
+void sppwk_swap_two_sides(
+		enum sppwk_swap_type swap_type,
 		int port_id, enum sppwk_port_dir dir);
 
 /**
- * Update port capability.
+ * Update port direction of given component.
  *
- * @param component_info
- *  The pointer to struct sppwk_comp_info.@n
- *  The data for updating the internal data of port ability.
+ * @param comp Pointer to sppwk_comp_info.
  */
-void spp_port_ability_update(const struct sppwk_comp_info *component);
+void sppwk_update_port_dir(const struct sppwk_comp_info *comp);
 
 /**
  * Wrapper function for rte_eth_rx_burst() with ring latency feature.
diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c
index 6850962..e41c65a 100644
--- a/src/vf/classifier_mac.c
+++ b/src/vf/classifier_mac.c
@@ -679,8 +679,7 @@ change_classifier_index(struct management_info *mng_info, int id)
 	if (unlikely(mng_info->ref_index ==
 			mng_info->upd_index)) {
 		/* Change reference index of port ability. */
-		spp_port_ability_change_index(PORT_ABILITY_CHG_INDEX_REF,
-									0, 0);
+		sppwk_swap_two_sides(SPPWK_SWAP_REF, 0, 0);
 
 		/* Transmit all packets for switching the using data. */
 		transmit_all_packet(mng_info->cmp_infos + mng_info->ref_index);
diff --git a/src/vf/forwarder.c b/src/vf/forwarder.c
index 77afc4e..cd28a58 100644
--- a/src/vf/forwarder.c
+++ b/src/vf/forwarder.c
@@ -170,8 +170,7 @@ change_forward_index(int id)
 	struct forward_info *info = &g_forward_info[id];
 	if (info->ref_index == info->upd_index) {
 		/* Change reference index of port ability. */
-		spp_port_ability_change_index(
-				PORT_ABILITY_CHG_INDEX_REF, 0, 0);
+		sppwk_swap_two_sides(SPPWK_SWAP_REF, 0, 0);
 
 		info->ref_index = (info->upd_index+1) % TWO_SIDES;
 	}
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 504ee26..dbd47bf 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -248,7 +248,7 @@ main(int argc, char *argv[])
 			break;
 
 		init_forwarder();
-		spp_port_ability_init();
+		sppwk_port_capability_init();
 
 		/* Setup connection for accepting commands from controller */
 		get_spp_ctl_ip(ctl_ip);
diff --git a/src/vf/vf_cmd_runner.c b/src/vf/vf_cmd_runner.c
index 5246af7..520398b 100644
--- a/src/vf/vf_cmd_runner.c
+++ b/src/vf/vf_cmd_runner.c
@@ -529,7 +529,7 @@ update_comp_info(struct sppwk_comp_info *p_comp_info, int *p_change_comp)
 			continue;
 
 		comp_info = (p_comp_info + cnt);
-		spp_port_ability_update(comp_info);
+		sppwk_update_port_dir(comp_info);
 
 		if (comp_info->wk_type == SPPWK_TYPE_CLS) {
 			ret = update_classifier(comp_info);
-- 
2.17.1


  reply	other threads:[~2019-07-01  4:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-01  4:11 [spp] [PATCH 0/2] Refactor port capability yasufum.o
2019-07-01  4:11 ` yasufum.o [this message]
2019-07-01  4:11 ` [spp] [PATCH 2/2] shared/sec: refactor port capability funcs yasufum.o

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=20190701041156.34004-2-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@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).