From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8BAAC3A5A4 for ; Sun, 1 Sep 2019 10:41:24 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 6051D21897 for ; Sun, 1 Sep 2019 10:41:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6051D21897 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 820DB1C2EF; Sun, 1 Sep 2019 12:40:33 +0200 (CEST) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id EC1111C227 for ; Sun, 1 Sep 2019 12:40:19 +0200 (CEST) From: Moti Haimovsky To: viacheslavo@mellanox.com, rasland@mellanox.com Cc: dev@dpdk.org Date: Sun, 1 Sep 2019 13:40:15 +0300 Message-Id: <4006c30d82850846482c0218bfa26d346843619c.1567332903.git.motih@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 7/7] net/mlx5: supp modify VLAN ID on existing VLAN hdr X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit adds support for modifying the VID of the outermost VLAN header already present in the packet. Signed-off-by: Moti Haimovsky --- drivers/net/mlx5/mlx5_flow.h | 3 +- drivers/net/mlx5/mlx5_flow_dv.c | 90 +++++++++++++++++++++++++++++++++++------ drivers/net/mlx5/mlx5_prm.h | 1 + 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 15c9c04..95abbb8 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -171,7 +171,8 @@ MLX5_FLOW_ACTION_INC_TCP_SEQ | \ MLX5_FLOW_ACTION_DEC_TCP_SEQ | \ MLX5_FLOW_ACTION_INC_TCP_ACK | \ - MLX5_FLOW_ACTION_DEC_TCP_ACK) + MLX5_FLOW_ACTION_DEC_TCP_ACK | \ + MLX5_FLOW_ACTION_OF_SET_VLAN_VID) #define MLX5_FLOW_VLAN_ACTIONS (MLX5_FLOW_ACTION_OF_POP_VLAN | \ MLX5_FLOW_ACTION_OF_PUSH_VLAN) diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index ea51805..8463327 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -123,6 +123,12 @@ struct field_modify_info modify_eth[] = { {0, 0, 0}, }; +struct field_modify_info modify_vlan_out_first_vid[] = { + /* Size in bits !!! */ + {12, 0, MLX5_MODI_OUT_FIRST_VID}, + {0, 0, 0}, +}; + struct field_modify_info modify_ipv4[] = { {1, 8, MLX5_MODI_OUT_IPV4_TTL}, {4, 12, MLX5_MODI_OUT_SIPV4}, @@ -405,6 +411,46 @@ struct field_modify_info modify_tcp[] = { } /** + * Convert modify-header set VLAN VID action to DV specification. + * + * @param[in,out] resource + * Pointer to the modify-header resource. + * @param[in] action + * Pointer to action specification. + * @param[out] error + * Pointer to the error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_dv_convert_action_modify_vlan_vid + (struct mlx5_flow_dv_modify_hdr_resource *resource, + const struct rte_flow_action *action, + struct rte_flow_error *error) +{ + const struct rte_flow_action_of_set_vlan_vid *conf = + (const struct rte_flow_action_of_set_vlan_vid *)(action->conf); + int i = resource->actions_num; + struct mlx5_modification_cmd *actions = &resource->actions[i]; + struct field_modify_info *field = modify_vlan_out_first_vid; + + if (i >= MLX5_MODIFY_NUM) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, NULL, + "too many items to modify"); + actions[i].action_type = MLX5_MODIFICATION_TYPE_SET; + actions[i].field = field->id; + actions[i].length = field->size; + actions[i].offset = field->offset; + actions[i].data0 = rte_cpu_to_be_32(actions[i].data0); + actions[i].data1 = conf->vlan_vid; + actions[i].data1 = actions[i].data1 << 16; + resource->actions_num = ++i; + return 0; +} + +/** * Convert modify-header set TP action to DV specification. * * @param[in,out] resource @@ -1010,8 +1056,8 @@ struct field_modify_info modify_tcp[] = { /** * Validate the set VLAN VID. * - * @param[in] action_flags - * Holds the actions detected until now. + * @param[in] item_flags + * Holds the items detected in this rule. * @param[in] actions * Pointer to the list of actions remaining in the flow rule. * @param[in] attr @@ -1023,7 +1069,7 @@ struct field_modify_info modify_tcp[] = { * 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, +flow_dv_validate_action_set_vlan_vid(uint64_t item_flags, const struct rte_flow_action actions[], struct rte_flow_error *error) { @@ -1034,17 +1080,27 @@ struct field_modify_info modify_tcp[] = { return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, action, "VLAN VID value to too big"); + /* If a push VLAN action follows then it will handle this action */ if (mlx5_flow_find_action(actions, - RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN) == NULL) + RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)) + return 0; + + /* + * Action is on an existing VLAN header: + * Need to verify this is a single modify CID action. + * Rule mast include a match on outer VLAN. + */ + if (mlx5_flow_find_action(++action, + RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID)) 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, + "Multiple VLAN VID modifications are " + "not supported"); + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_VLAN)) + return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, action, - "set VLAN VID action must precede " - "the push VLAN action"); + "match on VLAN is required in order " + "to set VLAN VID"); return 0; } @@ -3474,7 +3530,7 @@ struct field_modify_info modify_tcp[] = { break; case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID: ret = flow_dv_validate_action_set_vlan_vid - (action_flags, actions, error); + (item_flags, actions, error); if (ret < 0) return ret; /* Count VID with push_vlan command. */ @@ -5196,6 +5252,8 @@ struct field_modify_info modify_tcp[] = { dev_flow->dv.actions[actions_n++] = dev_flow->dv.push_vlan_res->action; action_flags |= MLX5_FLOW_ACTION_OF_PUSH_VLAN; + /* Push VLAN command is also handling this VLAN_VID */ + action_flags &= ~MLX5_FLOW_ACTION_OF_SET_VLAN_VID; break; case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP: vlan_tci = @@ -5211,7 +5269,15 @@ struct field_modify_info modify_tcp[] = { vlan.tci |= ((const struct rte_flow_action_of_set_vlan_vid *) actions->conf)->vlan_vid; - /* Push VLAN command will use this value */ + if (mlx5_flow_find_action + (actions, + RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN)) + break; + /* If no VLAN push - this is a modify header action */ + if (flow_dv_convert_action_modify_vlan_vid + (&res, actions, error)) + return -rte_errno; + action_flags |= MLX5_FLOW_ACTION_OF_SET_VLAN_VID; break; case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP: case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP: diff --git a/drivers/net/mlx5/mlx5_prm.h b/drivers/net/mlx5/mlx5_prm.h index d62837e..e5afc1c 100644 --- a/drivers/net/mlx5/mlx5_prm.h +++ b/drivers/net/mlx5/mlx5_prm.h @@ -413,6 +413,7 @@ enum mlx5_modification_field { MLX5_MODI_OUT_DIPV6_31_0, MLX5_MODI_OUT_SIPV4, MLX5_MODI_OUT_DIPV4, + MLX5_MODI_OUT_FIRST_VID, MLX5_MODI_IN_SMAC_47_16 = 0x31, MLX5_MODI_IN_SMAC_15_0, MLX5_MODI_IN_ETHERTYPE, -- 1.8.3.1