mlx5: support promiscuous and allmulticast Rx modes
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>
Fri, 30 Oct 2015 18:52:37 +0000 (19:52 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 30 Oct 2015 21:31:22 +0000 (22:31 +0100)
These modes require special non-MAC flows.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Signed-off-by: Yaacov Hazan <yaacovh@mellanox.com>
drivers/net/mlx5/Makefile
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_ethdev.c
drivers/net/mlx5/mlx5_rxmode.c [new file with mode: 0644]
drivers/net/mlx5/mlx5_rxq.c
drivers/net/mlx5/mlx5_rxtx.h
drivers/net/mlx5/mlx5_trigger.c

index 88b361c..4d25d9c 100644 (file)
@@ -48,6 +48,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_rxtx.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_trigger.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_ethdev.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_mac.c
+SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_rxmode.c
 SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_stats.c
 
 # Dependencies.
index 38f5199..ee63bdf 100644 (file)
@@ -133,6 +133,10 @@ static const struct eth_dev_ops mlx5_dev_ops = {
        .dev_start = mlx5_dev_start,
        .dev_stop = mlx5_dev_stop,
        .dev_close = mlx5_dev_close,
+       .promiscuous_enable = mlx5_promiscuous_enable,
+       .promiscuous_disable = mlx5_promiscuous_disable,
+       .allmulticast_enable = mlx5_allmulticast_enable,
+       .allmulticast_disable = mlx5_allmulticast_disable,
        .stats_get = mlx5_stats_get,
        .stats_reset = mlx5_stats_reset,
        .dev_infos_get = mlx5_dev_infos_get,
index 79559bc..56da43c 100644 (file)
@@ -94,6 +94,8 @@ struct priv {
        uint16_t mtu; /* Configured MTU. */
        uint8_t port; /* Physical port number. */
        unsigned int started:1; /* Device started, flows enabled. */
+       unsigned int promisc_req:1; /* Promiscuous mode requested. */
+       unsigned int allmulti_req:1; /* All multicast mode requested. */
        unsigned int hw_qpg:1; /* QP groups are supported. */
        unsigned int hw_tss:1; /* TSS is supported. */
        unsigned int hw_rss:1; /* RSS is supported. */
@@ -177,6 +179,17 @@ int priv_mac_addr_add(struct priv *, unsigned int,
 void mlx5_mac_addr_add(struct rte_eth_dev *, struct ether_addr *, uint32_t,
                       uint32_t);
 
+/* mlx5_rxmode.c */
+
+int rxq_promiscuous_enable(struct rxq *);
+void mlx5_promiscuous_enable(struct rte_eth_dev *);
+void rxq_promiscuous_disable(struct rxq *);
+void mlx5_promiscuous_disable(struct rte_eth_dev *);
+int rxq_allmulticast_enable(struct rxq *);
+void mlx5_allmulticast_enable(struct rte_eth_dev *);
+void rxq_allmulticast_disable(struct rxq *);
+void mlx5_allmulticast_disable(struct rte_eth_dev *);
+
 /* mlx5_stats.c */
 
 void mlx5_stats_get(struct rte_eth_dev *, struct rte_eth_stats *);
index 0afc1bb..26b6d73 100644 (file)
@@ -605,6 +605,10 @@ mlx5_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
                if (!priv->rss) {
                        if (priv->started)
                                rxq_mac_addrs_add(rxq);
+                       if (priv->started && priv->promisc_req)
+                               rxq_promiscuous_enable(rxq);
+                       if (priv->started && priv->allmulti_req)
+                               rxq_allmulticast_enable(rxq);
                }
                /* Scattered burst function takes priority. */
                if (rxq->sp)
diff --git a/drivers/net/mlx5/mlx5_rxmode.c b/drivers/net/mlx5/mlx5_rxmode.c
new file mode 100644 (file)
index 0000000..7efa21b
--- /dev/null
@@ -0,0 +1,311 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2015 6WIND S.A.
+ *   Copyright 2015 Mellanox.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of 6WIND S.A. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+
+/* Verbs header. */
+/* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
+#ifdef PEDANTIC
+#pragma GCC diagnostic ignored "-pedantic"
+#endif
+#include <infiniband/verbs.h>
+#ifdef PEDANTIC
+#pragma GCC diagnostic error "-pedantic"
+#endif
+
+/* DPDK headers don't like -pedantic. */
+#ifdef PEDANTIC
+#pragma GCC diagnostic ignored "-pedantic"
+#endif
+#include <rte_ethdev.h>
+#ifdef PEDANTIC
+#pragma GCC diagnostic error "-pedantic"
+#endif
+
+#include "mlx5.h"
+#include "mlx5_rxtx.h"
+#include "mlx5_utils.h"
+
+/**
+ * Enable promiscuous mode in a RX queue.
+ *
+ * @param rxq
+ *   Pointer to RX queue structure.
+ *
+ * @return
+ *   0 on success, errno value on failure.
+ */
+int
+rxq_promiscuous_enable(struct rxq *rxq)
+{
+       struct ibv_flow *flow;
+       struct ibv_flow_attr attr = {
+               .type = IBV_FLOW_ATTR_ALL_DEFAULT,
+               .num_of_specs = 0,
+               .port = rxq->priv->port,
+               .flags = 0
+       };
+
+       if (rxq->priv->vf)
+               return 0;
+       if (rxq->promisc_flow != NULL)
+               return 0;
+       DEBUG("%p: enabling promiscuous mode", (void *)rxq);
+       errno = 0;
+       flow = ibv_create_flow(rxq->qp, &attr);
+       if (flow == NULL) {
+               /* It's not clear whether errno is always set in this case. */
+               ERROR("%p: flow configuration failed, errno=%d: %s",
+                     (void *)rxq, errno,
+                     (errno ? strerror(errno) : "Unknown error"));
+               if (errno)
+                       return errno;
+               return EINVAL;
+       }
+       rxq->promisc_flow = flow;
+       DEBUG("%p: promiscuous mode enabled", (void *)rxq);
+       return 0;
+}
+
+/**
+ * DPDK callback to enable promiscuous mode.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ */
+void
+mlx5_promiscuous_enable(struct rte_eth_dev *dev)
+{
+       struct priv *priv = dev->data->dev_private;
+       unsigned int i;
+       int ret;
+
+       priv_lock(priv);
+       priv->promisc_req = 1;
+       /* If device isn't started, this is all we need to do. */
+       if (!priv->started)
+               goto end;
+       if (priv->rss) {
+               ret = rxq_promiscuous_enable(&priv->rxq_parent);
+               if (ret) {
+                       priv_unlock(priv);
+                       return;
+               }
+               goto end;
+       }
+       for (i = 0; (i != priv->rxqs_n); ++i) {
+               if ((*priv->rxqs)[i] == NULL)
+                       continue;
+               ret = rxq_promiscuous_enable((*priv->rxqs)[i]);
+               if (!ret)
+                       continue;
+               /* Failure, rollback. */
+               while (i != 0)
+                       if ((*priv->rxqs)[--i] != NULL)
+                               rxq_promiscuous_disable((*priv->rxqs)[i]);
+               priv_unlock(priv);
+               return;
+       }
+end:
+       priv_unlock(priv);
+}
+
+/**
+ * Disable promiscuous mode in a RX queue.
+ *
+ * @param rxq
+ *   Pointer to RX queue structure.
+ */
+void
+rxq_promiscuous_disable(struct rxq *rxq)
+{
+       if (rxq->priv->vf)
+               return;
+       if (rxq->promisc_flow == NULL)
+               return;
+       DEBUG("%p: disabling promiscuous mode", (void *)rxq);
+       claim_zero(ibv_destroy_flow(rxq->promisc_flow));
+       rxq->promisc_flow = NULL;
+       DEBUG("%p: promiscuous mode disabled", (void *)rxq);
+}
+
+/**
+ * DPDK callback to disable promiscuous mode.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ */
+void
+mlx5_promiscuous_disable(struct rte_eth_dev *dev)
+{
+       struct priv *priv = dev->data->dev_private;
+       unsigned int i;
+
+       priv_lock(priv);
+       priv->promisc_req = 0;
+       if (priv->rss) {
+               rxq_promiscuous_disable(&priv->rxq_parent);
+               goto end;
+       }
+       for (i = 0; (i != priv->rxqs_n); ++i)
+               if ((*priv->rxqs)[i] != NULL)
+                       rxq_promiscuous_disable((*priv->rxqs)[i]);
+end:
+       priv_unlock(priv);
+}
+
+/**
+ * Enable allmulti mode in a RX queue.
+ *
+ * @param rxq
+ *   Pointer to RX queue structure.
+ *
+ * @return
+ *   0 on success, errno value on failure.
+ */
+int
+rxq_allmulticast_enable(struct rxq *rxq)
+{
+       struct ibv_flow *flow;
+       struct ibv_flow_attr attr = {
+               .type = IBV_FLOW_ATTR_MC_DEFAULT,
+               .num_of_specs = 0,
+               .port = rxq->priv->port,
+               .flags = 0
+       };
+
+       if (rxq->allmulti_flow != NULL)
+               return 0;
+       DEBUG("%p: enabling allmulticast mode", (void *)rxq);
+       errno = 0;
+       flow = ibv_create_flow(rxq->qp, &attr);
+       if (flow == NULL) {
+               /* It's not clear whether errno is always set in this case. */
+               ERROR("%p: flow configuration failed, errno=%d: %s",
+                     (void *)rxq, errno,
+                     (errno ? strerror(errno) : "Unknown error"));
+               if (errno)
+                       return errno;
+               return EINVAL;
+       }
+       rxq->allmulti_flow = flow;
+       DEBUG("%p: allmulticast mode enabled", (void *)rxq);
+       return 0;
+}
+
+/**
+ * DPDK callback to enable allmulti mode.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ */
+void
+mlx5_allmulticast_enable(struct rte_eth_dev *dev)
+{
+       struct priv *priv = dev->data->dev_private;
+       unsigned int i;
+       int ret;
+
+       priv_lock(priv);
+       priv->allmulti_req = 1;
+       /* If device isn't started, this is all we need to do. */
+       if (!priv->started)
+               goto end;
+       if (priv->rss) {
+               ret = rxq_allmulticast_enable(&priv->rxq_parent);
+               if (ret) {
+                       priv_unlock(priv);
+                       return;
+               }
+               goto end;
+       }
+       for (i = 0; (i != priv->rxqs_n); ++i) {
+               if ((*priv->rxqs)[i] == NULL)
+                       continue;
+               ret = rxq_allmulticast_enable((*priv->rxqs)[i]);
+               if (!ret)
+                       continue;
+               /* Failure, rollback. */
+               while (i != 0)
+                       if ((*priv->rxqs)[--i] != NULL)
+                               rxq_allmulticast_disable((*priv->rxqs)[i]);
+               priv_unlock(priv);
+               return;
+       }
+end:
+       priv_unlock(priv);
+}
+
+/**
+ * Disable allmulti mode in a RX queue.
+ *
+ * @param rxq
+ *   Pointer to RX queue structure.
+ */
+void
+rxq_allmulticast_disable(struct rxq *rxq)
+{
+       if (rxq->allmulti_flow == NULL)
+               return;
+       DEBUG("%p: disabling allmulticast mode", (void *)rxq);
+       claim_zero(ibv_destroy_flow(rxq->allmulti_flow));
+       rxq->allmulti_flow = NULL;
+       DEBUG("%p: allmulticast mode disabled", (void *)rxq);
+}
+
+/**
+ * DPDK callback to disable allmulti mode.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ */
+void
+mlx5_allmulticast_disable(struct rte_eth_dev *dev)
+{
+       struct priv *priv = dev->data->dev_private;
+       unsigned int i;
+
+       priv_lock(priv);
+       priv->allmulti_req = 0;
+       if (priv->rss) {
+               rxq_allmulticast_disable(&priv->rxq_parent);
+               goto end;
+       }
+       for (i = 0; (i != priv->rxqs_n); ++i)
+               if ((*priv->rxqs)[i] != NULL)
+                       rxq_allmulticast_disable((*priv->rxqs)[i]);
+end:
+       priv_unlock(priv);
+}
index 620ec70..1cd28c2 100644 (file)
@@ -398,6 +398,8 @@ rxq_cleanup(struct rxq *rxq)
                                                &params));
        }
        if (rxq->qp != NULL) {
+               rxq_promiscuous_disable(rxq);
+               rxq_allmulticast_disable(rxq);
                rxq_mac_addrs_del(rxq);
                claim_zero(ibv_destroy_qp(rxq->qp));
        }
@@ -580,8 +582,12 @@ rxq_rehash(struct rte_eth_dev *dev, struct rxq *rxq)
        }
        /* Remove attached flows if RSS is disabled (no parent queue). */
        if (!priv->rss) {
+               rxq_allmulticast_disable(&tmpl);
+               rxq_promiscuous_disable(&tmpl);
                rxq_mac_addrs_del(&tmpl);
                /* Update original queue in case of failure. */
+               rxq->allmulti_flow = tmpl.allmulti_flow;
+               rxq->promisc_flow = tmpl.promisc_flow;
                memcpy(rxq->mac_flow, tmpl.mac_flow, sizeof(rxq->mac_flow));
        }
        /* From now on, any failure will render the queue unusable.
@@ -621,7 +627,13 @@ rxq_rehash(struct rte_eth_dev *dev, struct rxq *rxq)
        if (!priv->rss) {
                if (priv->started)
                        rxq_mac_addrs_add(&tmpl);
+               if (priv->started && priv->promisc_req)
+                       rxq_promiscuous_enable(&tmpl);
+               if (priv->started && priv->allmulti_req)
+                       rxq_allmulticast_enable(&tmpl);
                /* Update original queue in case of failure. */
