net/mlx5: support modify VLAN ID on new VLAN header
[dpdk.git] / drivers / net / mlx5 / mlx5_flow_dv.c
index 2780735..4b68aa6 100644 (file)
@@ -973,6 +973,88 @@ flow_dv_validate_action_push_vlan(uint64_t action_flags,
        return 0;
 }
 
+/**
+ * Validate the set VLAN PCP.
+ *
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
+ * @param[in] actions
+ *   Pointer to the list of actions remaining in the flow rule.
+ * @param[in] attr
+ *   Pointer to flow attributes
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_validate_action_set_vlan_pcp(uint64_t action_flags,
+                                    const struct rte_flow_action actions[],
+                                    struct rte_flow_error *error)
+{
+       const struct rte_flow_action *action = actions;
+       const struct rte_flow_action_of_set_vlan_pcp *conf = action->conf;
+
+       if (conf->vlan_pcp > 7)
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "VLAN PCP value is too big");
+       if (mlx5_flow_find_action(actions,
+                                 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN) == NULL)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN PCP can only be used "
+                                         "with push VLAN action");
+       if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN PCP action must precede "
+                                         "the push VLAN action");
+       return 0;
+}
+
+/**
+ * Validate the set VLAN VID.
+ *
+ * @param[in] action_flags
+ *   Holds the actions detected until now.
+ * @param[in] actions
+ *   Pointer to the list of actions remaining in the flow rule.
+ * @param[in] attr
+ *   Pointer to flow attributes
+ * @param[out] error
+ *   Pointer to error structure.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+static int
+flow_dv_validate_action_set_vlan_vid(uint64_t action_flags,
+                                    const struct rte_flow_action actions[],
+                                    struct rte_flow_error *error)
+{
+       const struct rte_flow_action *action = actions;
+       const struct rte_flow_action_of_set_vlan_vid *conf = action->conf;
+
+       if (conf->vlan_vid > RTE_BE16(0xFFE))
+               return rte_flow_error_set(error, EINVAL,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "VLAN VID value is too big");
+       if (mlx5_flow_find_action(actions,
+                                 RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN) == NULL)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN VID can only be used "
+                                         "with push VLAN action");
+       if (action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)
+               return rte_flow_error_set(error, ENOTSUP,
+                                         RTE_FLOW_ERROR_TYPE_ACTION, action,
+                                         "set VLAN VID action must precede "
+                                         "the push VLAN action");
+       return 0;
+}
+
 /**
  * Validate count action.
  *
@@ -3396,6 +3478,20 @@ flow_dv_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
                        action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
                        ++actions_n;
                        break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
+                       ret = flow_dv_validate_action_set_vlan_pcp
+                                               (action_flags, actions, error);
+                       if (ret < 0)
+                               return ret;
+                       /* Count PCP with push_vlan command. */
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+                       ret = flow_dv_validate_action_set_vlan_vid
+                                               (action_flags, actions, error);
+                       if (ret < 0)
+                               return ret;
+                       /* Count VID with push_vlan command. */
+                       break;
                case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
                case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
                        ret = flow_dv_validate_action_l2_encap(action_flags,
@@ -4989,6 +5085,7 @@ flow_dv_translate(struct rte_eth_dev *dev,
        uint8_t next_protocol = 0xff;
        struct rte_vlan_hdr vlan = { 0 };
        bool vlan_inherited = false;
+       uint16_t vlan_tci;
 
        flow->group = attr->group;
        if (attr->transfer)
@@ -5118,6 +5215,30 @@ cnt_err:
                                           dev_flow->dv.push_vlan_res->action;
                        action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN;
                        break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
+                       if (!vlan_inherited) {
+                               flow_dev_get_vlan_info_from_items(items, &vlan);
+                               vlan_inherited = true;
+                       }
+                       vlan_tci =
+                           ((const struct rte_flow_action_of_set_vlan_pcp *)
+                                                      actions->conf)->vlan_pcp;
+                       vlan_tci = vlan_tci << MLX5DV_FLOW_VLAN_PCP_SHIFT;
+                       vlan.vlan_tci &= ~MLX5DV_FLOW_VLAN_PCP_MASK;
+                       vlan.vlan_tci |= vlan_tci;
+                       /* Push VLAN command will use this value */
+                       break;
+               case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
+                       if (!vlan_inherited) {
+                               flow_dev_get_vlan_info_from_items(items, &vlan);
+                               vlan_inherited = true;
+                       }
+                       vlan.vlan_tci &= ~MLX5DV_FLOW_VLAN_VID_MASK;
+                       vlan.vlan_tci |= rte_be_to_cpu_16
+                           (((const struct rte_flow_action_of_set_vlan_vid *)
+                                                    actions->conf)->vlan_vid);
+                       /* Push VLAN command will use this value */
+                       break;
                case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
                case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
                        if (flow_dv_create_action_l2_encap(dev, actions,