DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pawel Wodkowski <pawelx.wodkowski@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 1/2] bond: extract common code to separate functions
Date: Wed, 17 Sep 2014 15:21:52 +0100	[thread overview]
Message-ID: <1410963713-13837-2-git-send-email-pawelx.wodkowski@intel.com> (raw)
In-Reply-To: <1410963713-13837-1-git-send-email-pawelx.wodkowski@intel.com>

Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Declan Doherty <declan.doherty@intel.com>
---
 lib/librte_pmd_bond/rte_eth_bond_api.c     |   59 +++++++++++++++++++++-------
 lib/librte_pmd_bond/rte_eth_bond_pmd.c     |   47 ++++++++++++++--------
 lib/librte_pmd_bond/rte_eth_bond_private.h |   30 ++++++++++++--
 3 files changed, 102 insertions(+), 34 deletions(-)

diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c
index dd33119..460df65 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_api.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_api.c
@@ -31,6 +31,8 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <string.h>
+
 #include <rte_mbuf.h>
 #include <rte_malloc.h>
 #include <rte_ethdev.h>
@@ -104,6 +106,39 @@ valid_slave_port_id(uint8_t port_id)
 	return 0;
 }
 
+void
+rte_eth_bond_activate_slave(struct rte_eth_dev *eth_dev, uint8_t port_id )
+{
+	struct bond_dev_private *internals = eth_dev->data->dev_private;
+	uint8_t active_count = internals->active_slave_count;
+
+	internals->active_slaves[active_count] = port_id;
+
+
+	internals->active_slave_count = active_count + 1;
+}
+
+void
+rte_eth_bond_deactive_slave(struct rte_eth_dev *eth_dev,
+	uint8_t slave_pos )
+{
+	struct bond_dev_private *internals = eth_dev->data->dev_private;
+	uint8_t active_count = internals->active_slave_count;
+
+	active_count--;
+
+	/* If slave was not at the end of the list
+	 * shift active slaves up active array list */
+	if (slave_pos < active_count) {
+		memmove(internals->active_slaves + slave_pos,
+				internals->active_slaves + slave_pos + 1,
+				(active_count - slave_pos) *
+					sizeof(internals->active_slaves[0]));
+	}
+
+	internals->active_slave_count = active_count;
+}
+
 uint8_t
 number_of_sockets(void)
 {
@@ -356,10 +391,8 @@ rte_eth_bond_slave_add(uint8_t bonded_port_id, uint8_t slave_port_id)
 	if (bonded_eth_dev->data->dev_started) {
 		rte_eth_link_get_nowait(slave_port_id, &link_props);
 
-		 if (link_props.link_status == 1) {
-			internals->active_slaves[internals->active_slave_count++] =
-					slave_port_id;
-		}
+		 if (link_props.link_status == 1)
+			rte_eth_bond_activate_slave(bonded_eth_dev, slave_port_id);
 	}
 
 	return 0;
@@ -373,6 +406,7 @@ err_add:
 int
 rte_eth_bond_slave_remove(uint8_t bonded_port_id, uint8_t slave_port_id)
 {
+	struct rte_eth_dev *eth_dev;
 	struct bond_dev_private *internals;
 	struct slave_conf *slave_conf;
 
@@ -386,20 +420,15 @@ rte_eth_bond_slave_remove(uint8_t bonded_port_id, uint8_t slave_port_id)
 	if (valid_slave_port_id(slave_port_id) != 0)
 		goto err_del;
 
-	internals = rte_eth_devices[bonded_port_id].data->dev_private;
+	eth_dev = &rte_eth_devices[bonded_port_id];
+	internals = eth_dev->data->dev_private;
 
 	/* first remove from active slave list */
-	for (i = 0; i < internals->active_slave_count; i++) {
-		if (internals->active_slaves[i] == slave_port_id)
-			pos = i;
-
-		/* shift active slaves up active array list */
-		if (pos >= 0 && i < (internals->active_slave_count - 1))
-			internals->active_slaves[i] = internals->active_slaves[i+1];
-	}
+	pos = find_slave_by_id(internals->active_slaves, internals->active_slave_count,
+			slave_port_id);
 
-	if (pos >= 0)
-		internals->active_slave_count--;
+	if (pos < internals->active_slave_count)
+		rte_eth_bond_deactive_slave(eth_dev, pos);
 
 	pos = -1;
 	/* now remove from slave list */
diff --git a/lib/librte_pmd_bond/rte_eth_bond_pmd.c b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
index 38cc1ae..482ddb8 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_pmd.c
+++ b/lib/librte_pmd_bond/rte_eth_bond_pmd.c
@@ -447,6 +447,27 @@ link_properties_valid(struct rte_eth_link *bonded_dev_link,
 }
 
 int
+mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr)
+{
+	struct ether_addr *mac_addr;
+
+	mac_addr = eth_dev->data->mac_addrs;
+
+	if (eth_dev == NULL) {
+		RTE_LOG(ERR, PMD, "%s: NULL pointer eth_dev specified\n", __func__);
+		return -1;
+	}
+
+	if (dst_mac_addr == NULL) {
+		RTE_LOG(ERR, PMD, "%s: NULL pointer MAC specified\n", __func__);
+		return -1;
+	}
+
+	ether_addr_copy(mac_addr, dst_mac_addr);
+	return 0;
+}
+
+int
 mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr)
 {
 	struct ether_addr *mac_addr;
@@ -817,7 +838,7 @@ bond_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
 					0, dev->pci_dev->numa_node);
 
 	if (bd_tx_q == NULL)
