From patchwork Thu Jun 14 08:52:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 10463681 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 4B19B600D0 for ; Thu, 14 Jun 2018 08:53:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B6B8289B7 for ; Thu, 14 Jun 2018 08:53:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3086C289C2; Thu, 14 Jun 2018 08:53:39 +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 4D6E7289B7 for ; Thu, 14 Jun 2018 08:53:38 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 415y8J44HczDrqP for ; Thu, 14 Jun 2018 18:53:36 +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="avrioTdI"; 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::243; helo=mail-wm0-x243.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="avrioTdI"; dkim-atps=neutral Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) (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 415y7q6tvwzF0mR for ; Thu, 14 Jun 2018 18:53:11 +1000 (AEST) Received: by mail-wm0-x243.google.com with SMTP id o13-v6so9118364wmf.4 for ; Thu, 14 Jun 2018 01:53:11 -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=Sp2eLjh3c6d/OvI4dVlwo6bDoCXv/eeQ03pZxGg5Tuo=; b=avrioTdInfVE1cyJF/sqg6ju1ZEpFx3M9m3Xcg2z2LT7qwoDgZylLilxxLCONSxTrU U4EL9V7MctNMlwHB6b5WgcAv0L7MrlR+17geqB7TcE2/T3siaEemqzUOiDGvwKQcTqsU NQoYsc2vTodLVO7u1p1epHhiZT7iPoVqpjWESqeycG2OU+g7Tm0O3pEGsLyNorQkpAnp LNb+SWYZGX4DLRCJvGBgbt7jdlEIIHTJBE+ly/2PJvzQCo383TTucY8mWHRKA+37mgvg iqd9vljyymoAkhOUzmHPRD10XBvyCcy3H0x88rV/FfRDUInc9K0suqItkx32yRPvc/WZ Tekg== 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=Sp2eLjh3c6d/OvI4dVlwo6bDoCXv/eeQ03pZxGg5Tuo=; b=MhuYOnM6Mm5Yh63Xw6fqgq0pEexPyVgWb/4vjnb7XaJO74uMx9UAusnvWyipMgkUOs pyC67UEarO1AfRvWLEhSwpqcZOSp61ofu0Pq1pE5vU+0ZIwf1jjK1Puph8ij1bKfDYdO 2wNUywdc2Sc51WXJ3AC4bdBdEq2nEnhY3nbPbxyQBxTZTQUT8qUUxlEbCz5+TKrjspxR pDJTQfXOS9F74z/Pke/OHJ9Chvhmr7DcfFS10NA2MRVtJA2gicTyWnKhiKRQRRyw0nUL yiulcJAKY7FTTdfJSA4tuJkBF6ytHLkKpRlIpbJ/BA+ortCg+dpBcJCtY2C9NSfX6tnJ DKZg== X-Gm-Message-State: APt69E3vTZXcdBMeMSBn5uoTRJx7b4eoTlvcYs4hlNKcn/kxn4lDsXmk idMPFRp2Q17JW8zcdzmSYkqnpg== X-Google-Smtp-Source: ADUXVKJ1r0Dz/P4IkJjbN2OM5ONgjy3v9gSg6ZviyeHkZeEgs/w/jp93HQULksEemCFGf62SGYzNnA== X-Received: by 2002:a1c:d543:: with SMTP id m64-v6mr1023368wmg.12.1528966388847; Thu, 14 Jun 2018 01:53:08 -0700 (PDT) Received: from localhost ([83.167.225.161]) by smtp.gmail.com with ESMTPSA id p38-v6sm11650471wrc.11.2018.06.14.01.53.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 01:53:08 -0700 (PDT) From: Jiri Pirko To: linux-internal@mellanox.com Subject: [patch net-next/mlxsw internal 12/15] mlxsw: spectrum_acl: Prepare for Spectrum2 block encoding Date: Thu, 14 Jun 2018 10:52:38 +0200 Message-Id: <20180614085241.1873-13-jiri@resnulli.us> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180614085241.1873-1-jiri@resnulli.us> References: <20180614085241.1873-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 In Spectrum the key (and mask) block layout is very straight forward and every block is 16 bytes aligned. However, in Spectrum2 the blocks are not even byte aligned, which makes it difficult to encode them using current method. Instead, first encode each block and then encode the block in the general blocks layout. Signed-off-by: Ido Schimmel Signed-off-by: Jiri Pirko --- .../ethernet/mellanox/mlxsw/core_acl_flex_keys.c | 70 ++++++++++++++++++---- .../ethernet/mellanox/mlxsw/core_acl_flex_keys.h | 3 +- .../mellanox/mlxsw/spectrum_acl_flex_keys.c | 46 ++------------ 3 files changed, 66 insertions(+), 53 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c index bf645215f514..5f8485c7640e 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c @@ -416,24 +416,74 @@ void mlxsw_afk_values_add_buf(struct mlxsw_afk_element_values *values, } EXPORT_SYMBOL(mlxsw_afk_values_add_buf); +static void mlxsw_sp_afk_encode_u32(const struct mlxsw_item *storage_item, + const struct mlxsw_item *output_item, + char *storage, char *output) +{ + u32 value; + + value = __mlxsw_item_get32(storage, storage_item, 0); + __mlxsw_item_set32(output, output_item, 0, value); +} + +static void mlxsw_sp_afk_encode_buf(const struct mlxsw_item *storage_item, + const struct mlxsw_item *output_item, + char *storage, char *output) +{ + char *storage_data = __mlxsw_item_data(storage, storage_item, 0); + char *output_data = __mlxsw_item_data(output, output_item, 0); + size_t len = output_item->size.bytes; + + memcpy(output_data, storage_data, len); +} + +static void +mlxsw_sp_afk_encode_one(const struct mlxsw_afk_element_inst *elinst, + char *output, char *storage) +{ + const struct mlxsw_item *storage_item = &elinst->info->item; + const struct mlxsw_item *output_item = &elinst->item; + + if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_U32) + mlxsw_sp_afk_encode_u32(storage_item, output_item, + storage, output); + else if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_BUF) + mlxsw_sp_afk_encode_buf(storage_item, output_item, + storage, output); +} + +#define MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE 16 + void mlxsw_afk_encode(struct mlxsw_afk *mlxsw_afk, struct mlxsw_afk_key_info *key_info, struct mlxsw_afk_element_values *values, char *key, char *mask) { + char block_mask[MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE]; + char block_key[MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE]; const struct mlxsw_afk_element_inst *elinst; enum mlxsw_afk_element element; - int block_index; + int block_index, i; + + for (i = 0; i < key_info->blocks_count; i++) { + memset(block_key, 0, MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE); + memset(block_mask, 0, MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE); + + mlxsw_afk_element_usage_for_each(element, &values->elusage) { + elinst = mlxsw_afk_key_info_elinst_get(key_info, + element, + &block_index); + if (!elinst || block_index != i) + continue; + + mlxsw_sp_afk_encode_one(elinst, block_key, + values->storage.key); + mlxsw_sp_afk_encode_one(elinst, block_mask, + values->storage.mask); + } - mlxsw_afk_element_usage_for_each(element, &values->elusage) { - elinst = mlxsw_afk_key_info_elinst_get(key_info, element, - &block_index); - if (!elinst) - continue; - mlxsw_afk->ops->encode_one(elinst, block_index, - values->storage.key, key); - mlxsw_afk->ops->encode_one(elinst, block_index, - values->storage.mask, mask); + mlxsw_afk->ops->encode_block(block_key, i, key); + mlxsw_afk->ops->encode_block(block_mask, i, mask); } } EXPORT_SYMBOL(mlxsw_afk_encode); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h index 441636cd13d8..2ffde915349b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h @@ -219,8 +219,7 @@ struct mlxsw_afk; struct mlxsw_afk_ops { const struct mlxsw_afk_block *blocks; unsigned int blocks_count; - void (*encode_one)(const struct mlxsw_afk_element_inst *elinst, - int block_index, char *storage, char *output); + void (*encode_block)(char *block, int block_index, char *output); }; struct mlxsw_afk *mlxsw_afk_create(unsigned int max_blocks, 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 fe46338f0087..21be0987a93a 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.c @@ -127,50 +127,21 @@ static const struct mlxsw_afk_block mlxsw_sp1_afk_blocks[] = { MLXSW_AFK_BLOCK(0xB0, mlxsw_sp_afk_element_info_packet_type), }; -static void mlxsw_sp1_afk_encode_u32(const struct mlxsw_item *storage_item, - const struct mlxsw_item *output_item, - char *storage, char *output_indexed) -{ - u32 value; - - value = __mlxsw_item_get32(storage, storage_item, 0); - __mlxsw_item_set32(output_indexed, output_item, 0, value); -} - -static void mlxsw_sp1_afk_encode_buf(const struct mlxsw_item *storage_item, - const struct mlxsw_item *output_item, - char *storage, char *output_indexed) -{ - char *storage_data = __mlxsw_item_data(storage, storage_item, 0); - char *output_data = __mlxsw_item_data(output_indexed, output_item, 0); - size_t len = output_item->size.bytes; - - memcpy(output_data, storage_data, len); -} - #define MLXSW_SP1_AFK_KEY_BLOCK_SIZE 16 -static void -mlxsw_sp1_afk_encode_one(const struct mlxsw_afk_element_inst *elinst, - int block_index, char *storage, char *output) +static void mlxsw_sp1_afk_encode_block(char *block, int block_index, + char *output) { unsigned int offset = block_index * MLXSW_SP1_AFK_KEY_BLOCK_SIZE; char *output_indexed = output + offset; - const struct mlxsw_item *storage_item = &elinst->info->item; - const struct mlxsw_item *output_item = &elinst->item; - - if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_U32) - mlxsw_sp1_afk_encode_u32(storage_item, output_item, - storage, output_indexed); - else if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_BUF) - mlxsw_sp1_afk_encode_buf(storage_item, output_item, - storage, output_indexed); + + memcpy(output_indexed, block, MLXSW_SP1_AFK_KEY_BLOCK_SIZE); } const struct mlxsw_afk_ops mlxsw_sp1_afk_ops = { .blocks = mlxsw_sp1_afk_blocks, .blocks_count = ARRAY_SIZE(mlxsw_sp1_afk_blocks), - .encode_one = mlxsw_sp1_afk_encode_one, + .encode_block = mlxsw_sp1_afk_encode_block, }; static struct mlxsw_afk_element_inst mlxsw_sp_afk_element_info_mac_0[] = { @@ -271,14 +242,7 @@ static const struct mlxsw_afk_block mlxsw_sp2_afk_blocks[] = { MLXSW_AFK_BLOCK(0x92, mlxsw_sp_afk_element_info_l4_2), }; -static void -mlxsw_sp2_afk_encode_one(const struct mlxsw_afk_element_inst *elinst, - int block_index, char *storage, char *output) -{ -} - const struct mlxsw_afk_ops mlxsw_sp2_afk_ops = { .blocks = mlxsw_sp2_afk_blocks, .blocks_count = ARRAY_SIZE(mlxsw_sp2_afk_blocks), - .encode_one = mlxsw_sp2_afk_encode_one, };