ethdev: use constants for link state
[dpdk.git] / drivers / net / bonding / rte_eth_bond_pmd.c
index 8f84ec1..54788cf 100644 (file)
@@ -39,6 +39,7 @@
 #include <rte_tcp.h>
 #include <rte_udp.h>
 #include <rte_ip.h>
+#include <rte_ip_frag.h>
 #include <rte_devargs.h>
 #include <rte_kvargs.h>
 #include <rte_dev.h>
@@ -170,6 +171,7 @@ bond_ethdev_rx_burst_8023ad(void *queue, struct rte_mbuf **bufs,
                         * mode and packet address does not match. */
                        if (unlikely(hdr->ether_type == ether_type_slow_be ||
                                !collecting || (!promisc &&
+                                       !is_multicast_ether_addr(&hdr->d_addr) &&
                                        !is_same_ether_addr(&bond_mac, &hdr->d_addr)))) {
 
                                if (hdr->ether_type == ether_type_slow_be) {
@@ -479,7 +481,7 @@ ether_hash(struct ether_hdr *eth_hdr)
 static inline uint32_t
 ipv4_hash(struct ipv4_hdr *ipv4_hdr)
 {
-       return (ipv4_hdr->src_addr ^ ipv4_hdr->dst_addr);
+       return ipv4_hdr->src_addr ^ ipv4_hdr->dst_addr;
 }
 
 static inline uint32_t
@@ -552,17 +554,20 @@ xmit_l34_hash(const struct rte_mbuf *buf, uint8_t slave_count)
 
                l3hash = ipv4_hash(ipv4_hdr);
 
-               ip_hdr_offset = (ipv4_hdr->version_ihl & IPV4_HDR_IHL_MASK) *
-                               IPV4_IHL_MULTIPLIER;
-
-               if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
-                       tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
-                                       ip_hdr_offset);
-                       l4hash = HASH_L4_PORTS(tcp_hdr);
-               } else if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
-                       udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
-                                       ip_hdr_offset);
-                       l4hash = HASH_L4_PORTS(udp_hdr);
+               /* there is no L4 header in fragmented packet */
+               if (likely(rte_ipv4_frag_pkt_is_fragmented(ipv4_hdr) == 0)) {
+                       ip_hdr_offset = (ipv4_hdr->version_ihl & IPV4_HDR_IHL_MASK) *
+                                       IPV4_IHL_MULTIPLIER;
+
+                       if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
+                               tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr +
+                                               ip_hdr_offset);
+                               l4hash = HASH_L4_PORTS(tcp_hdr);
+                       } else if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
+                               udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr +
+                                               ip_hdr_offset);
+                               l4hash = HASH_L4_PORTS(udp_hdr);
+                       }
                }
        } else if  (rte_cpu_to_be_16(ETHER_TYPE_IPv6) == proto) {
                struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)
@@ -1300,6 +1305,8 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
        struct bond_rx_queue *bd_rx_q;
        struct bond_tx_queue *bd_tx_q;
 
+       uint16_t old_nb_tx_queues = slave_eth_dev->data->nb_tx_queues;
+       uint16_t old_nb_rx_queues = slave_eth_dev->data->nb_rx_queues;
        int errval;
        uint16_t q_id;
 
@@ -1340,7 +1347,9 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
        }
 
        /* Setup Rx Queues */