-			return -1;
+		return -1;
 
 	bd_tx_q->queue_id = tx_queue_id;
 	bd_tx_q->dev_private = dev->data->dev_private;
@@ -940,7 +961,6 @@ bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
 	case BONDING_MODE_ACTIVE_BACKUP:
 	default:
 		rte_eth_promiscuous_enable(internals->current_primary_port);
-
 	}
 }
 
@@ -975,7 +995,8 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
 	struct bond_dev_private *internals;
 	struct rte_eth_link link;
 
-	int i, valid_slave = 0, active_pos = -1;
+	int i, valid_slave = 0;
+	uint8_t active_pos;
 	uint8_t lsc_flag = 0;
 
 	if (type != RTE_ETH_EVENT_INTR_LSC || param == NULL)
@@ -1005,16 +1026,12 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
 		return;
 
 	/* Search for port in active port list */
-	for (i = 0; i < internals->active_slave_count; i++) {
-		if (port_id == internals->active_slaves[i]) {
-			active_pos = i;
-			break;
-		}
-	}
+	active_pos = find_slave_by_id(internals->active_slaves,
+			internals->active_slave_count, port_id);
 
 	rte_eth_link_get_nowait(port_id, &link);
 	if (link.link_status) {
-		if (active_pos >= 0)
+		if (active_pos < internals->active_slave_count)
 			return;
 
 		/* if no active slave ports then set this port to be primary port */
@@ -1028,21 +1045,19 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
 			link_properties_set(bonded_eth_dev,
 					&(slave_eth_dev->data->dev_link));
 		}
