RSS hash configuration is currently ignored by the PMD, this commits
removes the RSS feature on promiscuous mode.

This functionality will be added in a later commit.

Signed-off-by: Nelio Laranjeiro <nelio.laranje...@6wind.com>
---
 drivers/net/mlx5/mlx5.c         |   1 +
 drivers/net/mlx5/mlx5.h         |  15 +++--
 drivers/net/mlx5/mlx5_flow.c    | 127 ++++++++++++++++++++++++++++++++++++----
 drivers/net/mlx5/mlx5_rxmode.c  |  52 +++++-----------
 drivers/net/mlx5/mlx5_rxq.c     |   8 +--
 drivers/net/mlx5/mlx5_rxtx.h    |   3 -
 drivers/net/mlx5/mlx5_trigger.c |  20 +++++--
 7 files changed, 158 insertions(+), 68 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index 52cbb20..f000404 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -775,6 +775,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv, struct 
rte_pci_device *pci_dev)
                priv->dev = eth_dev;
                eth_dev->dev_ops = &mlx5_dev_ops;
                TAILQ_INIT(&priv->flows);
+               TAILQ_INIT(&priv->ctrl_flows);
 
                /* Bring Ethernet device up. */
                DEBUG("forcing Ethernet interface up");
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 3c2e719..cbf8849 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -39,6 +39,7 @@
 #include <limits.h>
 #include <net/if.h>
 #include <netinet/in.h>
+#include <sys/queue.h>
 
 /* Verbs header. */
 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
@@ -86,6 +87,9 @@ struct mlx5_xstats_ctrl {
        uint64_t base[MLX5_MAX_XSTATS];
 };
 
