net/bonding: fix burst hash computation
[dpdk.git] / drivers / net / bonding / rte_eth_bond_pmd.c
index 997fffc..c34c325 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <rte_mbuf.h>
 #include <rte_malloc.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_ethdev_vdev.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -800,7 +800,7 @@ burst_xmit_l2_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
 
                hash = ether_hash(eth_hdr);
 
-               slaves[i++] = (hash ^= hash >> 8) % slave_count;
+               slaves[i] = (hash ^= hash >> 8) % slave_count;
        }
 }
 
@@ -838,7 +838,7 @@ burst_xmit_l23_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
                hash ^= hash >> 16;
                hash ^= hash >> 8;
 
-               slaves[i++] = hash % slave_count;
+               slaves[i] = hash % slave_count;
        }
 }
 
@@ -907,7 +907,7 @@ burst_xmit_l34_hash(struct rte_mbuf **buf, uint16_t nb_pkts,
                hash ^= hash >> 16;
                hash ^= hash >> 8;
 
-               slaves[i++] = hash % slave_count;
+               slaves[i] = hash % slave_count;
        }
 }
 
@@ -1229,7 +1229,7 @@ bond_ethdev_tx_burst_balance(void *queue, struct rte_mbuf **bufs,
        /* Number of mbufs for transmission on each slave */
        uint16_t slave_nb_bufs[RTE_MAX_ETHPORTS] = { 0 };
        /* Mapping array generated by hash function to map mbufs to slaves */
-       uint16_t bufs_slave_port_idxs[RTE_MAX_ETHPORTS] = { 0 };
+       uint16_t bufs_slave_port_idxs[nb_bufs];
 
        uint16_t slave_tx_count, slave_tx_fail_count[RTE_MAX_ETHPORTS] = { 0 };
        uint16_t total_tx_count = 0, total_tx_fail_count = 0;
@@ -1435,17 +1435,17 @@ bond_ethdev_tx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
                if (likely(rte_ring_empty(port->tx_ring)))
                        continue;
 
-               rte_ring_dequeue(port->tx_ring, (void **)&ctrl_pkt);
-
-               slave_tx_count = rte_eth_tx_burst(slave_port_ids[i],
+               if (rte_ring_dequeue(port->tx_ring,
+                                    (void **)&ctrl_pkt) != -ENOENT) {
+                       slave_tx_count = rte_eth_tx_burst(slave_port_ids[i],
                                        bd_tx_q->queue_id, &ctrl_pkt, 1);
-
-               /*
-                * re-enqueue LAG control plane packets to buffering
-                * ring if transmission fails so the packet isn't lost.
-                */
-               if (slave_tx_count != 1)
-                       rte_ring_enqueue(port->tx_ring, ctrl_pkt);
+                       /*
+                        * re-enqueue LAG control plane packets to buffering
+                        * ring if transmission fails so the packet isn't lost.
+                        */
+                       if (slave_tx_count != 1)
+                               rte_ring_enqueue(port->tx_ring, ctrl_pkt);
+               }
        }
 
        return total_tx_count;
@@ -2823,6 +2823,41 @@ bond_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev,
        return 0;
 }
 
+static int
+bond_ethdev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+       struct rte_eth_dev *slave_eth_dev;
+       struct bond_dev_private *internals = dev->data->dev_private;
+       int ret, i;
+
+       rte_spinlock_lock(&internals->lock);
+
+       for (i = 0; i < internals->slave_count; i++) {
+               slave_eth_dev = &rte_eth_devices[internals->slaves[i].port_id];
+               if (*slave_eth_dev->dev_ops->mtu_set == NULL) {
+                       rte_spinlock_unlock(&internals->lock);
+                       return -ENOTSUP;
+               }
+       }
+       for (i = 0; i < internals->slave_count; i++) {
+               ret = rte_eth_dev_set_mtu(internals->slaves[i].port_id, mtu);
+               if (ret < 0) {
+                       rte_spinlock_unlock(&internals->lock);
+                       return ret;
+               }
+       }
+
+       rte_spinlock_unlock(&internals->lock);
+       return 0;
+}
+
+static void
+bond_ethdev_mac_address_set(struct rte_eth_dev *dev, struct ether_addr *addr)
+{
+       if (mac_address_set(dev, addr))
+               RTE_BOND_LOG(ERR, "Failed to update MAC address");
+}
+
 const struct eth_dev_ops default_dev_ops = {
        .dev_start            = bond_ethdev_start,
        .dev_stop             = bond_ethdev_stop,
@@ -2842,7 +2877,9 @@ const struct eth_dev_ops default_dev_ops = {
        .reta_update          = bond_ethdev_rss_reta_update,
        .reta_query           = bond_ethdev_rss_reta_query,
        .rss_hash_update      = bond_ethdev_rss_hash_update,
-       .rss_hash_conf_get    = bond_ethdev_rss_hash_conf_get
+       .rss_hash_conf_get    = bond_ethdev_rss_hash_conf_get,
+       .mtu_set              = bond_ethdev_mtu_set,
+       .mac_addr_set         = bond_ethdev_mac_address_set
 };
 
 static int