net/bonding: fix dedicated queue mode in vector burst
[dpdk.git] / drivers / net / bonding / rte_eth_bond_pmd.c
index a9ed5d8..542c663 100644 (file)
@@ -7,8 +7,8 @@
 
 #include <rte_mbuf.h>
 #include <rte_malloc.h>
-#include <rte_ethdev_driver.h>
-#include <rte_ethdev_vdev.h>
+#include <ethdev_driver.h>
+#include <ethdev_vdev.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
 #include <rte_ip.h>
@@ -69,7 +69,7 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
        struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
        internals = bd_rx_q->dev_private;
        slave_count = internals->active_slave_count;
-       active_slave = internals->active_slave;
+       active_slave = bd_rx_q->active_slave;
 
        for (i = 0; i < slave_count && nb_pkts; i++) {
                uint16_t num_rx_slave;
@@ -86,8 +86,8 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
                        active_slave = 0;
        }
 
-       if (++internals->active_slave >= slave_count)
-               internals->active_slave = 0;
+       if (++bd_rx_q->active_slave >= slave_count)
+               bd_rx_q->active_slave = 0;
        return num_rx_total;
 }
 
@@ -303,9 +303,9 @@ rx_burst_8023ad(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts,
        memcpy(slaves, internals->active_slaves,
                        sizeof(internals->active_slaves[0]) * slave_count);
 
-       idx = internals->active_slave;
+       idx = bd_rx_q->active_slave;
        if (idx >= slave_count) {
-               internals->active_slave = 0;
+               bd_rx_q->active_slave = 0;
                idx = 0;
        }
        for (i = 0; i < slave_count && num_rx_total < nb_pkts; i++) {
@@ -342,11 +342,11 @@ rx_burst_8023ad(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts,
                                                 bufs[j])) ||
                                !collecting ||
                                (!promisc &&
-                                ((rte_is_unicast_ether_addr(&hdr->d_addr) &&
+                                ((rte_is_unicast_ether_addr(&hdr->dst_addr) &&
                                   !rte_is_same_ether_addr(bond_mac,
-                                                      &hdr->d_addr)) ||
+                                                      &hdr->dst_addr)) ||
                                  (!allmulti &&
-                                  rte_is_multicast_ether_addr(&hdr->d_addr)))))) {
+                                  rte_is_multicast_ether_addr(&hdr->dst_addr)))))) {
 
                                if (hdr->ether_type == ether_type_slow_be) {
                                        bond_mode_8023ad_handle_slow_pkt(
@@ -367,8 +367,8 @@ rx_burst_8023ad(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts,
                        idx = 0;
        }
 
-       if (++internals->active_slave >= slave_count)
-               internals->active_slave = 0;
+       if (++bd_rx_q->active_slave >= slave_count)
+               bd_rx_q->active_slave = 0;
 
        return num_rx_total;
 }
@@ -473,17 +473,13 @@ update_client_stats(uint32_t addr, uint16_t port, uint32_t *TXorRXindicator)
 #ifdef RTE_LIBRTE_BOND_DEBUG_ALB
 #define MODE6_DEBUG(info, src_ip, dst_ip, eth_h, arp_op, port, burstnumber) \
        rte_log(RTE_LOG_DEBUG, bond_logtype,                            \
-               "%s port:%d SrcMAC:%02X:%02X:%02X:%02X:%02X:%02X SrcIP:%s " \
-               "DstMAC:%02X:%02X:%02X:%02X:%02X:%02X DstIP:%s %s %d\n", \
+               "%s port:%d SrcMAC:" RTE_ETHER_ADDR_PRT_FMT " SrcIP:%s " \
+               "DstMAC:" RTE_ETHER_ADDR_PRT_FMT " DstIP:%s %s %d\n", \
                info,                                                   \
                port,                                                   \
-               eth_h->s_addr.addr_bytes[0], eth_h->s_addr.addr_bytes[1], \
-               eth_h->s_addr.addr_bytes[2], eth_h->s_addr.addr_bytes[3], \
-               eth_h->s_addr.addr_bytes[4], eth_h->s_addr.addr_bytes[5], \
+               RTE_ETHER_ADDR_BYTES(&eth_h->src_addr),                  \
                src_ip,                                                 \
-               eth_h->d_addr.addr_bytes[0], eth_h->d_addr.addr_bytes[1], \
-               eth_h->d_addr.addr_bytes[2], eth_h->d_addr.addr_bytes[3], \
-               eth_h->d_addr.addr_bytes[4], eth_h->d_addr.addr_bytes[5], \
+               RTE_ETHER_ADDR_BYTES(&eth_h->dst_addr),                  \
                dst_ip,                                                 \
                arp_op, ++burstnumber)
 #endif
@@ -534,8 +530,8 @@ mode6_debug(const char __rte_unused *info,
 static uint16_t
 bond_ethdev_rx_burst_alb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
-       struct bond_tx_queue *bd_tx_q = (struct bond_tx_queue *)queue;
-       struct bond_dev_private *internals = bd_tx_q->dev_private;
+       struct bond_rx_queue *bd_rx_q = (struct bond_rx_queue *)queue;
+       struct bond_dev_private *internals = bd_rx_q->dev_private;
        struct rte_ether_hdr *eth_h;
        uint16_t ether_type, offset;
        uint16_t nb_recv_pkts;
@@ -647,9 +643,9 @@ static inline uint16_t
 ether_hash(struct rte_ether_hdr *eth_hdr)
 {
        unaligned_uint16_t *word_src_addr =
-               (unaligned_uint16_t *)eth_hdr->s_addr.addr_bytes;
+               (unaligned_uint16_t *)eth_hdr->src_addr.addr_bytes;
        unaligned_uint16_t *word_dst_addr =
-               (unaligned_uint16_t *)eth_hdr->d_addr.addr_bytes;
+               (unaligned_uint16_t *)eth_hdr->dst_addr.addr_bytes;
 
        return (word_src_addr[0] ^ word_dst_addr[0]) ^
                        (word_src_addr[1] ^ word_dst_addr[1]) ^
@@ -946,10 +942,10 @@ bond_ethdev_tx_burst_tlb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
                        ether_hdr = rte_pktmbuf_mtod(bufs[j],
                                                struct rte_ether_hdr *);
-                       if (rte_is_same_ether_addr(&ether_hdr->s_addr,
+                       if (rte_is_same_ether_addr(&ether_hdr->src_addr,
                                                        &primary_slave_addr))
                                rte_ether_addr_copy(&active_slave_addr,
-                                               &ether_hdr->s_addr);
+                                               &ether_hdr->src_addr);
 #if defined(RTE_LIBRTE_BOND_DEBUG_ALB) || defined(RTE_LIBRTE_BOND_DEBUG_ALB_L1)
                                        mode6_debug("TX IPv4:", ether_hdr, slaves[i], &burstnumberTX);
 #endif
@@ -1021,7 +1017,7 @@ bond_ethdev_tx_burst_alb(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
                        slave_idx = bond_mode_alb_arp_xmit(eth_h, offset, internals);
 
                        /* Change src mac in eth header */
-                       rte_eth_macaddr_get(slave_idx, &eth_h->s_addr);
+                       rte_eth_macaddr_get(slave_idx, &eth_h->src_addr);
 
                        /* Add packet to slave tx buffer */
                        slave_bufs[slave_idx][slave_bufs_pkts[slave_idx]] = bufs[i];
@@ -1694,7 +1690,10 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
        struct bond_dev_private *internals = bonded_eth_dev->data->dev_private;
 
        /* Stop slave */
-       rte_eth_dev_stop(slave_eth_dev->data->port_id);
+       errval = rte_eth_dev_stop(slave_eth_dev->data->port_id);
+       if (errval != 0)
+               RTE_BOND_LOG(ERR, "rte_eth_dev_stop: port %u, err (%d)",
+                            slave_eth_dev->data->port_id, errval);
 
        /* Enable interrupts on slave device if supported */
        if (slave_eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
@@ -1725,6 +1724,17 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
                slave_eth_dev->data->dev_conf.rxmode.offloads &=
                                ~DEV_RX_OFFLOAD_VLAN_FILTER;
 
+       slave_eth_dev->data->dev_conf.rxmode.max_rx_pkt_len =
+                       bonded_eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+
+       if (bonded_eth_dev->data->dev_conf.rxmode.offloads &
+                       DEV_RX_OFFLOAD_JUMBO_FRAME)
+               slave_eth_dev->data->dev_conf.rxmode.offloads |=
+                               DEV_RX_OFFLOAD_JUMBO_FRAME;
+       else
+               slave_eth_dev->data->dev_conf.rxmode.offloads &=
+                               ~DEV_RX_OFFLOAD_JUMBO_FRAME;
+
        nb_rx_queues = bonded_eth_dev->data->nb_rx_queues;
        nb_tx_queues = bonded_eth_dev->data->nb_tx_queues;
 
@@ -1791,12 +1801,13 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
                                != 0)
                        return errval;
 
-               if (bond_ethdev_8023ad_flow_verify(bonded_eth_dev,
-                               slave_eth_dev->data->port_id) != 0) {
+               errval = bond_ethdev_8023ad_flow_verify(bonded_eth_dev,
+                               slave_eth_dev->data->port_id);
+               if (errval != 0) {
                        RTE_BOND_LOG(ERR,
-                               "rte_eth_tx_queue_setup: port=%d queue_id %d, err (%d)",
-                               slave_eth_dev->data->port_id, q_id, errval);
-                       return -1;
+                               "bond_ethdev_8023ad_flow_verify: port=%d, err (%d)",
+                               slave_eth_dev->data->port_id, errval);
+                       return errval;
                }
 
                if (internals->mode4.dedicated_queues.flow[slave_eth_dev->data->port_id] != NULL)
@@ -1804,8 +1815,14 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
                                        internals->mode4.dedicated_queues.flow[slave_eth_dev->data->port_id],
                                        &flow_error);
 
-               bond_ethdev_8023ad_flow_set(bonded_eth_dev,
+               errval = bond_ethdev_8023ad_flow_set(bonded_eth_dev,
                                slave_eth_dev->data->port_id);
+               if (errval != 0) {
+                       RTE_BOND_LOG(ERR,
+                               "bond_ethdev_8023ad_flow_set: port=%d, err (%d)",
+                               slave_eth_dev->data->port_id, errval);
+                       return errval;
+               }
        }
 
        /* Start device */
@@ -2046,11 +2063,12 @@ bond_ethdev_free_queues(struct rte_eth_dev *dev)
        }
 }
 
-void
+int
 bond_ethdev_stop(struct rte_eth_dev *eth_dev)
 {
        struct bond_dev_private *internals = eth_dev->data->dev_private;
        uint16_t i;
+       int ret;
 
        if (internals->mode == BONDING_MODE_8023AD) {
                struct port *port;
@@ -2089,10 +2107,17 @@ bond_ethdev_stop(struct rte_eth_dev *eth_dev)
                                internals->active_slave_count, slave_id) !=
                                                internals->active_slave_count) {
                        internals->slaves[i].last_link_status = 0;
-                       rte_eth_dev_stop(slave_id);
+                       ret = rte_eth_dev_stop(slave_id);
+                       if (ret != 0) {
+                               RTE_BOND_LOG(ERR, "Failed to stop device on port %u",
+                                            slave_id);
+                               return ret;
+                       }
                        deactivate_slave(eth_dev, slave_id);
                }
        }
+
+       return 0;
 }
 
 int
@@ -2110,7 +2135,11 @@ bond_ethdev_close(struct rte_eth_dev *dev)
        while (internals->slave_count != skipped) {
                uint16_t port_id = internals->slaves[skipped].port_id;
 
-               rte_eth_dev_stop(port_id);
+               if (rte_eth_dev_stop(port_id) != 0) {
+                       RTE_BOND_LOG(ERR, "Failed to stop device on port %u",
+                                    port_id);
+                       skipped++;
+               }
 
                if (rte_eth_bond_slave_remove(bond_port_id, port_id) != 0) {
                        RTE_BOND_LOG(ERR,
@@ -2130,9 +2159,8 @@ bond_ethdev_close(struct rte_eth_dev *dev)
         */
        rte_mempool_free(internals->mode6.mempool);
 
-       dev->dev_ops = NULL;
-       dev->rx_pkt_burst = NULL;
-       dev->tx_pkt_burst = NULL;
+       if (internals->kvlist != NULL)
+               rte_kvargs_free(internals->kvlist);
 
        return 0;
 }
@@ -2304,8 +2332,10 @@ bond_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
 }
 
 static void
-bond_ethdev_rx_queue_release(void *queue)
+bond_ethdev_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+       void *queue = dev->data->rx_queues[queue_id];
+
        if (queue == NULL)
                return;
 
@@ -2313,8 +2343,10 @@ bond_ethdev_rx_queue_release(void *queue)
 }
 
 static void
-bond_ethdev_tx_queue_release(void *queue)
+bond_ethdev_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
 {
+       void *queue = dev->data->rx_queues[queue_id];
+
        if (queue == NULL)
                return;
 
@@ -3086,14 +3118,11 @@ bond_ethdev_mac_address_set(struct rte_eth_dev *dev,
 }
 
 static int
-bond_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
-                enum rte_filter_type type, enum rte_filter_op op, void *arg)
+bond_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
+                 const struct rte_flow_ops **ops)
 {
-       if (type == RTE_ETH_FILTER_GENERIC && op == RTE_ETH_FILTER_GET) {
-               *(const void **)arg = &bond_flow_ops;
-               return 0;
-       }
-       return -ENOTSUP;
+       *ops = &bond_flow_ops;
+       return 0;
 }
 
 static int