+/* Flow list . */
+TAILQ_HEAD(mlx5_flows, rte_flow);
+
 struct priv {
        struct rte_eth_dev *dev; /* Ethernet device. */
        struct ibv_context *ctx; /* Verbs context. */
@@ -103,7 +107,6 @@ struct priv {
        /* Device properties. */
        uint16_t mtu; /* Configured MTU. */
        uint8_t port; /* Physical port number. */
-       unsigned int promisc_req:1; /* Promiscuous mode requested. */
        unsigned int allmulti_req:1; /* All multicast mode requested. */
        unsigned int hw_csum:1; /* Checksum offload is supported. */
        unsigned int hw_csum_l2tun:1; /* Same for L2 tunnels. */
@@ -143,7 +146,8 @@ struct priv {
        struct rte_intr_handle intr_handle; /* Interrupt handler. */
        unsigned int (*reta_idx)[]; /* RETA index table. */
        unsigned int reta_idx_n; /* RETA index size. */
-       TAILQ_HEAD(mlx5_flows, rte_flow) flows; /* RTE Flow rules. */
+       struct mlx5_flows flows; /* RTE Flow rules. */
+       struct mlx5_flows ctrl_flows; /* Control flow rules. */
        LIST_HEAD(mr, mlx5_mr) mr; /* Memory region. */
        LIST_HEAD(rxq, mlx5_rxq_ctrl) rxqsctrl; /* DPDK Rx queues. */
        LIST_HEAD(rxqibv, mlx5_rxq_ibv) rxqsibv; /* Verbs Rx queues. */
@@ -289,11 +293,14 @@ struct rte_flow *mlx5_flow_create(struct rte_eth_dev *,
                                  struct rte_flow_error *);
 int mlx5_flow_destroy(struct rte_eth_dev *, struct rte_flow *,
                      struct rte_flow_error *);
+void priv_flow_flush(struct priv *, struct mlx5_flows *);
 int mlx5_flow_flush(struct rte_eth_dev *, struct rte_flow_error *);
 int mlx5_flow_isolate(struct rte_eth_dev *, int, struct rte_flow_error *);
-int priv_flow_start(struct priv *);
-void priv_flow_stop(struct priv *);
+int priv_flow_start(struct priv *, struct mlx5_flows *);
+void priv_flow_stop(struct priv *, struct mlx5_flows *);
 int priv_flow_verify(struct priv *);
+int mlx5_flow_ctrl(struct rte_eth_dev *, struct rte_flow_item_eth *,
+                  struct rte_flow_item_eth *, unsigned int, unsigned int);
 
 /* mlx5_mr.c */
 
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 90deb30..39a49af 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -1169,11 +1169,14 @@ mlx5_flow_create(struct rte_eth_dev *dev,
  *
  * @param priv
  *   Pointer to private structure.
+ * @param list
+ *   Pointer to a TAILQ flow list.
  * @param[in] flow
  *   Flow to destroy.
  */
 static void
 priv_flow_destroy(struct priv *priv,
+                 struct mlx5_flows *list,
                  struct rte_flow *flow)
 {
        unsigned int i;
@@ -1193,7 +1196,7 @@ priv_flow_destroy(struct priv *priv,
                 * To remove the mark from the queue, the queue must not be
                 * present in any other marked flow (RSS or not).
                 */
-               TAILQ_FOREACH(tmp, &priv->flows, next) {
+               TAILQ_FOREACH(tmp, list, next) {
                        unsigned int j;
 
                        if (!tmp->mark)
@@ -1208,7 +1211,7 @@ priv_flow_destroy(struct priv *priv,
                rxq->mark = mark;
        }
 out:
-       TAILQ_REMOVE(&priv->flows, flow, next);
+       TAILQ_REMOVE(list, flow, next);
        if (flow->ibv_flow)
                claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
        mlx5_priv_hrxq_release(priv, flow->hrxq);
@@ -1232,7 +1235,7 @@ mlx5_flow_destroy(struct rte_eth_dev *dev,
 
        (void)error;
        priv_lock(priv);
-       priv_flow_destroy(priv, flow);
+       priv_flow_destroy(priv, &priv->flows, flow);
        priv_unlock(priv);
        return 0;
 }
@@ -1242,15 +1245,17 @@ mlx5_flow_destroy(struct rte_eth_dev *dev,
  *
  * @param priv
  *   Pointer to private structure.
+ * @param list
+ *   Pointer to a TAILQ flow list.
  */
-static void
-priv_flow_flush(struct priv *priv)
+void
+priv_flow_flush(struct priv *priv, struct mlx5_flows *list)
 {
-       while (!TAILQ_EMPTY(&priv->flows)) {
+       while (!TAILQ_EMPTY(list)) {
                struct rte_flow *flow;
 
-               flow = TAILQ_FIRST(&priv->flows);
-               priv_flow_destroy(priv, flow);
+               flow = TAILQ_FIRST(list);
+               priv_flow_destroy(priv, list, flow);
        }
 }
 
@@ -1268,7 +1273,7 @@ mlx5_flow_flush(struct rte_eth_dev *dev,
 
        (void)error;
        priv_lock(priv);
-       priv_flow_flush(priv);
+       priv_flow_flush(priv, &priv->flows);
        priv_unlock(priv);
        return 0;
 }
@@ -1280,13 +1285,15 @@ mlx5_flow_flush(struct rte_eth_dev *dev,
  *
  * @param priv
  *   Pointer to private structure.
+ * @param list
+ *   Pointer to a TAILQ flow list.
  */
 void
-priv_flow_stop(struct priv *priv)
+priv_flow_stop(struct priv *priv, struct mlx5_flows *list)
 {
        struct rte_flow *flow;
 
-       TAILQ_FOREACH_REVERSE(flow, &priv->flows, mlx5_flows, next) {
+       TAILQ_FOREACH_REVERSE(flow, list, mlx5_flows, next) {
                unsigned int i;
 
                claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
@@ -1303,16 +1310,18 @@ priv_flow_stop(struct priv *priv)
  *
  * @param priv
  *   Pointer to private structure.
+ * @param list
+ *   Pointer to a TAILQ flow list.
  *
  * @return
  *   0 on success, a errno value otherwise and rte_errno is set.
  */
 int
-priv_flow_start(struct priv *priv)
+priv_flow_start(struct priv *priv, struct mlx5_flows *list)
 {
        struct rte_flow *flow;
 
-       TAILQ_FOREACH(flow, &priv->flows, next) {
+       TAILQ_FOREACH(flow, list, next) {
                flow->ibv_flow = ibv_exp_create_flow(flow->hrxq->qp,
                                                     flow->ibv_attr);
                if (!flow->ibv_flow) {
@@ -1381,3 +1390,95 @@ priv_flow_verify(struct priv *priv)
        }
        return ret;
 }
+
+/**
+ * Enable/disable a flow control configured from the control plane.
+ *
+ * @param dev
+ *   Pointer to Ethernet device.
+ * @param spec
+ *   An Ethernet flow spec to apply.
+ * @param mask
+ *   An Ethernet flow mask to apply.
+ * @param priority
+ *   The flow priority.
+ * @param enable
+ *   Enable/disable the flow.
+ *
+ * @return
+ *   0 on success.
+ */
+int
+mlx5_flow_ctrl(struct rte_eth_dev *dev,
+              struct rte_flow_item_eth *spec,
+              struct rte_flow_item_eth *mask,
+              unsigned int priority,
+              unsigned int enable)
+{
+       struct priv *priv = dev->data->dev_private;
+       const struct rte_flow_attr attr = {
+               .priority = priority,
+               .ingress = 1,
+       };
+       struct rte_flow_item items[] = {
+               {
+                       .type = RTE_FLOW_ITEM_TYPE_ETH,
+                       .spec = spec,
+                       .last = NULL,
+                       .mask = mask,
+               },
+               {
+                       .type = RTE_FLOW_ITEM_TYPE_END,
+               },
+       };
+       struct rte_flow_action actions[] = {
+               {
+                       .type = RTE_FLOW_ACTION_TYPE_QUEUE,
+                       .conf = &(struct rte_flow_action_queue){
+                               .index = 0,
+                       },
+               },
+               {
+                       .type = RTE_FLOW_ACTION_TYPE_END,
+               },
+       };
+       struct rte_flow *flow;
+       struct rte_flow_error error;
+
+       if (enable) {
+               flow = priv_flow_create(priv, &attr, items, actions, &error);
+               if (!flow) {
+                       return 1;
+               }
+               TAILQ_INSERT_TAIL(&priv->ctrl_flows, flow, next);
+               DEBUG("Control flow created %p", (void *)flow);
+       } else {
+               struct spec {
+                       struct ibv_exp_flow_attr ibv_attr;
+                       struct ibv_exp_flow_spec_eth eth;
+               } spec;
+               struct mlx5_flow_parse parser = {
+                       .ibv_attr = &spec.ibv_attr,
+                       .offset = sizeof(struct ibv_exp_flow_attr),
+               };
+               struct ibv_exp_flow_spec_eth *eth;
+               const unsigned int attr_size = sizeof(struct ibv_exp_flow_attr);
+
+               claim_zero(mlx5_flow_create_eth(&items[0], NULL, &parser));
+               TAILQ_FOREACH(flow, &priv->ctrl_flows, next) {
+                       eth = (void *)((uintptr_t)flow->ibv_attr + attr_size);
+                       assert(eth->type == IBV_EXP_FLOW_SPEC_ETH);
+                       if (!memcmp(eth, &spec.eth, sizeof(*eth)))
+                               break;
+               }
+               if (flow) {
+                       claim_zero(ibv_exp_destroy_flow(flow->ibv_flow));
+                       mlx5_priv_hrxq_release(priv, flow->hrxq);
+                       rte_free(flow->ibv_attr);
+                       DEBUG("Control flow destroyed %p", (void *)flow);
+                       TAILQ_REMOVE(&priv->ctrl_flows, flow, next);
+                       rte_free(flow);
+               }
+       }
+       return 0;
+}
diff --git a/drivers/net/mlx5/mlx5_rxmode.c b/drivers/net/mlx5/mlx5_rxmode.c
index 4a51e47..d6ca907 100644
--- a/drivers/net/mlx5/mlx5_rxmode.c
+++ b/drivers/net/mlx5/mlx5_rxmode.c
@@ -53,20 +53,6 @@
 
 /* Initialization data for special flows. */
 static const struct special_flow_init special_flow_init[] = {
-       [HASH_RXQ_FLOW_TYPE_PROMISC] = {
-               .dst_mac_val = "\x00\x00\x00\x00\x00\x00",
-               .dst_mac_mask = "\x00\x00\x00\x00\x00\x00",
-               .hash_types =
-                       1 << HASH_RXQ_TCPV4 |
-                       1 << HASH_RXQ_UDPV4 |
-                       1 << HASH_RXQ_IPV4 |
-                       1 << HASH_RXQ_TCPV6 |
-                       1 << HASH_RXQ_UDPV6 |
-                       1 << HASH_RXQ_IPV6 |
-                       1 << HASH_RXQ_ETH |
-                       0,
-               .per_vlan = 0,
-       },
        [HASH_RXQ_FLOW_TYPE_ALLMULTI] = {
                .dst_mac_val = "\x01\x00\x00\x00\x00\x00",
                .dst_mac_mask = "\x01\x00\x00\x00\x00\x00",
@@ -342,7 +328,7 @@ priv_special_flow_enable_all(struct priv *priv)
 
        if (priv->isolated)
                return 0;
-       for (flow_type = HASH_RXQ_FLOW_TYPE_PROMISC;
+       for (flow_type = HASH_RXQ_FLOW_TYPE_ALLMULTI;
                        flow_type != HASH_RXQ_FLOW_TYPE_MAC;
                        ++flow_type) {
                int ret;
@@ -369,7 +355,7 @@ priv_special_flow_disable_all(struct priv *priv)
 {
        enum hash_rxq_flow_type flow_type;
 
-       for (flow_type = HASH_RXQ_FLOW_TYPE_PROMISC;
+       for (flow_type = HASH_RXQ_FLOW_TYPE_ALLMULTI;
                        flow_type != HASH_RXQ_FLOW_TYPE_MAC;
                        ++flow_type)
                priv_special_flow_disable(priv, flow_type);
@@ -384,19 +370,16 @@ priv_special_flow_disable_all(struct priv *priv)
 void
 mlx5_promiscuous_enable(struct rte_eth_dev *dev)
 {
-       struct priv *priv = dev->data->dev_private;
-       int ret;
+       struct rte_flow_item_eth eth = {
+               .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
+               .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
+               .type = 0,
+       };
 
        if (mlx5_is_secondary())
                return;
-
-       priv_lock(priv);
-       priv->promisc_req = 1;
-       ret = priv_rehash_flows(priv);
-       if (ret)
-               ERROR("error while enabling promiscuous mode: %s",
-                     strerror(ret));
-       priv_unlock(priv);
+       dev->data->promiscuous = 1;
+       claim_zero(mlx5_flow_ctrl(dev, &eth, &eth, 3, 1));
 }
 
 /**
@@ -408,19 +391,16 @@ mlx5_promiscuous_enable(struct rte_eth_dev *dev)
 void
 mlx5_promiscuous_disable(struct rte_eth_dev *dev)
 {
-       struct priv *priv = dev->data->dev_private;
-       int ret;
+       struct rte_flow_item_eth eth = {
+               .dst.addr_bytes = "\x00\x00\x00\x00\x00\x00",
+               .src.addr_bytes = "\x00\x00\x00\x00\x00\x00",
+               .type = 0,
+       };
 
        if (mlx5_is_secondary())
                return;
-
-       priv_lock(priv);
-       priv->promisc_req = 0;
-       ret = priv_rehash_flows(priv);
-       if (ret)
-               ERROR("error while disabling promiscuous mode: %s",
-                     strerror(ret));
-       priv_unlock(priv);
+       dev->data->promiscuous = 0;
+       claim_zero(mlx5_flow_ctrl(dev, &eth, &eth, 3, 0));
 }
 
 /**
diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
index 076b575..5f9e84a 100644
--- a/drivers/net/mlx5/mlx5_rxq.c
+++ b/drivers/net/mlx5/mlx5_rxq.c
@@ -573,13 +573,7 @@ priv_destroy_hash_rxqs(struct priv *priv)
 int
 priv_allow_flow_type(struct priv *priv, enum hash_rxq_flow_type type)
 {
-       /* Only FLOW_TYPE_PROMISC is allowed when promiscuous mode
-        * has been requested. */
-       if (priv->promisc_req)
-               return type == HASH_RXQ_FLOW_TYPE_PROMISC;
        switch (type) {
-       case HASH_RXQ_FLOW_TYPE_PROMISC:
-               return !!priv->promisc_req;
        case HASH_RXQ_FLOW_TYPE_ALLMULTI:
                return !!priv->allmulti_req;
        case HASH_RXQ_FLOW_TYPE_BROADCAST:
@@ -610,7 +604,7 @@ priv_rehash_flows(struct priv *priv)
 {
        enum hash_rxq_flow_type i;
 
-       for (i = HASH_RXQ_FLOW_TYPE_PROMISC;
+       for (i = HASH_RXQ_FLOW_TYPE_ALLMULTI;
                        i != RTE_DIM((*priv->hash_rxqs)[0].special_flow);
                        ++i)
                if (!priv_allow_flow_type(priv, i)) {
diff --git a/drivers/net/mlx5/mlx5_rxtx.h b/drivers/net/mlx5/mlx5_rxtx.h
index 6397a50..166cd5d 100644
--- a/drivers/net/mlx5/mlx5_rxtx.h
+++ b/drivers/net/mlx5/mlx5_rxtx.h
@@ -233,7 +233,6 @@ struct special_flow_init {
 };
 
 enum hash_rxq_flow_type {
-       HASH_RXQ_FLOW_TYPE_PROMISC,
        HASH_RXQ_FLOW_TYPE_ALLMULTI,
        HASH_RXQ_FLOW_TYPE_BROADCAST,
        HASH_RXQ_FLOW_TYPE_IPV6MULTI,
@@ -245,8 +244,6 @@ static inline const char *
 hash_rxq_flow_type_str(enum hash_rxq_flow_type flow_type)
 {
        switch (flow_type) {
-       case HASH_RXQ_FLOW_TYPE_PROMISC:
-               return "promiscuous";
        case HASH_RXQ_FLOW_TYPE_ALLMULTI:
                return "allmulticast";
        case HASH_RXQ_FLOW_TYPE_BROADCAST:
diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c
index bedce0a..ead8238 100644
--- a/drivers/net/mlx5/mlx5_trigger.c
+++ b/drivers/net/mlx5/mlx5_trigger.c
@@ -165,7 +165,16 @@ mlx5_dev_start(struct rte_eth_dev *dev)
                      (void *)priv, strerror(err));
                goto error;
        }
-       err = priv_flow_start(priv);
+       if (dev->data->promiscuous)
+              mlx5_promiscuous_enable(dev);
+       err = priv_flow_start(priv, &priv->ctrl_flows);
+       if (err) {
+               ERROR("%p: an error occurred while configuring control flows:"
+                     " %s",
+                     (void *)priv, strerror(err));
+               goto error;
+       }
+       err = priv_flow_start(priv, &priv->flows);
        if (err) {
                ERROR("%p: an error occurred while configuring flows:"
                      " %s",
@@ -189,7 +198,8 @@ mlx5_dev_start(struct rte_eth_dev *dev)
        priv_special_flow_disable_all(priv);
        priv_mac_addrs_disable(priv);
        priv_destroy_hash_rxqs(priv);
-       priv_flow_stop(priv);
+       priv_flow_stop(priv, &priv->flows);
+       priv_flow_flush(priv, &priv->ctrl_flows);
        priv_rxq_stop(priv);
        priv_txq_stop(priv);
        priv_unlock(priv);
@@ -218,13 +228,13 @@ mlx5_dev_stop(struct rte_eth_dev *dev)
        priv_special_flow_disable_all(priv);
        priv_mac_addrs_disable(priv);
        priv_destroy_hash_rxqs(priv);
-       priv_flow_stop(priv);
-       priv_rx_intr_vec_disable(priv);
+       priv_flow_stop(priv, &priv->flows);
+       priv_flow_flush(priv, &priv->ctrl_flows);
        LIST_FOREACH(mr, &priv->mr, next) {
                priv_mr_release(priv, mr);
        }
        priv_txq_stop(priv);
        priv_rxq_stop(priv);
-       priv_dev_interrupt_handler_uninstall(priv, dev);
+       priv_rx_intr_vec_disable(priv);
        priv_unlock(priv);
 }
-- 
2.1.4

Reply via email to