-       for (q_id = 0; q_id < bonded_eth_dev->data->nb_rx_queues; q_id++) {
+       /* Use existing queues, if any */
+       for (q_id = old_nb_rx_queues;
+            q_id < bonded_eth_dev->data->nb_rx_queues; q_id++) {
                bd_rx_q = (struct bond_rx_queue *)bonded_eth_dev->data->rx_queues[q_id];
 
                errval = rte_eth_rx_queue_setup(slave_eth_dev->data->port_id, q_id,
@@ -1356,7 +1365,9 @@ slave_configure(struct rte_eth_dev *bonded_eth_dev,
        }
 
        /* Setup Tx Queues */
-       for (q_id = 0; q_id < bonded_eth_dev->data->nb_tx_queues; q_id++) {
+       /* Use existing queues, if any */
+       for (q_id = old_nb_tx_queues;
+            q_id < bonded_eth_dev->data->nb_tx_queues; q_id++) {
                bd_tx_q = (struct bond_tx_queue *)bonded_eth_dev->data->tx_queues[q_id];
 
                errval = rte_eth_tx_queue_setup(slave_eth_dev->data->port_id, q_id,
@@ -1443,18 +1454,11 @@ slave_add(struct bond_dev_private *internals,
        slave_details->port_id = slave_eth_dev->data->port_id;
        slave_details->last_link_status = 0;
 
-       /* If slave device doesn't support interrupts then we need to enabled
-        * polling to monitor link status */
+       /* Mark slave devices that don't support interrupts so we can
+        * compensate when we start the bond
+        */
        if (!(slave_eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)) {
                slave_details->link_status_poll_enabled = 1;
-
-               if (!internals->link_status_polling_enabled) {
-                       internals->link_status_polling_enabled = 1;
-
-                       rte_eal_alarm_set(internals->link_status_polling_interval_ms * 1000,
-                                       bond_ethdev_slave_link_status_change_monitor,
-                                       (void *)&rte_eth_devices[internals->port_id]);
-               }
        }
 
        slave_details->link_status_wait_to_complete = 0;
@@ -1495,7 +1499,7 @@ bond_ethdev_start(struct rte_eth_dev *eth_dev)
                return -1;
        }
 
-       eth_dev->data->dev_link.link_status = 0;
+       eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
        eth_dev->data->dev_started = 1;
 
        internals = eth_dev->data->dev_private;
@@ -1539,6 +1543,18 @@ bond_ethdev_start(struct rte_eth_dev *eth_dev)
                                        eth_dev->data->port_id, internals->slaves[i].port_id);
                        return -1;
                }
+               /* We will need to poll for link status if any slave doesn't
+                * support interrupts
+                */
+               if (internals->slaves[i].link_status_poll_enabled)
+                       internals->link_status_polling_enabled = 1;
+       }
+       /* start polling if needed */
+       if (internals->link_status_polling_enabled) {
+               rte_eal_alarm_set(
+                       internals->link_status_polling_interval_ms * 1000,
+                       bond_ethdev_slave_link_status_change_monitor,
+                       (void *)&rte_eth_devices[internals->port_id]);
        }
 
        if (internals->user_defined_primary_port)
@@ -1611,8 +1627,10 @@ bond_ethdev_stop(struct rte_eth_dev *eth_dev)
 
        internals->active_slave_count = 0;
        internals->link_status_polling_enabled = 0;
+       for (i = 0; i < internals->slave_count; i++)
+               internals->slaves[i].last_link_status = 0;
 
-       eth_dev->data->dev_link.link_status = 0;
+       eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
        eth_dev->data->dev_started = 0;
 }
 
@@ -1778,7 +1796,7 @@ bond_ethdev_link_update(struct rte_eth_dev *bonded_eth_dev,
 
        if (!bonded_eth_dev->data->dev_started ||
                internals->active_slave_count == 0) {
-               bonded_eth_dev->data->dev_link.link_status = 0;
+               bonded_eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
                return 0;
        } else {
                struct rte_eth_dev *slave_eth_dev;
@@ -1789,7 +1807,7 @@ bond_ethdev_link_update(struct rte_eth_dev *bonded_eth_dev,
 
                        (*slave_eth_dev->dev_ops->link_update)(slave_eth_dev,
                                        wait_to_complete);
-                       if (slave_eth_dev->data->dev_link.link_status == 1) {
+                       if (slave_eth_dev->data->dev_link.link_status == ETH_LINK_UP) {
                                link_up = 1;
                                break;
                        }
@@ -1958,7 +1976,7 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
                /* 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;
+                       bonded_eth_dev->data->dev_link.link_status = ETH_LINK_UP;
                        internals->current_primary_port = port_id;
                        lsc_flag = 1;
 
@@ -1986,7 +2004,7 @@ bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
                 * link properties */
                if (internals->active_slave_count < 1) {
                        lsc_flag = 1;
-                       bonded_eth_dev->data->dev_link.link_status = 0;
+                       bonded_eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;
 
                        link_properties_reset(bonded_eth_dev);
                }
@@ -2137,25 +2155,25 @@ bond_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev,
        return 0;
 }
 
-struct eth_dev_ops default_dev_ops = {
-               .dev_start            = bond_ethdev_start,
-               .dev_stop             = bond_ethdev_stop,
-               .dev_close            = bond_ethdev_close,
-               .dev_configure        = bond_ethdev_configure,
-               .dev_infos_get        = bond_ethdev_info,
-               .rx_queue_setup       = bond_ethdev_rx_queue_setup,
-               .tx_queue_setup       = bond_ethdev_tx_queue_setup,
-               .rx_queue_release     = bond_ethdev_rx_queue_release,
-               .tx_queue_release     = bond_ethdev_tx_queue_release,
-               .link_update          = bond_ethdev_link_update,
-               .stats_get            = bond_ethdev_stats_get,
-               .stats_reset          = bond_ethdev_stats_reset,
-               .promiscuous_enable   = bond_ethdev_promiscuous_enable,
-               .promiscuous_disable  = bond_ethdev_promiscuous_disable,
-               .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
+const struct eth_dev_ops default_dev_ops = {
+       .dev_start            = bond_ethdev_start,
+       .dev_stop             = bond_ethdev_stop,
+       .dev_close            = bond_ethdev_close,
+       .dev_configure        = bond_ethdev_configure,
+       .dev_infos_get        = bond_ethdev_info,
+       .rx_queue_setup       = bond_ethdev_rx_queue_setup,
+       .tx_queue_setup       = bond_ethdev_tx_queue_setup,
+       .rx_queue_release     = bond_ethdev_rx_queue_release,
+       .tx_queue_release     = bond_ethdev_tx_queue_release,
+       .link_update          = bond_ethdev_link_update,
+       .stats_get            = bond_ethdev_stats_get,
+       .stats_reset          = bond_ethdev_stats_reset,
+       .promiscuous_enable   = bond_ethdev_promiscuous_enable,
+       .promiscuous_disable  = bond_ethdev_promiscuous_disable,
+       .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
 };
 
 static int