net/mlx4: separate Rx/Tx definitions
[dpdk.git] / drivers / net / mlx4 / mlx4_flow.c
index edfac03..61455ce 100644 (file)
@@ -2,7 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright 2017 6WIND S.A.
- *   Copyright 2017 Mellanox.
+ *   Copyright 2017 Mellanox
  *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
 #include <rte_flow_driver.h>
 #include <rte_malloc.h>
 
-/* Generated configuration header. */
-#include "mlx4_autoconf.h"
-
 /* PMD headers. */
 #include "mlx4.h"
 #include "mlx4_flow.h"
+#include "mlx4_rxtx.h"
+#include "mlx4_utils.h"
 
 /** Static initializer for items. */
 #define ITEMS(...) \
@@ -706,13 +705,9 @@ mlx4_flow_validate(struct rte_eth_dev *dev,
                   struct rte_flow_error *error)
 {
        struct priv *priv = dev->data->dev_private;
-       int ret;
        struct mlx4_flow flow = { .offset = sizeof(struct ibv_flow_attr) };
 
-       priv_lock(priv);
-       ret = priv_flow_validate(priv, attr, items, actions, error, &flow);
-       priv_unlock(priv);
-       return ret;
+       return priv_flow_validate(priv, attr, items, actions, error, &flow);
 }
 
 /**
@@ -755,29 +750,21 @@ mlx4_flow_create_drop_queue(struct priv *priv)
                ERROR("Cannot allocate memory for drop struct");
                goto err;
        }
-       cq = ibv_exp_create_cq(priv->ctx, 1, NULL, NULL, 0,
-                             &(struct ibv_exp_cq_init_attr){
-                                       .comp_mask = 0,
-                             });
+       cq = ibv_create_cq(priv->ctx, 1, NULL, NULL, 0);
        if (!cq) {
                ERROR("Cannot create drop CQ");
                goto err_create_cq;
        }
-       qp = ibv_exp_create_qp(priv->ctx,
-                             &(struct ibv_exp_qp_init_attr){
-                                       .send_cq = cq,
-                                       .recv_cq = cq,
-                                       .cap = {
-                                               .max_recv_wr = 1,
-                                               .max_recv_sge = 1,
-                                       },
-                                       .qp_type = IBV_QPT_RAW_PACKET,
-                                       .comp_mask =
-                                               IBV_EXP_QP_INIT_ATTR_PD |
-                                               IBV_EXP_QP_INIT_ATTR_PORT,
-                                       .pd = priv->pd,
-                                       .port_num = priv->port,
-                             });
+       qp = ibv_create_qp(priv->pd,
+                          &(struct ibv_qp_init_attr){
+                               .send_cq = cq,
+                               .recv_cq = cq,
+                               .cap = {
+                                       .max_recv_wr = 1,
+                                       .max_recv_sge = 1,
+                               },
+                               .qp_type = IBV_QPT_RAW_PACKET,
+                          });
        if (!qp) {
                ERROR("Cannot create drop QP");
                goto err_create_qp;
@@ -829,7 +816,7 @@ priv_flow_create_action_queue(struct priv *priv,
                return NULL;
        }
        if (action->drop) {
-               qp = priv->flow_drop_queue->qp;
+               qp = priv->flow_drop_queue ? priv->flow_drop_queue->qp : NULL;
        } else {
                struct rxq *rxq = (*priv->rxqs)[action->queue_id];
 
@@ -837,6 +824,8 @@ priv_flow_create_action_queue(struct priv *priv,
                rte_flow->qp = qp;
        }
        rte_flow->ibv_attr = ibv_attr;
+       if (!priv->started)
+               return rte_flow;
        rte_flow->ibv_flow = ibv_create_flow(qp, rte_flow->ibv_attr);
        if (!rte_flow->ibv_flow) {
                rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
@@ -844,36 +833,25 @@ priv_flow_create_action_queue(struct priv *priv,
                goto error;
        }
        return rte_flow;
-
 error:
        rte_free(rte_flow);
        return NULL;
 }
 
 /**
- * Convert a flow.
- *
- * @param priv
- *   Pointer to private structure.
- * @param[in] attr
- *   Flow rule attributes.
- * @param[in] items
- *   Pattern specification (list terminated by the END pattern item).
- * @param[in] actions
- *   Associated actions (list terminated by the END action).
- * @param[out] error
- *   Perform verbose error reporting if not NULL.
+ * Create a flow.
  *
- * @return
- *   A flow on success, NULL otherwise.
+ * @see rte_flow_create()
+ * @see rte_flow_ops
  */
