mbuf: replace data pointer by an offset
[dpdk.git] / lib / librte_pmd_bond / rte_eth_bond_pmd.c
index aa910ba..506a448 100644 (file)
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/queue.h>
-#include <linux/binfmts.h>
-
 #include <rte_mbuf.h>
-#include <rte_cycles.h>
-#include <rte_dev.h>
-#include <rte_devargs.h>
+#include <rte_malloc.h>
 #include <rte_ethdev.h>
+#include <rte_tcp.h>
+#include <rte_udp.h>
 #include <rte_ip.h>
+#include <rte_devargs.h>
 #include <rte_kvargs.h>
-#include <rte_malloc.h>
-#include <rte_memcpy.h>
-#include <rte_memory.h>
-#include <rte_udp.h>
+#include <rte_dev.h>
 
 #include "rte_eth_bond.h"
 #include "rte_eth_bond_private.h"
@@ -203,14 +198,14 @@ xmit_slave_hash(const struct rte_mbuf *buf, uint8_t slave_count, uint8_t policy)
 
        switch (policy) {
        case BALANCE_XMIT_POLICY_LAYER2:
-               eth_hdr = (struct ether_hdr *)buf->pkt.data;
+               eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
 
                hash = ether_hash(eth_hdr);
                hash ^= hash >> 8;
                return hash % slave_count;
 
        case BALANCE_XMIT_POLICY_LAYER23:
-               eth_hdr = (struct ether_hdr *)buf->pkt.data;
+               eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
 
                if (buf->ol_flags & PKT_RX_VLAN_PKT)
                        eth_offset = sizeof(struct ether_hdr) + sizeof(struct vlan_hdr);
@@ -683,8 +678,8 @@ bond_ethdev_start(struct rte_eth_dev *eth_dev)
        for (i = 0; i < internals->slave_count; i++) {
                if (slave_configure(eth_dev, &(rte_eth_devices[internals->slaves[i]]))
                                != 0) {
-                       RTE_LOG(ERR, PMD,
-                                       "bonded port (%d) failed to reconfigure slave device %d)",
+                       RTE_LOG(ERR, PMD, "bonded port "
+                                       "(%d) failed to reconfigure slave device (%d)\n)",
                                        eth_dev->data->port_id, internals->slaves[i]);
                        return -1;
                }
@@ -925,17 +920,12 @@ 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, bonded_port_id, valid_slave, active_pos = -1;
+       int i, valid_slave = 0, active_pos = -1;
 
-       if (type != RTE_ETH_EVENT_INTR_LSC)
+       if (type != RTE_ETH_EVENT_INTR_LSC || param == NULL)
                return;
 
-       if (param == NULL)
-               return;
-
-       bonded_port_id = *(uint8_t *)param;
-
-       bonded_eth_dev = &rte_eth_devices[bonded_port_id];
+       bonded_eth_dev = &rte_eth_devices[*(uint8_t *)param];
        slave_eth_dev = &rte_eth_devices[port_id];
 
        if (valid_bonded_ethdev(bonded_eth_dev))
@@ -968,48 +958,51 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
 
        rte_eth_link_get_nowait(port_id, &link);
        if (link.link_status) {
-               if (active_pos == -1) {
-                       /* if no active slave ports then set this port to be primary port */
-                       if (internals->active_slave_count == 0) {
-                               /* If first active slave, then change link status */
-                               bonded_eth_dev->data->dev_link.link_status = 1;
-                               internals->current_primary_port = port_id;
+               if (active_pos >= 0)
+                       return;
+
+               /* if no active slave ports then set this port to be primary port */
+               if (internals->active_slave_count < 1) {
+                       /* If first active slave, then change link status */
+                       bonded_eth_dev->data->dev_link.link_status = 1;
+                       internals->current_primary_port = port_id;
+
+                       /* Inherit eth dev link properties from first active slave */
+                       link_properties_set(bonded_eth_dev,
+                                       &(slave_eth_dev->data->dev_link));
+               }
+               internals->active_slaves[internals->active_slave_count++] = 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)
+                       return;
 
-                               /* Inherit eth dev link properties from first active slave */
-                               link_properties_set(bonded_eth_dev,
-                                               &(slave_eth_dev->data->dev_link));
+               /* 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_slaves[internals->active_slave_count++] = port_id;
+               internals->active_slave_count--;
 
-                       /* 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);
+               /* No active slaves, change link status to down and reset other
+                * link properties */
+               if (internals->active_slave_count < 1) {
+                       bonded_eth_dev->data->dev_link.link_status = 0;
 
+                       link_properties_reset(bonded_eth_dev);
                }
-       } else {
-               if (active_pos != -1) {
-                       /* 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--;
-
-                       /* No active slaves, change link status to down and reset other
-                        * link properties */
-                       if (internals->active_slave_count == 0)
-                               link_properties_reset(bonded_eth_dev);
-
-                       /* Update primary id, take first active slave from list or if none
-                        * available set to -1 */
-                       if (port_id == internals->current_primary_port) {
-                               if (internals->active_slave_count > 0)
-                                       bond_ethdev_primary_set(internals,
-                                                       internals->active_slaves[0]);
-                               else
-                                       internals->current_primary_port = internals->primary_port;
-                       }
+
+               /* Update primary id, take first active slave from list or if none
+                * available set to -1 */
+               if (port_id == internals->current_primary_port) {
+                       if (internals->active_slave_count > 0)
+                               bond_ethdev_primary_set(internals,
+                                               internals->active_slaves[0]);
+                       else
+                               internals->current_primary_port = internals->primary_port;
                }
        }
 }