net/mlx5: use correct field in a union structure
[dpdk.git] / drivers / net / mlx5 / mlx5_flow.c
index c385f6c..ec6d00f 100644 (file)
@@ -538,7 +538,7 @@ struct ibv_spec_header {
 };
 
 /**
- * Check support for a given item.
+ * Check item is fully supported by the NIC matching capability.
  *
  * @param item[in]
  *   Item specification.
@@ -555,60 +555,33 @@ static int
 mlx5_flow_item_validate(const struct rte_flow_item *item,
                        const uint8_t *mask, unsigned int size)
 {
-       if (!item->spec && (item->mask || item->last)) {
-               rte_errno = EINVAL;
-               return -rte_errno;
-       }
-       if (item->spec && !item->mask) {
-               unsigned int i;
-               const uint8_t *spec = item->spec;
-
-               for (i = 0; i < size; ++i)
-                       if ((spec[i] | mask[i]) != mask[i]) {
-                               rte_errno = EINVAL;
-                               return -rte_errno;
-                       }
-       }
-       if (item->last && !item->mask) {
-               unsigned int i;
-               const uint8_t *spec = item->last;
-
-               for (i = 0; i < size; ++i)
-                       if ((spec[i] | mask[i]) != mask[i]) {
-                               rte_errno = EINVAL;
-                               return -rte_errno;
-                       }
-       }
-       if (item->mask) {
-               unsigned int i;
-               const uint8_t *spec = item->spec;
-
-               for (i = 0; i < size; ++i)
-                       if ((spec[i] | mask[i]) != mask[i]) {
-                               rte_errno = EINVAL;
-                               return -rte_errno;
-                       }
-       }
-       if (item->spec && item->last) {
-               uint8_t spec[size];
-               uint8_t last[size];
-               const uint8_t *apply = mask;
-               unsigned int i;
-               int ret;
+       unsigned int i;
+       const uint8_t *spec = item->spec;
+       const uint8_t *last = item->last;
+       const uint8_t *m = item->mask ? item->mask : mask;
 
-               if (item->mask)
-                       apply = item->mask;
-               for (i = 0; i < size; ++i) {
-                       spec[i] = ((const uint8_t *)item->spec)[i] & apply[i];
-                       last[i] = ((const uint8_t *)item->last)[i] & apply[i];
-               }
-               ret = memcmp(spec, last, size);
-               if (ret != 0) {
-                       rte_errno = EINVAL;
-                       return -rte_errno;
-               }
+       if (!spec && (item->mask || last))
+               goto error;
+       if (!spec)
+               return 0;
+       /*
+        * Single-pass check to make sure that:
+        * - item->mask is supported, no bits are set outside mask.
+        * - Both masked item->spec and item->last are equal (no range
+        *   supported).
+        */
+       for (i = 0; i < size; i++) {
+               if (!m[i])
+                       continue;
+               if ((m[i] | mask[i]) != mask[i])
+                       goto error;
+               if (last && ((spec[i] & m[i]) != (last[i] & m[i])))
+                       goto error;
        }
        return 0;