-static struct rte_flow *
-priv_flow_create(struct priv *priv,
+struct rte_flow *
+mlx4_flow_create(struct rte_eth_dev *dev,
                 const struct rte_flow_attr *attr,
                 const struct rte_flow_item items[],
                 const struct rte_flow_action actions[],
                 struct rte_flow_error *error)
 {
+       struct priv *priv = dev->data->dev_private;
        struct rte_flow *rte_flow;
        struct mlx4_flow_action action;
        struct mlx4_flow flow = { .offset = sizeof(struct ibv_flow_attr), };
@@ -923,57 +901,48 @@ priv_flow_create(struct priv *priv,
        }
        rte_flow = priv_flow_create_action_queue(priv, flow.ibv_attr,
                                                 &action, error);
-       if (rte_flow)
+       if (rte_flow) {
+               LIST_INSERT_HEAD(&priv->flows, rte_flow, next);
+               DEBUG("Flow created %p", (void *)rte_flow);
                return rte_flow;
+       }
 exit:
        rte_free(flow.ibv_attr);
        return NULL;
 }
 
 /**
- * Create a flow.
+ * @see rte_flow_isolate()
  *
- * @see rte_flow_create()
- * @see rte_flow_ops
+ * Must be done before calling dev_configure().
+ *
+ * @param dev
+ *   Pointer to the ethernet device structure.
+ * @param enable
+ *   Nonzero to enter isolated mode, attempt to leave it otherwise.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative value on error.
  */
-struct rte_flow *
-mlx4_flow_create(struct rte_eth_dev *dev,
-                const struct rte_flow_attr *attr,
-                const struct rte_flow_item items[],
-                const struct rte_flow_action actions[],
-                struct rte_flow_error *error)
+int
+mlx4_flow_isolate(struct rte_eth_dev *dev,
+                 int enable,
+                 struct rte_flow_error *error)
 {
        struct priv *priv = dev->data->dev_private;
-       struct rte_flow *flow;
 
-       priv_lock(priv);
-       flow = priv_flow_create(priv, attr, items, actions, error);
-       if (flow) {
-               LIST_INSERT_HEAD(&priv->flows, flow, next);
-               DEBUG("Flow created %p", (void *)flow);
+       if (priv->rxqs) {
+               rte_flow_error_set(error, ENOTSUP,
+                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                  NULL, "isolated mode must be set"
+                                  " before configuring the device");
+               return -rte_errno;
        }
-       priv_unlock(priv);
-       return flow;
-}
-
-/**
- * Destroy a flow.
- *
- * @param priv
- *   Pointer to private structure.
- * @param[in] flow
- *   Flow to destroy.
- */
-static void
-priv_flow_destroy(struct priv *priv, struct rte_flow *flow)
-{
-       (void)priv;
-       LIST_REMOVE(flow, next);
-       if (flow->ibv_flow)
-               claim_zero(ibv_destroy_flow(flow->ibv_flow));
-       rte_free(flow->ibv_attr);
-       DEBUG("Flow destroyed %p", (void *)flow);
-       rte_free(flow);
+       priv->isolated = !!enable;
+       return 0;
 }
 
 /**
@@ -987,32 +956,17 @@ mlx4_flow_destroy(struct rte_eth_dev *dev,
                  struct rte_flow *flow,
                  struct rte_flow_error *error)
 {
-       struct priv *priv = dev->data->dev_private;
-
+       (void)dev;
        (void)error;
-       priv_lock(priv);
-       priv_flow_destroy(priv, flow);
-       priv_unlock(priv);
+       LIST_REMOVE(flow, next);
+       if (flow->ibv_flow)
+               claim_zero(ibv_destroy_flow(flow->ibv_flow));
+       rte_free(flow->ibv_attr);
+       DEBUG("Flow destroyed %p", (void *)flow);
+       rte_free(flow);
        return 0;
 }
 
-/**
- * Destroy all flows.
- *
- * @param priv
- *   Pointer to private structure.
- */
-static void
-priv_flow_flush(struct priv *priv)
-{
-       while (!LIST_EMPTY(&priv->flows)) {
-               struct rte_flow *flow;
-
-               flow = LIST_FIRST(&priv->flows);
-               priv_flow_destroy(priv, flow);
-       }
-}
-
 /**
  * Destroy all flows.
  *
@@ -1025,10 +979,12 @@ mlx4_flow_flush(struct rte_eth_dev *dev,
 {
        struct priv *priv = dev->data->dev_private;
 
-       (void)error;
-       priv_lock(priv);
-       priv_flow_flush(priv);
-       priv_unlock(priv);
+       while (!LIST_EMPTY(&priv->flows)) {
+               struct rte_flow *flow;
+
+               flow = LIST_FIRST(&priv->flows);
+               mlx4_flow_destroy(dev, flow, error);
+       }
        return 0;
 }