From patchwork Wed Jun 27 14:30:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 10491819 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6536C60375 for ; Wed, 27 Jun 2018 14:32:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51D9C29384 for ; Wed, 27 Jun 2018 14:32:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5037D293AF; Wed, 27 Jun 2018 14:32:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF6E129421 for ; Wed, 27 Jun 2018 14:32:34 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41G53P0MYqzF1Nr for ; Thu, 28 Jun 2018 00:32:33 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="M2vO5ZQ6"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=resnulli.us (client-ip=2a00:1450:400c:c09::244; helo=mail-wm0-x244.google.com; envelope-from=jiri@resnulli.us; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="M2vO5ZQ6"; dkim-atps=neutral Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41G50v1MHZzF1DM for ; Thu, 28 Jun 2018 00:30:23 +1000 (AEST) Received: by mail-wm0-x244.google.com with SMTP id n17-v6so5225312wmh.2 for ; Wed, 27 Jun 2018 07:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=o9kcpYjVP4371mXj6ZQ2MVe9R1E6q9WvckaLOvnYfbo=; b=M2vO5ZQ6uwPNvNHulIX5VlC4AsCY88Pje8DQB0TQBIzBrqCx4sydJyya6upQEj2jLZ YiK3Z9EDQ0KIDbZGHUg1BxPEV1LKeDDsJtIPH5Q0iVV6cwdzxkoXzzAYMEQJCzL2J3Sv 9kFfEROYSp2z6MLSpEhh/pyzh047023EdndwknK1T/NGtXDzl/fAoORj4+x5whPS7P36 M/0JE7uZo8W8jitwAQVfihZj+l0a6/Vb+OXeAlAT1EMtnBETM0xBgpB/Blmh/f9qVWPd 20/eKi0vabq7vQ9/sMc+7QvsO9DCcG9zps/FDMqEBWg2fczVGGEiasFJQHXKJDAs9D6B VSpA== 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=o9kcpYjVP4371mXj6ZQ2MVe9R1E6q9WvckaLOvnYfbo=; b=S9YinbjHya+prmfmtXFWP2qyYV4/+UV1iKIV6qozsAYiT/7i2K7kefyGc5zaXhkhbm wR8knDnF4uISBz6wLGKIY0lofv9ux0x/eUZIAuqvxOWOBb3iei3s5JbOPVMXJV6KY7nA WvBhliJ3iQuluYmqoAasIVKXd8VlYla8LMwwrwle8H8l5KVTbeZMVcafyTgp/BZrvfqm UtGedoVgIgRmS6XyKnr45SuU+vJoEhn3FA3tiXht1JE2fNuMoWehLyvCZrm7XzCI2Wdv joPbqfhKEl6H8l8jTSie84axtfCTfLPPa0s8O0xX0iGbvbUOl+6jFo46JVXEUIHm3LAe ilQw== X-Gm-Message-State: APt69E0d+8zFA3hTcTBJKalqgwRr31ZTGbGGHerfLbVF8IKTidiyjLFG +NcnrfhBbN3QN7h28kvzZeiHGw== X-Google-Smtp-Source: AAOMgpfZB3tO3refWXmfH//cflSvKiN8JRXF1sIep+HmLOuj0b44XvlTc0QwcVwDBJ5I2uzMNXxp2g== X-Received: by 2002:a1c:2e90:: with SMTP id u138-v6mr4858153wmu.156.1530109819544; Wed, 27 Jun 2018 07:30:19 -0700 (PDT) Received: from localhost ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id g75-v6sm8925825wmd.38.2018.06.27.07.30.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Jun 2018 07:30:19 -0700 (PDT) From: Jiri Pirko To: linux-internal@mellanox.com Subject: [patch net-next/mlxsw internal v2 13/15] mlxsw: spectrum_acl: Add support for Spectrum-2 block encoding Date: Wed, 27 Jun 2018 16:30:03 +0200 Message-Id: <20180627143005.2016-14-jiri@resnulli.us> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180627143005.2016-1-jiri@resnulli.us> References: <20180627143005.2016-1-jiri@resnulli.us> X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ido Schimmel Encode each flexible key block in the general block scheme according its block index. Signed-off-by: Ido Schimmel Signed-off-by: Jiri Pirko --- v1->v2: - s/Spectrum2/Spectrum-2/ --- .../mellanox/mlxsw/spectrum_acl_flex_keys.c | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c index 21be0987a93a..aa8927cee376 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c @@ -242,7 +242,75 @@ static const struct mlxsw_afk_block mlxsw_sp2_afk_blocks[] = { MLXSW_AFK_BLOCK(0x92, mlxsw_sp_afk_element_info_l4_2), }; +#define MLXSW_SP2_AFK_BITS_PER_BLOCK 36 + +/* A block in Spectrum-2 is of the following form: + * + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | | | | | | | | | | | | | | | | | | | | | | | | | | | | |35|34|33|32| + * +-----------------------------------------------------------------------------------------------+ + * |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + */ +MLXSW_ITEM64(sp2_afk, block, value, 0x00, 0, MLXSW_SP2_AFK_BITS_PER_BLOCK); + +/* The key / mask block layout in Spectrum-2 is of the following form: + * + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * | | | | | | | | | | | | | | | | | block11_high | + * +-----------------------------------------------------------------------------------------------+ + * | block11_low | block10_high | + * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + * ... + */ + +struct mlxsw_sp2_afk_block_layout { + unsigned short offset; + struct mlxsw_item item; +}; + +#define MLXSW_SP2_AFK_BLOCK_LAYOUT(_block, _offset, _shift) \ + { \ + .offset = _offset, \ + { \ + .shift = _shift, \ + .size = {.bits = MLXSW_SP2_AFK_BITS_PER_BLOCK}, \ + .name = #_block, \ + } \ + } \ + +static const struct mlxsw_sp2_afk_block_layout mlxsw_sp2_afk_blocks_layout[] = { + MLXSW_SP2_AFK_BLOCK_LAYOUT(block0, 0x30, 0), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block1, 0x2C, 4), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block2, 0x28, 8), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block3, 0x24, 12), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block4, 0x20, 16), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block5, 0x1C, 20), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block6, 0x18, 24), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block7, 0x14, 28), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block8, 0x0C, 0), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block9, 0x08, 4), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block10, 0x04, 8), + MLXSW_SP2_AFK_BLOCK_LAYOUT(block11, 0x00, 12), +}; + +static void mlxsw_sp2_afk_encode_block(char *block, int block_index, + char *output) +{ + u64 block_value = mlxsw_sp2_afk_block_value_get(block); + const struct mlxsw_sp2_afk_block_layout *block_layout; + + if (WARN_ON(block_index < 0 || + block_index >= ARRAY_SIZE(mlxsw_sp2_afk_blocks_layout))) + return; + + block_layout = &mlxsw_sp2_afk_blocks_layout[block_index]; + __mlxsw_item_set64(output + block_layout->offset, + &block_layout->item, 0, block_value); +} + const struct mlxsw_afk_ops mlxsw_sp2_afk_ops = { .blocks = mlxsw_sp2_afk_blocks, .blocks_count = ARRAY_SIZE(mlxsw_sp2_afk_blocks), + .encode_block = mlxsw_sp2_afk_encode_block, };