From patchwork Mon Feb 13 09:24:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 13138008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CF06C636CC for ; Mon, 13 Feb 2023 09:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lnJ9Fq34yiTsbYtuYIi1vJfQlG9+5NmGt31Qz0O1p+s=; b=Nh8lzXKcxqVxYA gtPIGCSG/ELtOI+6cYHgqwj9dUNNsSluzTr+Zdn3AEAZpf06QArn/ceHr5GlSXxQblFKlPyRKe9zL V14vl+4/9cCEpDS9uopzoRjZ0PM478isJgoIT3xzina16sTTT2af0Mt4NpWHRLpE6A5UKJg5E0gIX OgrXBz7giHIMmKaEPhNt70vTO/OcobMgoYDbrYJIoYskc9akENVECB5NxS4B4wQJDi87mcMTHlF1e Np4VIklVuOihO85IONX+gJW+IGqM4o0QtOMC/TqiqEYGF8a7t3b+ry6F9zsz/wt8ygcIyueQ8CuZP wpIY5j/REE8PAHBgVU5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRV7L-00DqqD-Px; Mon, 13 Feb 2023 09:27:24 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRV4z-00DpmC-Uq for linux-arm-kernel@lists.infradead.org; Mon, 13 Feb 2023 09:25:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676280298; x=1707816298; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YV62iu9/O8cBsP3qS4XjVw4K1ZerXtPbvNDExU2QIF8=; b=OYk2pf8YvMCcFuz5HyKIUhGTt5ZdcVVFkZdlBmO08swe491APS11b4TL VsheyhbJKbZ1GU19Sgy54aUaG2/k7/4cMzE1IwqrHAYjkKJ6gqUjNVK7J AczE+9lar238EYEsL/S0krAxANNbA6C+IaTNHuQFlsKgHgnTtwAA24K/2 NWmpr+o28c/5+WXNwCH4EPBhmAvyz4Zf2cMKC2mXbAicWvhJEM3oM4ixG k9BH9w2zo9xssmeWJB5MefhygCaDMQVr3Km58bhB0DzYhm6vW7aR6FFpf pR5CEUlrN5eE9g7Fn+UP4yQYaZSusXsrqA8J+rZVrD4J5e6vT57aWO78V A==; X-IronPort-AV: E=Sophos;i="5.97,293,1669100400"; d="scan'208";a="196611584" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 13 Feb 2023 02:24:52 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 13 Feb 2023 02:24:50 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Mon, 13 Feb 2023 02:24:47 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , Randy Dunlap , "Casper Andersson" , Russell King , Wan Jiabing , "Nathan Huckleberry" , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Dan Carpenter , Michael Walle Subject: [PATCH net-next 04/10] net: microchip: sparx5: Use chain ids without offsets when enabling rules Date: Mon, 13 Feb 2023 10:24:20 +0100 Message-ID: <20230213092426.1331379-5-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213092426.1331379-1-steen.hegelund@microchip.com> References: <20230213092426.1331379-1-steen.hegelund@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230213_012458_109038_5CE36C7C X-CRM114-Status: GOOD ( 13.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This improves the check performed on linked rules when enabling or disabling them. The chain id used must be the chain id without the offset used for linking the rules. Signed-off-by: Steen Hegelund --- .../net/ethernet/microchip/vcap/vcap_api.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 68e04d47f6fd..9ca0cb855c3c 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1568,6 +1568,18 @@ static int vcap_write_counter(struct vcap_rule_internal *ri, return 0; } +/* Return the chain id rounded down to nearest lookup */ +static int vcap_round_down_chain(int cid) +{ + return cid - (cid % VCAP_CID_LOOKUP_SIZE); +} + +/* Return the chain id rounded up to nearest lookup */ +static int vcap_round_up_chain(int cid) +{ + return vcap_round_down_chain(cid + VCAP_CID_LOOKUP_SIZE); +} + /* Convert a chain id to a VCAP lookup index */ int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid) { @@ -1650,9 +1662,7 @@ bool vcap_is_next_lookup(struct vcap_control *vctrl, int src_cid, int dst_cid) return false; /* The offset must be at least one lookup, round up */ - next_cid = src_cid + VCAP_CID_LOOKUP_SIZE; - next_cid /= VCAP_CID_LOOKUP_SIZE; - next_cid *= VCAP_CID_LOOKUP_SIZE; + next_cid = vcap_round_up_chain(src_cid); if (dst_cid < next_cid) return false; @@ -2177,12 +2187,13 @@ static int vcap_get_next_chain(struct vcap_control *vctrl, static bool vcap_path_exist(struct vcap_control *vctrl, struct net_device *ndev, int dst_cid) { + int cid = vcap_round_down_chain(dst_cid); struct vcap_enabled_port *eport = NULL; struct vcap_enabled_port *elem; struct vcap_admin *admin; int tmp; - if (dst_cid == 0) /* Chain zero is always available */ + if (cid == 0) /* Chain zero is always available */ return true; /* Find first entry that starts from chain 0*/ @@ -2201,7 +2212,7 @@ static bool vcap_path_exist(struct vcap_control *vctrl, struct net_device *ndev, return false; tmp = eport->dst_cid; - while (tmp != dst_cid && tmp != 0) + while (tmp != cid && tmp != 0) tmp = vcap_get_next_chain(vctrl, ndev, tmp); return !!tmp;