net/mlx5: add flow sync API
[dpdk.git] / drivers / net / mlx5 / mlx5_flow.c
index 0c496ee..e2af7a9 100644 (file)
@@ -31,6 +31,7 @@
 #include "mlx5_flow_os.h"
 #include "mlx5_rxtx.h"
 #include "mlx5_common_os.h"
+#include "rte_pmd_mlx5.h"
 
 static struct mlx5_flow_tunnel *
 mlx5_find_tunnel_id(struct rte_eth_dev *dev, uint32_t id);
@@ -1793,6 +1794,8 @@ mlx5_flow_validate_attributes(struct rte_eth_dev *dev,
  *   Item specification.
  * @param[in] item_flags
  *   Bit-fields that holds the items detected until now.
+ * @param[in] ext_vlan_sup
+ *   Whether extended VLAN features are supported or not.
  * @param[out] error
  *   Pointer to error structure.
  *
@@ -1913,7 +1916,7 @@ mlx5_flow_validate_item_icmp(const struct rte_flow_item *item,
  */
 int
 mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
-                           uint64_t item_flags,
+                           uint64_t item_flags, bool ext_vlan_sup,
                            struct rte_flow_error *error)
 {
        const struct rte_flow_item_eth *mask = item->mask;
@@ -1921,6 +1924,7 @@ mlx5_flow_validate_item_eth(const struct rte_flow_item *item,
                .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff",
                .src.addr_bytes = "\xff\xff\xff\xff\xff\xff",
                .type = RTE_BE16(0xffff),
+               .has_vlan = ext_vlan_sup ? 1 : 0,
        };
        int ret;
        int tunnel = !!(item_flags & MLX5_FLOW_LAYER_TUNNEL);
@@ -3039,6 +3043,14 @@ flow_null_query(struct rte_eth_dev *dev __rte_unused,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, NULL);
 }
 
+static int
+flow_null_sync_domain(struct rte_eth_dev *dev __rte_unused,
+                     uint32_t domains __rte_unused,
+                     uint32_t flags __rte_unused)
+{
+       return 0;
+}
+
 /* Void driver to protect from null pointer reference. */
 const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
        .validate = flow_null_validate,
@@ -3048,6 +3060,7 @@ const struct mlx5_flow_driver_ops mlx5_flow_null_drv_ops = {
        .remove = flow_null_remove,
        .destroy = flow_null_destroy,
        .query = flow_null_query,
+       .sync_domain = flow_null_sync_domain,
 };
 
 /**
@@ -3617,6 +3630,7 @@ flow_check_hairpin_split(struct rte_eth_dev *dev,
        const struct rte_flow_action_queue *queue;
        const struct rte_flow_action_rss *rss;
        const struct rte_flow_action_raw_encap *raw_encap;
+       const struct rte_eth_hairpin_conf *conf;
 
        if (!attr->ingress)
                return 0;
@@ -3626,8 +3640,8 @@ flow_check_hairpin_split(struct rte_eth_dev *dev,
                        queue = actions->conf;
                        if (queue == NULL)
                                return 0;
-                       if (mlx5_rxq_get_type(dev, queue->index) !=
-                           MLX5_RXQ_TYPE_HAIRPIN)
+                       conf = mlx5_rxq_get_hairpin_conf(dev, queue->index);
+                       if (conf != NULL && !!conf->tx_explicit)
                                return 0;
                        queue_action = 1;
                        action_n++;
@@ -3636,8 +3650,8 @@ flow_check_hairpin_split(struct rte_eth_dev *dev,
                        rss = actions->conf;
                        if (rss == NULL || rss->queue_num == 0)
                                return 0;
-                       if (mlx5_rxq_get_type(dev, rss->queue[0]) !=
-                           MLX5_RXQ_TYPE_HAIRPIN)
+                       conf = mlx5_rxq_get_hairpin_conf(dev, rss->queue[0]);
+                       if (conf != NULL && !!conf->tx_explicit)
                                return 0;
                        queue_action = 1;
                        action_n++;
@@ -8164,3 +8178,24 @@ err:
                mlx5_free(thub);
        return err;
 }
+
+#ifndef HAVE_MLX5DV_DR
+#define MLX5_DOMAIN_SYNC_FLOW ((1 << 0) | (1 << 1))
+#else
+#define MLX5_DOMAIN_SYNC_FLOW \
+       (MLX5DV_DR_DOMAIN_SYNC_FLAGS_SW | MLX5DV_DR_DOMAIN_SYNC_FLAGS_HW)
+#endif
+
+int rte_pmd_mlx5_sync_flow(uint16_t port_id, uint32_t domains)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct mlx5_flow_driver_ops *fops;
+       int ret;
+       struct rte_flow_attr attr = { .transfer = 0 };
+
+       fops = flow_get_drv_ops(flow_get_drv_type(dev, &attr));
+       ret = fops->sync_domain(dev, domains, MLX5_DOMAIN_SYNC_FLOW);
+       if (ret > 0)
+               ret = -ret;
+       return ret;
+}