@@ -3185,7 +3214,7 @@ const struct eth_dev_ops default_dev_ops = {
        .mac_addr_set         = bond_ethdev_mac_address_set,
        .mac_addr_add         = bond_ethdev_mac_addr_add,
        .mac_addr_remove      = bond_ethdev_mac_addr_remove,
-       .filter_ctrl          = bond_filter_ctrl
+       .flow_ops_get         = bond_flow_ops_get
 };
 
 static int
@@ -3209,7 +3238,6 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t mode)
        }
 
        internals = eth_dev->data->dev_private;
-       eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
        eth_dev->data->nb_rx_queues = (uint16_t)1;
        eth_dev->data->nb_tx_queues = (uint16_t)1;
 
@@ -3224,7 +3252,8 @@ bond_alloc(struct rte_vdev_device *dev, uint8_t mode)
        }
 
        eth_dev->dev_ops = &default_dev_ops;
-       eth_dev->data->dev_flags = RTE_ETH_DEV_INTR_LSC;
+       eth_dev->data->dev_flags = RTE_ETH_DEV_INTR_LSC |
+                                       RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
        rte_spinlock_init(&internals->lock);
        rte_spinlock_init(&internals->lsc_lock);
@@ -3314,8 +3343,9 @@ bond_probe(struct rte_vdev_device *dev)
        const char *name;
        struct bond_dev_private *internals;
        struct rte_kvargs *kvlist;