+error:
+       rte_errno = ENOTSUP;
+       return -rte_errno;
 }
 
 /**
@@ -2061,7 +2034,7 @@ mlx5_flow_create_action_queue_drop(struct rte_eth_dev *dev,
                parser->queue[HASH_RXQ_ETH].ibv_attr;
        if (parser->count)
                flow->cs = parser->cs;
-       if (!priv->dev->data->dev_started)
+       if (!dev->data->dev_started)
                return 0;
        parser->queue[HASH_RXQ_ETH].ibv_attr = NULL;
        flow->frxq[HASH_RXQ_ETH].ibv_flow =
@@ -2113,7 +2086,6 @@ mlx5_flow_create_action_queue_rss(struct rte_eth_dev *dev,
                                  struct rte_flow *flow,
                                  struct rte_flow_error *error)
 {
-       struct priv *priv = dev->data->dev_private;
        unsigned int i;
 
        for (i = 0; i != hash_rxq_init_n; ++i) {
@@ -2122,7 +2094,7 @@ mlx5_flow_create_action_queue_rss(struct rte_eth_dev *dev,
                flow->frxq[i].ibv_attr = parser->queue[i].ibv_attr;
                parser->queue[i].ibv_attr = NULL;
                flow->frxq[i].hash_fields = parser->queue[i].hash_fields;
-               if (!priv->dev->data->dev_started)
+               if (!dev->data->dev_started)
                        continue;
                flow->frxq[i].hrxq =
                        mlx5_hrxq_get(dev,
@@ -2268,7 +2240,7 @@ mlx5_flow_create_action_queue(struct rte_eth_dev *dev,
                              struct rte_flow *flow,
                              struct rte_flow_error *error)
 {
-       struct priv *priv = dev->data->dev_private;
+       struct priv *priv __rte_unused = dev->data->dev_private;
        int ret;
        unsigned int i;
        unsigned int flows_n = 0;
@@ -2281,7 +2253,7 @@ mlx5_flow_create_action_queue(struct rte_eth_dev *dev,
                goto error;
        if (parser->count)
                flow->cs = parser->cs;
-       if (!priv->dev->data->dev_started)
+       if (!dev->data->dev_started)
                return 0;
        for (i = 0; i != hash_rxq_init_n; ++i) {
                if (!flow->frxq[i].hrxq)
@@ -3124,9 +3096,9 @@ mlx5_flow_isolate(struct rte_eth_dev *dev,
        }
        priv->isolated = !!enable;
        if (enable)
-               priv->dev->dev_ops = &mlx5_dev_ops_isolate;
+               dev->dev_ops = &mlx5_dev_ops_isolate;
        else
-               priv->dev->dev_ops = &mlx5_dev_ops;
+               dev->dev_ops = &mlx5_dev_ops;
        return 0;
 }
 
@@ -3409,13 +3381,13 @@ mlx5_fdir_filter_delete(struct rte_eth_dev *dev,
        if (parser.drop) {
                struct ibv_flow_spec_action_drop *drop;
 
-               drop = (void *)((uintptr_t)parser.queue[HASH_RXQ_ETH].ibv_attr +
-                               parser.queue[HASH_RXQ_ETH].offset);
+               drop = (void *)((uintptr_t)parser.queue[parser.layer].ibv_attr +
+                               parser.queue[parser.layer].offset);
                *drop = (struct ibv_flow_spec_action_drop){
                        .type = IBV_FLOW_SPEC_ACTION_DROP,
                        .size = sizeof(struct ibv_flow_spec_action_drop),
                };
-               parser.queue[HASH_RXQ_ETH].ibv_attr->num_of_specs++;
+               parser.queue[parser.layer].ibv_attr->num_of_specs++;
        }
        TAILQ_FOREACH(flow, &priv->flows, next) {
                struct ibv_flow_attr *attr;
@@ -3426,8 +3398,8 @@ mlx5_fdir_filter_delete(struct rte_eth_dev *dev,
                void *flow_spec;
                unsigned int specs_n;
 
-               attr = parser.queue[HASH_RXQ_ETH].ibv_attr;
-               flow_attr = flow->frxq[HASH_RXQ_ETH].ibv_attr;
+               attr = parser.queue[parser.layer].ibv_attr;
+               flow_attr = flow->frxq[parser.layer].ibv_attr;
                /* Compare first the attributes. */
                if (memcmp(attr, flow_attr, sizeof(struct ibv_flow_attr)))
                        continue;
@@ -3514,11 +3486,10 @@ mlx5_fdir_filter_flush(struct rte_eth_dev *dev)
 static void
 mlx5_fdir_info_get(struct rte_eth_dev *dev, struct rte_eth_fdir_info *fdir_info)
 {
-       struct priv *priv = dev->data->dev_private;
        struct rte_eth_fdir_masks *mask =
-               &priv->dev->data->dev_conf.fdir_conf.mask;
+               &dev->data->dev_conf.fdir_conf.mask;
 
-       fdir_info->mode = priv->dev->data->dev_conf.fdir_conf.mode;
+       fdir_info->mode = dev->data->dev_conf.fdir_conf.mode;
        fdir_info->guarant_spc = 0;
        rte_memcpy(&fdir_info->mask, mask, sizeof(fdir_info->mask));
        fdir_info->max_flexpayload = 0;
@@ -3546,9 +3517,8 @@ static int
 mlx5_fdir_ctrl_func(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
                    void *arg)
 {
-       struct priv *priv = dev->data->dev_private;
        enum rte_fdir_mode fdir_mode =
-               priv->dev->data->dev_conf.fdir_conf.mode;
+               dev->data->dev_conf.fdir_conf.mode;
 
        if (filter_op == RTE_ETH_FILTER_NOP)
                return 0;