From patchwork Tue Jul 17 15:36:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 10529861 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 050266020A for ; Tue, 17 Jul 2018 15:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5B812970D for ; Tue, 17 Jul 2018 15:41:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C32702968E; Tue, 17 Jul 2018 15:41:07 +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=BAD_ENC_HEADER,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 6EE4029668 for ; Tue, 17 Jul 2018 15:41:06 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41VPdD4WttzF3J8 for ; Wed, 18 Jul 2018 01:41:04 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="M31qGZQr"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=40.107.0.59; helo=eur02-am5-obe.outbound.protection.outlook.com; envelope-from=idosch@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="M31qGZQr"; dkim-atps=neutral Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00059.outbound.protection.outlook.com [40.107.0.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41VPYR150SzF3Hc for ; Wed, 18 Jul 2018 01:37:46 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dU8CcWG91NPYoCfPjEEmb0WzVW4ArNBjlfMFAb+Ke8E=; b=M31qGZQriPSovXVQJrqEx/eZtEqGzJVzRrAbhEiMUX77yu8TsAgE7cchRVU/oCN4yl/SzQRGwzZx+XZLr5VYS7p3rZGM0vzOZNp3osKko74REHuGuBefptK3kKFLnHu56f1P1ouM4bFK5qQtjyii1pm4tuOTF/S+KCyMeNEjiEM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=idosch@mellanox.com; Received: from splinter.mtl.com (193.47.165.251) by HE1PR0501MB2330.eurprd05.prod.outlook.com (2603:10a6:3:27::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.21; Tue, 17 Jul 2018 15:37:33 +0000 From: Ido Schimmel To: linux-internal@mellanox.com Subject: [PATCH RESEND net-next mlxsw 08/18] mlxsw: spectrum_acl: Add support for C-TCAM eRPs Date: Tue, 17 Jul 2018 18:36:47 +0300 Message-Id: <20180717153657.16324-9-idosch@mellanox.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180717153657.16324-1-idosch@mellanox.com> References: <20180717153657.16324-1-idosch@mellanox.com> MIME-Version: 1.0 X-Originating-IP: [193.47.165.251] X-ClientProxiedBy: AM0PR02CA0020.eurprd02.prod.outlook.com (2603:10a6:208:3e::33) To HE1PR0501MB2330.eurprd05.prod.outlook.com (2603:10a6:3:27::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8122d342-c93b-4e96-84dc-08d5ebfb378c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2330; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2330; 3:w+hSymsCe9108QwqIbI5tsvl7tAhA6T0TrjKDFy7gvQhEdI2cyv+pnsX/yF66hWKYMTeful46BPk8VO7/DkZfER78YsJERA6M+CQSbbeSXyHyGJosNiR78Z2NB3LmMWChAcm7Nwm9jODq5CUG690or+l+aQLBzDv95R/pBGW1qv3x4XOIq7QyMYTTE9vLO1pnfUpPg9AVaANtxR6ExY4LowZhr7rR6VtzNjcTCeXMzo31Hev30Qyk+EQMGnNbgiC; 25:F5xamwNiXYPHsdv9S1N9Pdd2KBZPNZLaWjZkZCJv83/VfOMdcsfiELAiYTBQVA1KozArMIhlMM4QeUb0HH08g8vKQFWVQyLAeM8/Ykp/a5pe2Z5bBx6g6vPkpfsN8nXn6JPNdruiPAfzJhFfHggRgrsQt1v5U671VsBp4d6cOalGJdIHKwFJmvzhU+SzWjB6nb4L6Ect1A7x+f2hL5QDd9l0ehIE1NN9fFp4KCl/Zvk1kxJoKDzAEQ28326+ldRid5Oehk5CY1FpbUoTsbXBebadEdJflpek6T4L/6o2wZoW5YQ+dCmJR/okyS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4MXWgsJz8yJhwdDoSP6Kg4eZOSYQ9rQBH3CKMPML4i6genyrA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:HE1PR0501MB2330; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2330; X-Forefront-PRVS: 073631BD3D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(1496009)(396003)(39860400002)(346002)(136003)(376002)(366004)(189003)(199004)(51416003)(2906002)(8676002)(476003)(8936002)(6506007)(956004)(81156014)(2616005)(6486002)(2351001)(26005)(386003)(81166006)(16526019)(107886003)(53416004)(486006)(105586002)(446003)(4326008)(11346002)(34206002)(106356001)(66066001)(53936002)(47776003)(76176011)(68736007)(478600001)(6512007)(316002)(50226002)(50466002)(52116002)(7736002)(2361001)(3846002)(14444005)(16586007)(305945005)(37006003)(97736004)(86362001)(6116002)(36756003)(217873002)(1076002)(48376002)(6636002)(5660300001)(6666003)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2330; H:splinter.mtl.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0501MB2330; 23:24y+nf3BDAEWUPGJjtFXqbYUHRhY0DNQz9ka4vU?= =?us-ascii?Q?/KHTmGI/qi6JBkOUeR8uHAWpdWrmPHW37TlvEq6AV++OgO40FZCeeibzrlHB?= =?us-ascii?Q?lRsJK4M2qSB5h2V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FLll3LbSHFxiuWAyWMzSeKHcPnc/QrL6krdjurTuRZaqEBqlbZ2IyQmD88oK5Hz9hV+jscPBeyD+kEY3+DNavV2VDSAyP4P/HkvjkzF1lZTgXgwHXkuEbZrGQZpAt7uZpXDzZtnCaLeqZqmjTY8kWOL4R20Klb+oGCFhBe/kxR2BkxYfk5iMgP4k/jxSKWzxZ1tujV7EQjsNHOgkLU2F/VoD+kyiVu/8+iPUQkoj9R3bbzjm8PCbMUY72WRtpsQrhTdzoW1vOmxYFifKks+1z8cjEsvFVXK9rpfQTr19wrwEb831IA==; 5:KRYCrTuOMq9O689oVQib1vpVkptq4a41pePhgLlLyjFgSfXZIoiw7vm7Ad4U0/xQKiD8IK/nM3PFQwLkDToXZQtB9a/8QJ7SmRkKHP0aJYaZP3zQvEJHqBUuukyW6Mbo6MPraNupqSG2i3MqzyopUPmLWS7nwVBHM4EWR/UgXB8=; 24:qRSioIy6Nb/1b/GXmWAjgnRF2pDouwLJG3vXM6nh8moKREOWdBxjXDQiaJP9IBgbnMvIi7viK6N+EIJObyeECvHJShwEzszE3TZw3/eBbqc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2330; 7:dnIEi3UtFmBSFSDnhZRkI1QNog3+T0hITzSBVOd1E+U7A7BUqFLrKp8AdHSNTVXnaoUqK1Xz6Mq5t34oz7NpfKh4Ic/BTsY5MBJwJ9wAlEjrq4+AlrINBQI5sqnUyGs4oDxjmHj+8WSCHYJ54d2Q0iH00JWXcoayl2MUstZdcG6pOny/0U04KCBrkHTH5OFQCsRnkTc8rrF4z/FuDJmCxoKj20CSHpAwFxi4qLLPex0mZDy/v0yoIjCkMCcbi35w X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2018 15:37:33.7817 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8122d342-c93b-4e96-84dc-08d5ebfb378c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2330 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP The number of eRPs that can be used by a single A-TCAM region is limited to 16. When more eRPs are needed, an ordinary circuit TCAM (C-TCAM) can be used to hold the extra eRPs. Unlike the A-TCAM, only a single (last) lookup is performed in the C-TCAM and not a lookup per-eRP. However, modeling the C-TCAM as extra eRPs will allow us to easily introduce support for pruning in a follow-up patch set and is also logically correct. The following diagram depicts the relation between both TCAMs: C-TCAM +-------------------+ +--------------------+ +-----------+ | | | | | | | eRP #1 (A-TCAM) +----> ... +----+ eRP #16 (A-TCAM) +----+ eRP #17 | | | | | | ... | +-------------------+ +--------------------+ | eRP #N | | | +-----------+ Lookup order is from left to right. Extend the eRP core APIs with a C-TCAM parameter which indicates whether the requested eRP is to be used with the C-TCAM or not. Since the C-TCAM is only meant to absorb rules that can't fit in the A-TCAM due to exceeded number of eRPs or key collision, an error is returned when a C-TCAM eRP needs to be created when the eRP state machine is in its initial state (i.e., 'no masks'). This should only happen in the face of very unlikely errors when trying to push rules into the A-TCAM. In order not to perform unnecessary lookups, the eRP core will only enable a C-TCAM lookup for a given region if it knows there are C-TCAM eRPs present. Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c | 202 +++++++++++++++++++-- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.h | 2 +- 2 files changed, 191 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c index 480c6463651b..509d755804cb 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c @@ -60,6 +60,7 @@ struct mlxsw_sp_acl_erp_core { struct mlxsw_sp_acl_erp_key { char mask[MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN]; + bool ctcam; }; struct mlxsw_sp_acl_erp { @@ -90,6 +91,7 @@ struct mlxsw_sp_acl_erp_table { unsigned long base_index; unsigned int num_atcam_erps; unsigned int num_max_atcam_erps; + unsigned int num_ctcam_erps; }; static const struct rhashtable_params mlxsw_sp_acl_erp_ht_params = { @@ -446,13 +448,14 @@ static void mlxsw_sp_acl_erp_table_erp_del(struct mlxsw_sp_acl_erp *erp) } static int -mlxsw_sp_acl_erp_table_enable(struct mlxsw_sp_acl_erp_table *erp_table) +mlxsw_sp_acl_erp_table_enable(struct mlxsw_sp_acl_erp_table *erp_table, + bool ctcam_le) { struct mlxsw_sp_acl_tcam_region *region = erp_table->aregion->region; struct mlxsw_sp *mlxsw_sp = erp_table->erp_core->mlxsw_sp; char pererp_pl[MLXSW_REG_PERERP_LEN]; - mlxsw_reg_pererp_pack(pererp_pl, region->id, false, true, 0, + mlxsw_reg_pererp_pack(pererp_pl, region->id, ctcam_le, true, 0, erp_table->base_index, 0); mlxsw_reg_pererp_erp_vector_pack(pererp_pl, erp_table->erp_index_bitmap, MLXSW_SP_ACL_ERP_MAX_PER_REGION); @@ -469,11 +472,12 @@ mlxsw_sp_acl_erp_table_disable(struct mlxsw_sp_acl_erp_table *erp_table) struct mlxsw_sp_acl_erp *master_rp; master_rp = mlxsw_sp_acl_erp_table_master_rp(erp_table); - if (!master_rp) - return; - + /* It is possible we do not have a master RP when we disable the + * table when there are no rules in the A-TCAM and the last C-TCAM + * rule is deleted + */ mlxsw_reg_pererp_pack(pererp_pl, region->id, false, false, 0, 0, - master_rp->id); + master_rp ? master_rp->id : 0); mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pererp), pererp_pl); } @@ -504,6 +508,7 @@ mlxsw_sp_acl_erp_table_expand(struct mlxsw_sp_acl_erp_table *erp_table) unsigned int num_erps, old_num_erps = erp_table->num_max_atcam_erps; struct mlxsw_sp_acl_erp_core *erp_core = erp_table->erp_core; unsigned long old_base_index = erp_table->base_index; + bool ctcam_le = erp_table->num_ctcam_erps > 0; int err; if (erp_table->num_atcam_erps < erp_table->num_max_atcam_erps) @@ -524,7 +529,7 @@ mlxsw_sp_acl_erp_table_expand(struct mlxsw_sp_acl_erp_table *erp_table) if (err) goto err_table_relocate; - err = mlxsw_sp_acl_erp_table_enable(erp_table); + err = mlxsw_sp_acl_erp_table_enable(erp_table, ctcam_le); if (err) goto err_table_enable; @@ -577,7 +582,7 @@ mlxsw_sp_acl_erp_region_table_trans(struct mlxsw_sp_acl_erp_table *erp_table) if (err) goto err_table_master_rp_add; - err = mlxsw_sp_acl_erp_table_enable(erp_table); + err = mlxsw_sp_acl_erp_table_enable(erp_table, false); if (err) goto err_table_enable; @@ -618,9 +623,10 @@ mlxsw_sp_acl_erp_region_erp_add(struct mlxsw_sp_acl_erp_table *erp_table, { struct mlxsw_sp_acl_tcam_region *region = erp_table->aregion->region; struct mlxsw_sp *mlxsw_sp = erp_table->erp_core->mlxsw_sp; + bool ctcam_le = erp_table->num_ctcam_erps > 0; char pererp_pl[MLXSW_REG_PERERP_LEN]; - mlxsw_reg_pererp_pack(pererp_pl, region->id, false, true, 0, + mlxsw_reg_pererp_pack(pererp_pl, region->id, ctcam_le, true, 0, erp_table->base_index, 0); mlxsw_reg_pererp_erp_vector_pack(pererp_pl, erp_table->erp_index_bitmap, MLXSW_SP_ACL_ERP_MAX_PER_REGION); @@ -634,9 +640,10 @@ static void mlxsw_sp_acl_erp_region_erp_del(struct mlxsw_sp_acl_erp *erp) struct mlxsw_sp_acl_erp_table *erp_table = erp->erp_table; struct mlxsw_sp_acl_tcam_region *region = erp_table->aregion->region; struct mlxsw_sp *mlxsw_sp = erp_table->erp_core->mlxsw_sp; + bool ctcam_le = erp_table->num_ctcam_erps > 0; char pererp_pl[MLXSW_REG_PERERP_LEN]; - mlxsw_reg_pererp_pack(pererp_pl, region->id, false, true, 0, + mlxsw_reg_pererp_pack(pererp_pl, region->id, ctcam_le, true, 0, erp_table->base_index, 0); mlxsw_reg_pererp_erp_vector_pack(pererp_pl, erp_table->erp_index_bitmap, MLXSW_SP_ACL_ERP_MAX_PER_REGION); @@ -645,6 +652,161 @@ static void mlxsw_sp_acl_erp_region_erp_del(struct mlxsw_sp_acl_erp *erp) mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pererp), pererp_pl); } +static int +mlxsw_sp_acl_erp_region_ctcam_enable(struct mlxsw_sp_acl_erp_table *erp_table) +{ + /* No need to re-enable lookup in the C-TCAM */ + if (erp_table->num_ctcam_erps > 1) + return 0; + + return mlxsw_sp_acl_erp_table_enable(erp_table, true); +} + +static void +mlxsw_sp_acl_erp_region_ctcam_disable(struct mlxsw_sp_acl_erp_table *erp_table) +{ + /* Only disable C-TCAM lookup when last C-TCAM eRP is deleted */ + if (erp_table->num_ctcam_erps > 1) + return; + + mlxsw_sp_acl_erp_table_enable(erp_table, false); +} + +static void +mlxsw_sp_acl_erp_ctcam_table_ops_set(struct mlxsw_sp_acl_erp_table *erp_table) +{ + switch (erp_table->num_atcam_erps) { + case 2: + /* Keep using the eRP table, but correctly set the + * operations pointer so that when an A-TCAM eRP is + * deleted we will transition to use the master mask + */ + erp_table->ops = &erp_two_masks_ops; + break; + case 1: + /* We only kept the eRP table because we had C-TCAM + * eRPs in use. Now that the last C-TCAM eRP is gone we + * can stop using the table and transition to use the + * master mask + */ + mlxsw_sp_acl_erp_region_master_mask_trans(erp_table); + erp_table->ops = &erp_single_mask_ops; + break; + case 0: + /* There are no more eRPs of any kind used by the region + * so free its eRP table and transition to initial state + */ + mlxsw_sp_acl_erp_table_disable(erp_table); + mlxsw_sp_acl_erp_table_free(erp_table->erp_core, + erp_table->num_max_atcam_erps, + erp_table->aregion->type, + erp_table->base_index); + erp_table->ops = &erp_no_mask_ops; + break; + default: + break; + } +} + +static struct mlxsw_sp_acl_erp * +__mlxsw_sp_acl_erp_ctcam_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, + struct mlxsw_sp_acl_erp_key *key) +{ + struct mlxsw_sp_acl_erp *erp; + int err; + + erp = kzalloc(sizeof(*erp), GFP_KERNEL); + if (!erp) + return ERR_PTR(-ENOMEM); + + memcpy(&erp->key, key, sizeof(*key)); + bitmap_from_arr32(erp->mask_bitmap, (void *) key->mask, + MLXSW_SP_ACL_TCAM_MASK_LEN); + refcount_set(&erp->refcnt, 1); + erp_table->num_ctcam_erps++; + erp->erp_table = erp_table; + + err = mlxsw_sp_acl_erp_master_mask_set(erp_table, erp); + if (err) + goto err_master_mask_set; + + err = rhashtable_insert_fast(&erp_table->erp_ht, &erp->ht_node, + mlxsw_sp_acl_erp_ht_params); + if (err) + goto err_rhashtable_insert; + + err = mlxsw_sp_acl_erp_region_ctcam_enable(erp_table); + if (err) + goto err_erp_region_ctcam_enable; + + /* When C-TCAM is used, the eRP table must be used */ + erp_table->ops = &erp_multiple_masks_ops; + + return erp; + +err_erp_region_ctcam_enable: + rhashtable_remove_fast(&erp_table->erp_ht, &erp->ht_node, + mlxsw_sp_acl_erp_ht_params); +err_rhashtable_insert: + mlxsw_sp_acl_erp_master_mask_clear(erp_table, erp); +err_master_mask_set: + erp_table->num_ctcam_erps--; + kfree(erp); + return ERR_PTR(err); +} + +static struct mlxsw_sp_acl_erp * +mlxsw_sp_acl_erp_ctcam_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, + struct mlxsw_sp_acl_erp_key *key) +{ + struct mlxsw_sp_acl_erp *erp; + int err; + + /* There is a special situation where we need to spill rules + * into the C-TCAM, yet the region is still using a master + * mask and thus not performing a lookup in the C-TCAM. This + * can happen when two rules that only differ in priority - and + * thus sharing the same key - are programmed. In this case + * we transition the region to use an eRP table + */ + err = mlxsw_sp_acl_erp_region_table_trans(erp_table); + if (err) + return ERR_PTR(err); + + erp = __mlxsw_sp_acl_erp_ctcam_mask_create(erp_table, key); + if (IS_ERR(erp)) { + err = PTR_ERR(erp); + goto err_erp_create; + } + + return erp; + +err_erp_create: + mlxsw_sp_acl_erp_region_master_mask_trans(erp_table); + return ERR_PTR(err); +} + +static void +mlxsw_sp_acl_erp_ctcam_mask_destroy(struct mlxsw_sp_acl_erp *erp) +{ + struct mlxsw_sp_acl_erp_table *erp_table = erp->erp_table; + + mlxsw_sp_acl_erp_region_ctcam_disable(erp_table); + rhashtable_remove_fast(&erp_table->erp_ht, &erp->ht_node, + mlxsw_sp_acl_erp_ht_params); + mlxsw_sp_acl_erp_master_mask_clear(erp_table, erp); + erp_table->num_ctcam_erps--; + kfree(erp); + + /* Once the last C-TCAM eRP was destroyed, the state we + * transition to depends on the number of A-TCAM eRPs currently + * in use + */ + if (erp_table->num_ctcam_erps > 0) + return; + mlxsw_sp_acl_erp_ctcam_table_ops_set(erp_table); +} + static struct mlxsw_sp_acl_erp * mlxsw_sp_acl_erp_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp_key *key) @@ -652,6 +814,9 @@ mlxsw_sp_acl_erp_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp *erp; int err; + if (key->ctcam) + return __mlxsw_sp_acl_erp_ctcam_mask_create(erp_table, key); + /* Expand the eRP table for the new eRP, if needed */ err = mlxsw_sp_acl_erp_table_expand(erp_table); if (err) @@ -690,12 +855,15 @@ static void mlxsw_sp_acl_erp_mask_destroy(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp *erp) { + if (erp->key.ctcam) + return mlxsw_sp_acl_erp_ctcam_mask_destroy(erp); + mlxsw_sp_acl_erp_region_erp_del(erp); mlxsw_sp_acl_erp_table_erp_del(erp); mlxsw_sp_acl_erp_index_put(erp_table, erp->index); mlxsw_sp_acl_erp_generic_destroy(erp); - if (erp_table->num_atcam_erps == 2) + if (erp_table->num_atcam_erps == 2 && erp_table->num_ctcam_erps == 0) erp_table->ops = &erp_two_masks_ops; } @@ -706,6 +874,9 @@ mlxsw_sp_acl_erp_second_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp *erp; int err; + if (key->ctcam) + return mlxsw_sp_acl_erp_ctcam_mask_create(erp_table, key); + /* Transition to use eRP table instead of master mask */ err = mlxsw_sp_acl_erp_region_table_trans(erp_table); if (err) @@ -748,6 +919,9 @@ static void mlxsw_sp_acl_erp_second_mask_destroy(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp *erp) { + if (erp->key.ctcam) + return mlxsw_sp_acl_erp_ctcam_mask_destroy(erp); + mlxsw_sp_acl_erp_region_erp_del(erp); mlxsw_sp_acl_erp_table_erp_del(erp); mlxsw_sp_acl_erp_index_put(erp_table, erp->index); @@ -764,6 +938,9 @@ mlxsw_sp_acl_erp_first_mask_create(struct mlxsw_sp_acl_erp_table *erp_table, { struct mlxsw_sp_acl_erp *erp; + if (key->ctcam) + return ERR_PTR(-EINVAL); + erp = mlxsw_sp_acl_erp_generic_create(erp_table, key); if (IS_ERR(erp)) return erp; @@ -783,7 +960,7 @@ mlxsw_sp_acl_erp_first_mask_destroy(struct mlxsw_sp_acl_erp_table *erp_table, struct mlxsw_sp_acl_erp * mlxsw_sp_acl_erp_get(struct mlxsw_sp_acl_atcam_region *aregion, - const char *mask) + const char *mask, bool ctcam) { struct mlxsw_sp_acl_erp_table *erp_table = aregion->erp_table; struct mlxsw_sp_acl_erp_key key; @@ -795,6 +972,7 @@ mlxsw_sp_acl_erp_get(struct mlxsw_sp_acl_atcam_region *aregion, ASSERT_RTNL(); memcpy(key.mask, mask, MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN); + key.ctcam = ctcam; erp = rhashtable_lookup_fast(&erp_table->erp_ht, &key, mlxsw_sp_acl_erp_ht_params); if (erp) { diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h index 5c9a479ece25..d6af9920a930 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h @@ -178,7 +178,7 @@ struct mlxsw_sp_acl_erp; u8 mlxsw_sp_acl_erp_id(const struct mlxsw_sp_acl_erp *erp); struct mlxsw_sp_acl_erp * mlxsw_sp_acl_erp_get(struct mlxsw_sp_acl_atcam_region *aregion, - const char *mask); + const char *mask, bool ctcam); void mlxsw_sp_acl_erp_put(struct mlxsw_sp_acl_atcam_region *aregion, struct mlxsw_sp_acl_erp *erp); int mlxsw_sp_acl_erp_region_init(struct mlxsw_sp_acl_atcam_region *aregion);