+               rxq->allmulti_flow = tmpl.allmulti_flow;
+               rxq->promisc_flow = tmpl.promisc_flow;
                memcpy(rxq->mac_flow, tmpl.mac_flow, sizeof(rxq->mac_flow));
        }
        /* Allocate pool. */
index 4183820..020acf0 100644 (file)
@@ -106,6 +106,8 @@ struct rxq {
        struct ibv_exp_cq_family *if_cq; /* CQ interface. */
        /* MAC flow steering rules. */
        struct ibv_flow *mac_flow[MLX5_MAX_MAC_ADDRESSES];
+       struct ibv_flow *promisc_flow; /* Promiscuous flow. */
+       struct ibv_flow *allmulti_flow; /* Multicast flow. */
        unsigned int port_id; /* Port ID for incoming packets. */
        unsigned int elts_n; /* (*elts)[] length. */
        unsigned int elts_head; /* Current index in (*elts)[]. */
index f5d965f..dced025 100644 (file)
@@ -86,6 +86,10 @@ mlx5_dev_start(struct rte_eth_dev *dev)
                if (rxq == NULL)
                        continue;
                ret = rxq_mac_addrs_add(rxq);
+               if (!ret && priv->promisc_req)
+                       ret = rxq_promiscuous_enable(rxq);
+               if (!ret && priv->allmulti_req)
+                       ret = rxq_allmulticast_enable(rxq);
                if (!ret)
                        continue;
                WARN("%p: QP flow attachment failed: %s",
@@ -94,6 +98,8 @@ mlx5_dev_start(struct rte_eth_dev *dev)
                while (i != 0) {
                        rxq = (*priv->rxqs)[--i];
                        if (rxq != NULL) {
+                               rxq_allmulticast_disable(rxq);
+                               rxq_promiscuous_disable(rxq);
                                rxq_mac_addrs_del(rxq);
                        }
                }
@@ -140,6 +146,8 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
                /* Ignore nonexistent RX queues. */
                if (rxq == NULL)
                        continue;
+               rxq_allmulticast_disable(rxq);
+               rxq_promiscuous_disable(rxq);
                rxq_mac_addrs_del(rxq);
        } while ((--r) && ((rxq = (*priv->rxqs)[++i]), i));
        priv_unlock(priv);