-		internals->active_slaves[internals->active_slave_count++] = port_id;
+
+		rte_eth_bond_activate_slave(bonded_eth_dev, port_id);
 
 		/* If user has defined the primary port then default to using it */
 		if (internals->user_defined_primary_port &&
 				internals->primary_port == port_id)
 			bond_ethdev_primary_set(internals, port_id);
 	} else {
-		if (active_pos < 0)
+		if (active_pos == internals->active_slave_count)
 			return;
 
 		/* Remove from active slave list */
-		for (i = active_pos; i < (internals->active_slave_count - 1); i++)
-			internals->active_slaves[i] = internals->active_slaves[i+1];
-
-		internals->active_slave_count--;
+		rte_eth_bond_deactive_slave(bonded_eth_dev, active_pos);
 
 		/* No active slaves, change link status to down and reset other
 		 * link properties */
diff --git a/lib/librte_pmd_bond/rte_eth_bond_private.h b/lib/librte_pmd_bond/rte_eth_bond_private.h
index 60f1e8d..6742a4c 100644
--- a/lib/librte_pmd_bond/rte_eth_bond_private.h
+++ b/lib/librte_pmd_bond/rte_eth_bond_private.h
@@ -115,11 +115,11 @@ struct bond_dev_private {
 	uint16_t nb_rx_queues;			/**< Total number of rx queues */
 	uint16_t nb_tx_queues;			/**< Total number of tx queues*/
 
-	uint8_t slave_count;			/**< Number of active slaves */
-	uint8_t active_slave_count;		/**< Number of slaves */
+	uint8_t slave_count;			/**< Number of slaves */
+	uint8_t active_slave_count;		/**< Number of active slaves */
 
-	uint8_t active_slaves[RTE_MAX_ETHPORTS];	/**< Active slave list */
 	uint8_t slaves[RTE_MAX_ETHPORTS];			/**< Slave list */
+	uint8_t active_slaves[RTE_MAX_ETHPORTS];	/**< Active slave list */
 
 	/** Persisted configuration of slaves */
 	struct slave_conf presisted_slaves_conf[RTE_MAX_ETHPORTS];
@@ -130,6 +130,19 @@ extern struct eth_dev_ops default_dev_ops;
 int
 valid_bonded_ethdev(struct rte_eth_dev *eth_dev);
 
+static inline uint8_t
+find_slave_by_id(uint8_t *slaves, uint8_t slaves_count,
+	uint8_t slave_id ) {
+
+	uint8_t pos;
+	for (pos = 0; pos < slaves_count; pos++) {
+		if (slave_id == slaves[pos])
+			break;
+	}
+
+	return pos;
+}
+
 int
 valid_port_id(uint8_t port_id);
 
@@ -140,6 +153,14 @@ int
 valid_slave_port_id(uint8_t port_id);
 
 void
+rte_eth_bond_deactive_slave(struct rte_eth_dev *eth_dev,
+	uint8_t slave_pos );
+
+void
+rte_eth_bond_activate_slave(struct rte_eth_dev *eth_dev,
+	uint8_t port_id );
+
+void
 link_properties_set(struct rte_eth_dev *bonded_eth_dev,
 		struct rte_eth_link *slave_dev_link);
 void
@@ -153,6 +174,9 @@ int
 mac_address_set(struct rte_eth_dev *eth_dev, struct ether_addr *new_mac_addr);
 
 int
+mac_address_get(struct rte_eth_dev *eth_dev, struct ether_addr *dst_mac_addr);
+
+int
 mac_address_slaves_update(struct rte_eth_dev *bonded_eth_dev);
 
 uint8_t
-- 
1.7.9.5

  reply	other threads:[~2014-09-17 14:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-17 14:21 [dpdk-dev] [PATCH 0/2] bond: add mode 4 support Pawel Wodkowski
2014-09-17 14:21 ` Pawel Wodkowski [this message]
2014-09-17 14:51   ` [dpdk-dev] [PATCH 1/2] bond: extract common code to separate functions Neil Horman
2014-09-17 14:21 ` [dpdk-dev] [PATCH 2/2] bond: add mode 4 support Pawel Wodkowski
2014-09-17 15:13   ` Neil Horman
2014-09-18  8:07     ` Wodkowski, PawelX
2014-09-18 16:02       ` Neil Horman
2014-09-19 12:47         ` Wodkowski, PawelX
2014-09-19 17:29           ` Neil Horman
2014-09-22  6:26             ` Wodkowski, PawelX
2014-09-22 10:24               ` Neil Horman
     [not found]                 ` <60ABE07DBB3A454EB7FAD707B4BB158213896977@IRSMSX109.ger.corp.intel.com>
2014-09-22 13:15                   ` Neil Horman

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=1410963713-13837-2-git-send-email-pawelx.wodkowski@intel.com \
    --to=pawelx.wodkowski@intel.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).