From patchwork Thu Jun 18 08:36:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1311931 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=vDHy3Zoa; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49nb0c0Yyzz9sR4 for ; Thu, 18 Jun 2020 18:37:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728753AbgFRIhf (ORCPT ); Thu, 18 Jun 2020 04:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728731AbgFRIh3 (ORCPT ); Thu, 18 Jun 2020 04:37:29 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08644C06174E for ; Thu, 18 Jun 2020 01:37:29 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id g7so2370740qvx.11 for ; Thu, 18 Jun 2020 01:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=f0wpaSdm/kbjyMK/zd6VzknUE9Tyb8h/E5yy8Dyg5Mg=; b=vDHy3ZoaBh1Si0+AEDx6zwz9bVEzjJntX2qmEpVRTjOKGiddC2PPV7FBjd+r9gz8Ix 9xiqbFu82edq3ozXPpBNH9bp31AgXa0faBhxBTbMOhX3DkglXq5HDx0nG3JwWzM94W3l QwqJJPYEBFkJlqksAk2/vK2GipG6Ju4MN66OkECyIX+HElaron9fFez4CgD/DoweHXT1 lMPaMYY5UYVA9U66bL9CF7+i80uvPdyF4IaARJNcbqzxkXB9SSnaptshHMDtNDl5RTnV FJ6Ns/5z7lOlm2oJsxNVjGcZlOUgKlhrpBJasmxFUQZVH/qxicf02em0Yq09M1IgcHzo 4Nkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=f0wpaSdm/kbjyMK/zd6VzknUE9Tyb8h/E5yy8Dyg5Mg=; b=fEeKG6eiMhayLNkJZiRUDWXfkjsiTwOjYCEHHBv0CxuJqilb+1hkEaGs05wHRVxQEE fmgLNpjMt4Fiq51jhlKjVrAkMNHY5HW5xfBFgFJyJYj7AwIoebulOJEntpse5z7t3qiD 428jslZh9cWeLixiquOeyAyH73hCr1RaXuRosfLROSToLog+LPUYeyTM0AGukvx+aZpk LYAQcadMX8CWW03abfXN8vJ9QGSryQJLRSo2AmmzrcT+c5ZKj9m7RCKNA2cVHjZRCkeC 9sj+P1G5w4tq5E9JQ5hiTf31aMi0g376ZRzCi7Lz8gke9E52FOjNsyXbgJcc2fT3tVJk 4yuw== X-Gm-Message-State: AOAM530PxOgLiObxxz3q6Yt1q72+uN20jg6x0SE83r+S3mVQ8cg7A85Z WiPAVxkSjp1v8Zuv11kFU7I= X-Google-Smtp-Source: ABdhPJzwro4KaJhr2SQxklkw+zOjprc66kp/1HrVeK77+OXsRGNgwKJaINZ2h2PlzrM1tsiDS5U4IQ== X-Received: by 2002:a05:6214:12f4:: with SMTP id w20mr2606863qvv.119.1592469448261; Thu, 18 Jun 2020 01:37:28 -0700 (PDT) Received: from localhost.localdomain ([111.205.198.3]) by smtp.gmail.com with ESMTPSA id l69sm2131551qke.112.2020.06.18.01.37.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jun 2020 01:37:27 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: paulb@mellanox.com, saeedm@mellanox.com, gerlitz.or@gmail.com, roid@mellanox.com Cc: netdev@vger.kernel.org, Tonghao Zhang Subject: [PATCH net-next v3 1/3] net/mlx5e: Implicitly decap the tunnel packet when necessary Date: Thu, 18 Jun 2020 16:36:44 +0800 Message-Id: <20200618083646.59507-1-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang The commit 0a7fcb78cc21 ("net/mlx5e: Support inner header rewrite with goto action"), will decapsulate the tunnel packets if there is a goto action in chain 0. But in some case, we don't want do that, for example: $ tc filter add dev $VXLAN protocol ip parent ffff: prio 1 chain 0 \ flower enc_dst_ip 2.2.2.100 enc_dst_port 4789 \ action goto chain 2 $ tc filter add dev $VXLAN protocol ip parent ffff: prio 1 chain 2 \ flower dst_mac 00:11:22:33:44:55 enc_src_ip 2.2.2.200 \ enc_dst_ip 2.2.2.100 enc_dst_port 4789 enc_key_id 100 \ action tunnel_key unset action mirred egress redirect dev enp130s0f0_0 $ tc filter add dev $VXLAN protocol ip parent ffff: prio 1 chain 2 \ flower dst_mac 00:11:22:33:44:66 enc_src_ip 2.2.2.200 \ enc_dst_ip 2.2.2.100 enc_dst_port 4789 enc_key_id 200 \ action tunnel_key unset action mirred egress redirect dev enp130s0f0_1 If there are pedit and goto actions, do the decapsulate and id mapping action. Signed-off-by: Tonghao Zhang --- .../ethernet/mellanox/mlx5/core/en/mapping.c | 24 ++++ .../ethernet/mellanox/mlx5/core/en/mapping.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 109 ++++++++++++------ 3 files changed, 99 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.c b/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.c index ea321e528749..90306dde6b60 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.c @@ -74,6 +74,30 @@ int mapping_add(struct mapping_ctx *ctx, void *data, u32 *id) return err; } +int mapping_find_by_data(struct mapping_ctx *ctx, void *data, u32 *id) +{ + struct mapping_item *mi; + u32 hash_key; + + mutex_lock(&ctx->lock); + + hash_key = jhash(data, ctx->data_size, 0); + hash_for_each_possible(ctx->ht, mi, node, hash_key) { + if (!memcmp(data, mi->data, ctx->data_size)) + goto found; + } + + mutex_unlock(&ctx->lock); + return -ENOENT; + +found: + if (id) + *id = mi->id; + + mutex_unlock(&ctx->lock); + return 0; +} + static void mapping_remove_and_free(struct mapping_ctx *ctx, struct mapping_item *mi) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.h b/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.h index 285525cc5470..af501c9796b7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/mapping.h @@ -9,6 +9,7 @@ struct mapping_ctx; int mapping_add(struct mapping_ctx *ctx, void *data, u32 *id); int mapping_remove(struct mapping_ctx *ctx, u32 id); int mapping_find(struct mapping_ctx *ctx, u32 id, void *data); +int mapping_find_by_data(struct mapping_ctx *ctx, void *data, u32 *id); /* mapping uses an xarray to map data to ids in add(), and for find(). * For locking, it uses a internal xarray spin lock for add()/remove(), diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index 7fc84f58e28a..05f8df8b53af 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -1836,7 +1836,8 @@ static void mlx5e_tc_del_flow(struct mlx5e_priv *priv, } } -static int flow_has_tc_fwd_action(struct flow_cls_offload *f) +static int flow_has_tc_action(struct flow_cls_offload *f, + enum flow_action_id action) { struct flow_rule *rule = flow_cls_offload_flow_rule(f); struct flow_action *flow_action = &rule->action; @@ -1844,12 +1845,8 @@ static int flow_has_tc_fwd_action(struct flow_cls_offload *f) int i; flow_action_for_each(i, act, flow_action) { - switch (act->id) { - case FLOW_ACTION_GOTO: + if (act->id == action) return true; - default: - continue; - } } return false; @@ -1901,10 +1898,37 @@ enc_opts_is_dont_care_or_full_match(struct mlx5e_priv *priv, sizeof(*__dst));\ }) +static void mlx5e_make_tunnel_match_key(struct flow_cls_offload *f, + struct net_device *filter_dev, + struct tunnel_match_key *tunnel_key) +{ + struct flow_rule *rule = flow_cls_offload_flow_rule(f); + + memset(tunnel_key, 0, sizeof(*tunnel_key)); + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL, + &tunnel_key->enc_control); + if (tunnel_key->enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, + &tunnel_key->enc_ipv4); + else + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, + &tunnel_key->enc_ipv6); + + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IP, &tunnel_key->enc_ip); + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_PORTS, + &tunnel_key->enc_tp); + COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_KEYID, + &tunnel_key->enc_key_id); + + tunnel_key->filter_ifindex = filter_dev->ifindex; +} + static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow, struct flow_cls_offload *f, - struct net_device *filter_dev) + struct net_device *filter_dev, + bool sets_mapping, + bool needs_mapping) { struct flow_rule *rule = flow_cls_offload_flow_rule(f); struct netlink_ext_ack *extack = f->common.extack; @@ -1925,22 +1949,7 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); uplink_priv = &uplink_rpriv->uplink_priv; - memset(&tunnel_key, 0, sizeof(tunnel_key)); - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL, - &tunnel_key.enc_control); - if (tunnel_key.enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, - &tunnel_key.enc_ipv4); - else - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, - &tunnel_key.enc_ipv6); - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_IP, &tunnel_key.enc_ip); - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_PORTS, - &tunnel_key.enc_tp); - COPY_DISSECTOR(rule, FLOW_DISSECTOR_KEY_ENC_KEYID, - &tunnel_key.enc_key_id); - tunnel_key.filter_ifindex = filter_dev->ifindex; - + mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key); err = mapping_add(uplink_priv->tunnel_mapping, &tunnel_key, &tun_id); if (err) return err; @@ -1970,10 +1979,10 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, mask = enc_opts_id ? TUNNEL_ID_MASK : (TUNNEL_ID_MASK & ~ENC_OPTS_BITS_MASK); - if (attr->chain) { + if (needs_mapping) { mlx5e_tc_match_to_reg_match(&attr->parse_attr->spec, TUNNEL_TO_REG, value, mask); - } else { + } else if (sets_mapping) { mod_hdr_acts = &attr->parse_attr->mod_hdr_acts; err = mlx5e_tc_match_to_reg_set(priv->mdev, mod_hdr_acts, @@ -1996,6 +2005,25 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, return err; } +static int mlx5e_lookup_flow_tunnel_id(struct mlx5e_priv *priv, + struct mlx5e_tc_flow *flow, + struct flow_cls_offload *f, + struct net_device *filter_dev, + u32 *tun_id) +{ + struct mlx5_rep_uplink_priv *uplink_priv; + struct mlx5e_rep_priv *uplink_rpriv; + struct tunnel_match_key tunnel_key; + struct mlx5_eswitch *esw; + + esw = priv->mdev->priv.eswitch; + uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); + uplink_priv = &uplink_rpriv->uplink_priv; + + mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key); + return mapping_find_by_data(uplink_priv->tunnel_mapping, &tunnel_key, tun_id); +} + static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow) { u32 enc_opts_id = flow->tunnel_id & ENC_OPTS_BITS_MASK; @@ -2057,13 +2085,19 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv, struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct netlink_ext_ack *extack = f->common.extack; bool needs_mapping, sets_mapping; + bool pedit_action; int err; if (!mlx5e_is_eswitch_flow(flow)) return -EOPNOTSUPP; - needs_mapping = !!flow->esw_attr->chain; - sets_mapping = !flow->esw_attr->chain && flow_has_tc_fwd_action(f); + pedit_action = flow_has_tc_action(f, FLOW_ACTION_MANGLE) || + flow_has_tc_action(f, FLOW_ACTION_ADD); + sets_mapping = pedit_action && + flow_has_tc_action(f, FLOW_ACTION_GOTO); + needs_mapping = !!flow->esw_attr->chain && + !mlx5e_lookup_flow_tunnel_id(priv, flow, f, + filter_dev, NULL); *match_inner = !needs_mapping; if ((needs_mapping || sets_mapping) && @@ -2075,7 +2109,7 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv, return -EOPNOTSUPP; } - if (!flow->esw_attr->chain) { + if (*match_inner) { err = mlx5e_tc_tun_parse(filter_dev, priv, spec, f, match_level); if (err) { @@ -2085,18 +2119,20 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv, "Failed to parse tunnel attributes"); return err; } - - /* With mpls over udp we decapsulate using packet reformat - * object - */ - if (!netif_is_bareudp(filter_dev)) - flow->esw_attr->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; } + /* With mpls over udp we decapsulate using packet reformat + * object + */ + if (!netif_is_bareudp(filter_dev) && + sets_mapping && !needs_mapping) + flow->esw_attr->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; + if (!needs_mapping && !sets_mapping) return 0; - return mlx5e_get_flow_tunnel_id(priv, flow, f, filter_dev); + return mlx5e_get_flow_tunnel_id(priv, flow, f, filter_dev, + sets_mapping, needs_mapping); } static void *get_match_inner_headers_criteria(struct mlx5_flow_spec *spec) @@ -4309,6 +4345,9 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; } + if (decap) + attr->action |= MLX5_FLOW_CONTEXT_ACTION_DECAP; + if (!(attr->action & (MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_DROP))) { NL_SET_ERR_MSG_MOD(extack, From patchwork Thu Jun 18 08:36:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1311933 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fxIzFw62; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49nb0j0z96z9sR4 for ; Thu, 18 Jun 2020 18:37:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728767AbgFRIhj (ORCPT ); Thu, 18 Jun 2020 04:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbgFRIhc (ORCPT ); Thu, 18 Jun 2020 04:37:32 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14588C0613ED for ; Thu, 18 Jun 2020 01:37:32 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id l6so1139701qkc.6 for ; Thu, 18 Jun 2020 01:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cCEVW6ZBtJXEgpwnbXbhYEgSKBTezBvPxT8n/yB/Du8=; b=fxIzFw62Jmjjg80IrcNOZu1u7SlrT8CJPgC2M9atw+i7gxszXCczW0iRO7oRnNGP6D pxDMxNsTyCXUfV2njTFx8EKO0jl2UPpmnJkfBQ4p/M/gLjMj7ELhJW6tAy69STMTBxTO wat04r2AGogC/JRWChXcNXAs86mbj8QBlu0kWrF+yUpu8L3GqxZxNDinXa6jsuZF5Pqo TQ4fGQb2ts8Zxsouxo6/WVC7G9FhYG4BiulMNcra/mffEV0+uATYCD/gCwJ7Vqj+GKpu tYdxr2G1Fll9BakBdQsBlwRlqTqOAm1JMmWKjpdWH7FIek3Dlk70TJrjxCMvLnK8JzT2 I5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cCEVW6ZBtJXEgpwnbXbhYEgSKBTezBvPxT8n/yB/Du8=; b=rSYrpAwGr/Ef3tLNy1R7VobKDGzqT0n2Y+THO0NHy/nD6q/sAYA8V+jSfKxAVGXvaq aphVHX4YTgIR51rkYV6VO8xAA99Xoj1kN1CuVIq4+dxS4OvMaWRizWd8e+JG1dz559ID GnbLYpnOj1ik4PBoXuPX3bntn0MZmgPvvnjQAwMnVu6k5PPo3TcEMFFB725gZ9LWpRkF cHuj/w4kGZcFZ4bhck+WduiRF4UqV5TX/U1o3AfYVvpaWM80k/YBrepecc8K+QSgH4vS tLypuBw7D4Bx9bF2v6gzAO/JywIBN8tCss3k3rhk3l1uVIAaJNWuLTy1uWSSL+nsJtng +fqA== X-Gm-Message-State: AOAM533l5FwlQ6DsK+LulnnToYiEsmUZ2I2b2W2U0jFxiKW3zAYzFhTw OLQhh2MCwhX4rptWfiU4Sfo= X-Google-Smtp-Source: ABdhPJzOE9mKsmF7INoO9JY/xKi7YSpSn9yy+RVXEEWR8eDYlCTm2GFaxErS+ju0YHGs2+kyBoIWoA== X-Received: by 2002:a37:a30a:: with SMTP id m10mr2768626qke.8.1592469451369; Thu, 18 Jun 2020 01:37:31 -0700 (PDT) Received: from localhost.localdomain ([111.205.198.3]) by smtp.gmail.com with ESMTPSA id l69sm2131551qke.112.2020.06.18.01.37.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jun 2020 01:37:30 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: paulb@mellanox.com, saeedm@mellanox.com, gerlitz.or@gmail.com, roid@mellanox.com Cc: netdev@vger.kernel.org, Tonghao Zhang Subject: [PATCH net-next v3 2/3] net/mlx5e: Introduce mlx5e_rep_uplink_priv helper Date: Thu, 18 Jun 2020 16:36:45 +0800 Message-Id: <20200618083646.59507-2-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200618083646.59507-1-xiangxia.m.yue@gmail.com> References: <20200618083646.59507-1-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang Introduce the mlx5e_rep_uplink_priv helper to make the codes more readable. Signed-off-by: Tonghao Zhang --- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 9 ++------- .../ethernet/mellanox/mlx5/core/en/tc_ct.c | 4 +--- .../net/ethernet/mellanox/mlx5/core/en_rep.h | 9 +++++++++ .../net/ethernet/mellanox/mlx5/core/en_tc.c | 20 +++++-------------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c index 80713123de5c..e92403a470cf 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c @@ -507,7 +507,6 @@ static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb, struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct tunnel_match_enc_opts enc_opts = {}; struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; struct metadata_dst *tun_dst; struct tunnel_match_key key; u32 tun_id, enc_opts_id; @@ -520,9 +519,7 @@ static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb, if (!tun_id) return true; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; - + uplink_priv = mlx5e_rep_uplink_priv(esw); err = mapping_find(uplink_priv->tunnel_mapping, tun_id, &key); if (err) { WARN_ON_ONCE(true); @@ -588,7 +585,6 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, #if IS_ENABLED(CONFIG_NET_TC_SKB_EXT) u32 chain = 0, reg_c0, reg_c1, tunnel_id, tuple_id; struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; struct tc_skb_ext *tc_skb_ext; struct mlx5_eswitch *esw; struct mlx5e_priv *priv; @@ -625,8 +621,7 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, tuple_id = reg_c1 & TUPLE_ID_MAX; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); if (!mlx5e_tc_ct_restore_flow(uplink_priv, skb, tuple_id)) return false; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c index 430025550fad..71841e7cca88 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c @@ -111,10 +111,8 @@ mlx5_tc_ct_get_ct_priv(struct mlx5e_priv *priv) { struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); return uplink_priv->ct_priv; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h index 1d5669801484..adcd3db0638f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h @@ -108,6 +108,15 @@ struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep) return rep->rep_data[REP_ETH].priv; } +static inline struct mlx5_rep_uplink_priv * +mlx5e_rep_uplink_priv(struct mlx5_eswitch *esw) +{ + struct mlx5e_rep_priv *priv; + + priv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); + return &priv->uplink_priv; +} + struct mlx5e_neigh { struct net_device *dev; union { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c index 05f8df8b53af..b33e40455b51 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -1245,12 +1245,10 @@ static void unready_flow_del(struct mlx5e_tc_flow *flow) static void add_unready_flow(struct mlx5e_tc_flow *flow) { struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *rpriv; struct mlx5_eswitch *esw; esw = flow->priv->mdev->priv.eswitch; - rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); mutex_lock(&uplink_priv->unready_flows_lock); unready_flow_add(flow, &uplink_priv->unready_flows); @@ -1260,12 +1258,10 @@ static void add_unready_flow(struct mlx5e_tc_flow *flow) static void remove_unready_flow(struct mlx5e_tc_flow *flow) { struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *rpriv; struct mlx5_eswitch *esw; esw = flow->priv->mdev->priv.eswitch; - rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); mutex_lock(&uplink_priv->unready_flows_lock); unready_flow_del(flow); @@ -1937,7 +1933,6 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, struct flow_match_enc_opts enc_opts_match; struct tunnel_match_enc_opts tun_enc_opts; struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; struct tunnel_match_key tunnel_key; bool enc_opts_is_dont_care = true; u32 tun_id, enc_opts_id = 0; @@ -1946,8 +1941,7 @@ static int mlx5e_get_flow_tunnel_id(struct mlx5e_priv *priv, int err; esw = priv->mdev->priv.eswitch; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key); err = mapping_add(uplink_priv->tunnel_mapping, &tunnel_key, &tun_id); @@ -2012,13 +2006,11 @@ static int mlx5e_lookup_flow_tunnel_id(struct mlx5e_priv *priv, u32 *tun_id) { struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; struct tunnel_match_key tunnel_key; struct mlx5_eswitch *esw; esw = priv->mdev->priv.eswitch; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); mlx5e_make_tunnel_match_key(f, filter_dev, &tunnel_key); return mapping_find_by_data(uplink_priv->tunnel_mapping, &tunnel_key, tun_id); @@ -2029,12 +2021,10 @@ static void mlx5e_put_flow_tunnel_id(struct mlx5e_tc_flow *flow) u32 enc_opts_id = flow->tunnel_id & ENC_OPTS_BITS_MASK; u32 tun_id = flow->tunnel_id >> ENC_OPTS_BITS; struct mlx5_rep_uplink_priv *uplink_priv; - struct mlx5e_rep_priv *uplink_rpriv; struct mlx5_eswitch *esw; esw = flow->priv->mdev->priv.eswitch; - uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH); - uplink_priv = &uplink_rpriv->uplink_priv; + uplink_priv = mlx5e_rep_uplink_priv(esw); if (tun_id) mapping_remove(uplink_priv->tunnel_mapping, tun_id); From patchwork Thu Jun 18 08:36:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1311932 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=klkSF2NA; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49nb0g06H3z9sSd for ; Thu, 18 Jun 2020 18:37:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728760AbgFRIhh (ORCPT ); Thu, 18 Jun 2020 04:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728752AbgFRIhf (ORCPT ); Thu, 18 Jun 2020 04:37:35 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CDABC06174E for ; Thu, 18 Jun 2020 01:37:35 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id q14so3774947qtr.9 for ; Thu, 18 Jun 2020 01:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NZEZKpyWhPA6yGR63CK/vh5TKUAQ+5lvK6MXVLUbqQM=; b=klkSF2NAYXbomoQJ6nc88LIjnYTiknac9cU+85VTQB+wvsq2Cboak01mZfc8kfdRop xJU6aOexgldzUWTjfc34HsqkgmR9y0v6q4U3cmB5Ard9HOUdwH1mRET17HweLM1Ddths 6qB5cyMJpiCMcGHJzvmUE4kCZ7TztTD4/N6zJFpQJs2DT3MDImZ37u9VEMW3o6jSiEEQ n2BVpQrElQLGegrmt0pOwhhTFou2HJJgDLAvIRXd10pHjat6xfYrmzHgULzd9oIcQrBg 4ayKhH/bPGff8Mz+WWKNJSV0Yd4ppuVULL6Fu2ar5mhPMYM2QNV3Ugb1d62M3Nl5GhB3 ePKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NZEZKpyWhPA6yGR63CK/vh5TKUAQ+5lvK6MXVLUbqQM=; b=FsPZfdHs/uKrE3GqIX03JHr945T7kZFNcDb1Uh5kIePGHHHrr/N1zMEhen6DdfQOQf BcnFkhmGakslB5G5NsAphXv1FPsrEM0/AuQISodzojNmBS493Cyy0frvfRBJUmK8fj3d RL1webvdsOFSk1SLjiUiqZoATjXLq2PZR06PFuqSED+5P/VfgpKx4k8t79VhZRUJeJgq eDy6dpBwuziuWboqOmAOnOffPTH0pq4nfwP6mFICSko21GlG9dAXYYLoID+CnIYjIH1P mDqJN5M9siIYIbU5pNkXOwwkJK4lE1rcRCEq8vK2qIjdOSWcJD8H2AZkWermsrh2Pe2d 8DQg== X-Gm-Message-State: AOAM533ii6d+lZM4UqhDMDZHw6RD8W8Q38NUPbfq7mDZ/8GlxHorftnS DZ+9VFaxLc020al3uc/F9xTxFRAgJcEeJg== X-Google-Smtp-Source: ABdhPJypbOXt8l8F0fyJHo0K9qJMzI5ZgnBf1G63pJKz+EqUFf/0TAN9WanZndeFL9NaIiUcNoKzpQ== X-Received: by 2002:ac8:6a08:: with SMTP id t8mr3230749qtr.271.1592469454458; Thu, 18 Jun 2020 01:37:34 -0700 (PDT) Received: from localhost.localdomain ([111.205.198.3]) by smtp.gmail.com with ESMTPSA id l69sm2131551qke.112.2020.06.18.01.37.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jun 2020 01:37:33 -0700 (PDT) From: xiangxia.m.yue@gmail.com To: paulb@mellanox.com, saeedm@mellanox.com, gerlitz.or@gmail.com, roid@mellanox.com Cc: netdev@vger.kernel.org, Tonghao Zhang Subject: [PATCH net-next v3 3/3] net/mlx5e: Fix the code style Date: Thu, 18 Jun 2020 16:36:46 +0800 Message-Id: <20200618083646.59507-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200618083646.59507-1-xiangxia.m.yue@gmail.com> References: <20200618083646.59507-1-xiangxia.m.yue@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tonghao Zhang Signed-off-by: Tonghao Zhang Reviewed-by: Roi Dayan --- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index 006807e04eda..795dda1a5e8a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -533,7 +533,7 @@ static bool mlx5e_rep_has_offload_stats(const struct net_device *dev, int attr_i { switch (attr_id) { case IFLA_OFFLOAD_XSTATS_CPU_HIT: - return true; + return true; } return false;