From patchwork Wed May 19 12:08:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 443918 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 15304C433ED for ; Wed, 19 May 2021 12:09:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA0C76135B for ; Wed, 19 May 2021 12:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353368AbhESMLE (ORCPT ); Wed, 19 May 2021 08:11:04 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:38699 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353367AbhESMLA (ORCPT ); Wed, 19 May 2021 08:11:00 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 4BF7A5C018D; Wed, 19 May 2021 08:09:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 19 May 2021 08:09:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=C438wb/me4Ff/NzMflplpZyoDZ0T88h4/8CHnFvNWyI=; b=dCwhku1/ lCGt4da2wv8nYDzra0Z6kYO811JbiiK836q3PFH5ezwu1eXpfeorosrv1trV0MTw ICZCg33/bK8qAcWPp5ViHjFoP65OP9mi930ngXUsSJpGOwnzd2U1H9cZTOt+QbA+ Euif8gbGp5G7A5/u41alm0NXAFWWvUu5HVwXdw72EbiqybIum4NbcHffYKRvx97c 8hakp4JPAJ6hBlSghBfqiUnXtui/Yi2xkFp9IUnXQo+J3y6viU2gjUrw++yBHObm IcguydtPNin+mtxQoMhjBAbV2wEuT0/lBDaEiH4cw1pBqUU/HbZV7vXBXB5B/3LP qkr3XrqyJ8JgWw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdeiledggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecuggftrfgrthhtvghrnhepudetieevffffveelkeeljeffkefhke ehgfdtffethfelvdejgffghefgveejkefhnecukfhppeekgedrvddvledrudehfedrudek jeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehiug hoshgthhesihguohhstghhrdhorhhg X-ME-Proxy: Received: from shredder.mellanox.com (igld-84-229-153-187.inter.net.il [84.229.153.187]) by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 May 2021 08:09:38 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com, petrm@nvidia.com, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 5/7] mlxsw: spectrum_outer: Factor out helper for common outer fields Date: Wed, 19 May 2021 15:08:22 +0300 Message-Id: <20210519120824.302191-6-idosch@idosch.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210519120824.302191-1-idosch@idosch.org> References: <20210519120824.302191-1-idosch@idosch.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Outer IPv4 and IPv6 addresses are used by multiple multipath hash policies. Factor out helpers that set these fields to increase code sharing between different policies. Signed-off-by: Ido Schimmel Reviewed-by: Petr Machata --- .../ethernet/mellanox/mlxsw/spectrum_router.c | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 3f896c5e50c7..605515137636 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -9613,6 +9613,17 @@ struct mlxsw_sp_mp_hash_config { #define MLXSW_SP_MP_HASH_FIELD_RANGE_SET(_fields, _field, _nr) \ bitmap_set(_fields, MLXSW_REG_RECR2_##_field, _nr) +static void mlxsw_sp_mp4_hash_outer_addr(struct mlxsw_sp_mp_hash_config *config) +{ + unsigned long *headers = config->headers; + unsigned long *fields = config->fields; + + MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP); + MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP); + MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_SIP0, 4); + MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_DIP0, 4); +} + static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_mp_hash_config *config) { @@ -9622,17 +9633,11 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp, switch (net->ipv4.sysctl_fib_multipath_hash_policy) { case 0: - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP); - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_SIP0, 4); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_DIP0, 4); + mlxsw_sp_mp4_hash_outer_addr(config); break; case 1: - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_NOT_TCP_NOT_UDP); - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV4_EN_TCP_UDP); + mlxsw_sp_mp4_hash_outer_addr(config); MLXSW_SP_MP_HASH_HEADER_SET(headers, TCP_UDP_EN_IPV4); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_SIP0, 4); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV4_DIP0, 4); MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV4_PROTOCOL); MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_SPORT); MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_DPORT); @@ -9640,6 +9645,19 @@ static void mlxsw_sp_mp4_hash_init(struct mlxsw_sp *mlxsw_sp, } } +static void mlxsw_sp_mp6_hash_outer_addr(struct mlxsw_sp_mp_hash_config *config) +{ + unsigned long *headers = config->headers; + unsigned long *fields = config->fields; + + MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_NOT_TCP_NOT_UDP); + MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_TCP_UDP); + MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_SIP0_7); + MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_SIP8, 8); + MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_DIP0_7); + MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_DIP8, 8); +} + static void mlxsw_sp_mp6_hash_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_mp_hash_config *config) { @@ -9648,23 +9666,13 @@ static void mlxsw_sp_mp6_hash_init(struct mlxsw_sp *mlxsw_sp, switch (ip6_multipath_hash_policy(mlxsw_sp_net(mlxsw_sp))) { case 0: - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_NOT_TCP_NOT_UDP); - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_TCP_UDP); - MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_SIP0_7); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_SIP8, 8); - MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_DIP0_7); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_DIP8, 8); + mlxsw_sp_mp6_hash_outer_addr(config); MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_NEXT_HEADER); MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_FLOW_LABEL); break; case 1: - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_NOT_TCP_NOT_UDP); - MLXSW_SP_MP_HASH_HEADER_SET(headers, IPV6_EN_TCP_UDP); + mlxsw_sp_mp6_hash_outer_addr(config); MLXSW_SP_MP_HASH_HEADER_SET(headers, TCP_UDP_EN_IPV6); - MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_SIP0_7); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_SIP8, 8); - MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_DIP0_7); - MLXSW_SP_MP_HASH_FIELD_RANGE_SET(fields, IPV6_DIP8, 8); MLXSW_SP_MP_HASH_FIELD_SET(fields, IPV6_NEXT_HEADER); MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_SPORT); MLXSW_SP_MP_HASH_FIELD_SET(fields, TCP_UDP_DPORT);