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: 56119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2250659wrn; Mon, 13 Feb 2023 01:30:00 -0800 (PST) X-Google-Smtp-Source: AK7set8Y9PYX79k4DbZ3SoUXb/mrh7keo/SQvwZ5gW5k6LVhXWo92TXPVrTsxzy6At/GrCU9Zd1C X-Received: by 2002:a50:d518:0:b0:4ac:bbc7:aa8e with SMTP id u24-20020a50d518000000b004acbbc7aa8emr5826346edi.41.1676280600704; Mon, 13 Feb 2023 01:30:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676280600; cv=none; d=google.com; s=arc-20160816; b=kSTdxBfRyZN0GL+0iScTozaL2IJf2KoKfebvsIO22Ota60r0n3/zx8KKf5PeVWdt85 ba2m6ZQxvyHmFdiPe1jddjVCiWM+Tfux1X2clDa0Q5K70y63nA2lt5IYfbOdH+/hRTkq OU3Ku5gm0Cf9lg5/vBPqueE44TTYXoFiATQ1bI3tDZ1NwPEo/i7ZFY7WlUJq+9KhxyPf +tenXvzmNvNveEP37PfNbONBT98ERU0mfBmfcYk9UDY4GjzXY9S8eDNjK6r5urCkWEFP 9obxc/1wjimuRS4vNolD+iyjqz7eZPUTv1FQMxWud5QmEhwNcINYSZ+rmqNlsmFs8ke5 wCFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CnllOaRs3osWGWsVu49fDZLUAzJwuWR3ht/dMONwLCk=; b=kT11h03/Lr6JeDt2vL6GM/wwNutyA38z+bC5ifAnStVTJhfmV7lb7F3eBd1R7Ujv6x KGxDJieBb0DYJNItEblvYksG1eljuqskpOSkdAZHTlbqlpL9RW5RVmC/almQNeXMob3G DVyzhvxW9HiZldxI7wbqrqhYFGh6bxKDrtqFhTVAwIZJ/ZKxM2hmkEXwQslRGzPI0x6l R55Uo+o6grOYwncbJDtBVp4dJuXkFhEDOsLiT+lXAVi91asDtpFYmX7/5SdS49APA1G7 I31a4fnFpl7YGpbuFhNSBK6V+fU5IQdQhVWb6ODZZ78r+BjMpqBUSxhGJxRu8Wk9sqer qCyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=OYk2pf8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020aa7cad1000000b004ab15dd69fdsi13151528edt.494.2023.02.13.01.29.37; Mon, 13 Feb 2023 01:30:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=OYk2pf8Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjBMJZX (ORCPT + 99 others); Mon, 13 Feb 2023 04:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjBMJZA (ORCPT ); Mon, 13 Feb 2023 04:25:00 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C96A014EAF; Mon, 13 Feb 2023 01:24:57 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757707607516711014?= X-GMAIL-MSGID: =?utf-8?q?1757707607516711014?= 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;