-       uint8_t bonding_mode, socket_id/*, agg_mode*/;
-       int  arg_count, port_id;
+       uint8_t bonding_mode;
+       int arg_count, port_id;
+       int socket_id;
        uint8_t agg_mode;
        struct rte_eth_dev *eth_dev;
 
@@ -3422,6 +3452,7 @@ bond_remove(struct rte_vdev_device *dev)
        struct rte_eth_dev *eth_dev;
        struct bond_dev_private *internals;
        const char *name;
+       int ret = 0;
 
        if (!dev)
                return -EINVAL;
@@ -3444,12 +3475,12 @@ bond_remove(struct rte_vdev_device *dev)
                return -EBUSY;
 
        if (eth_dev->data->dev_started == 1) {
-               bond_ethdev_stop(eth_dev);
+               ret = bond_ethdev_stop(eth_dev);
                bond_ethdev_close(eth_dev);
        }
        rte_eth_dev_release_port(eth_dev);
 
-       return 0;
+       return ret;
 }
 
 /* this part will resolve the slave portids after all the other pdev and vdev
@@ -3755,4 +3786,7 @@ RTE_PMD_REGISTER_PARAM_STRING(net_bonding,
        "up_delay=<int> "
        "down_delay=<int>");
 
-RTE_LOG_REGISTER(bond_logtype, pmd.net.bond, NOTICE);
+/* We can't use RTE_LOG_REGISTER_DEFAULT because of the forced name for
+ * this library, see meson.build.
+ */
+RTE_LOG_REGISTER(bond_logtype, pmd.net.bonding, NOTICE);