From patchwork Tue Jan 17 08:55:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 13104334 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 00E69C63797 for ; Tue, 17 Jan 2023 08:57:46 +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=F+Ie7QouihUmomg2gN0hbtgFM4IAELUpV1rzFtKb1mE=; b=k+wX80crLRediT eTCgAu59nUogsQ5LpM+qyHyURfOxH6dSQEpNuk4+sjZesZ7skjwlGb4G5jOSIlBAaqmGn6jtPhNQM sLqTOmN0ddXY2otnXpbxdKrYmingno8t1yAPQVH73J3Xei51YrUZt3VPQXv+1XYE7jcH+sxJmMEwa rhEfmzL63e41F7H3PSS1hnoZX8paw9v10+pHNHSnTqoIfbXqiAOOo6/8L0DP4IKswUACII4LGSe1U Ez3a2EKcSzlY0ntrRwqdrseUUSPyjzCLSyWBlsGiCtJn0X8D2CXy3roxiKOxvFUiw19Y2kuZdFBUd ZNDNCF5ekY4XThW7nHmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHhlt-00DQUV-KY; Tue, 17 Jan 2023 08:56:45 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHhl9-00DQB6-Jf for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2023 08:56:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1673945759; x=1705481759; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=snZiNtmGLv9PnppTNGgB75z+Rsn5YVgjz5NEqqogGM4=; b=TMUOmg1rwgCBOzYQULr5aJB7tseJwtL5+yQrfYUfV6vDh4p4GJIVRugG w0M8SsHpCp/x4PjsFDZL1y1sXcpSEeMOcwlioLYkAZE2+C7X0m+C1xz97 uURIubqIqECCgLS0cZP6STmEm9xAout1ZogMTi5VqeHdqhwviYzfVqXZR WqMxuHQUcXds8r1ld61Y1PuyL4ilhH/uvvMRNHawToOC9caGsyq2b5yCK PjqsFGQ8IVEm1n8I/FY6tMfF4Mp+f/nOJbg/N4FZdF7yhYFcFhehLHVQu SIe57LMhz0vGV6q1Eoe04SFDE3c1uaLcHyp9zz9gzTy/NkL3IjAnovBWJ w==; X-IronPort-AV: E=Sophos;i="5.97,222,1669100400"; d="scan'208";a="208096687" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Jan 2023 01:55:59 -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; Tue, 17 Jan 2023 01:55:58 -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; Tue, 17 Jan 2023 01:55:55 -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 2/5] net: microchip: sparx5: Add support to check for existing VCAP rule id Date: Tue, 17 Jan 2023 09:55:41 +0100 Message-ID: <20230117085544.591523-3-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117085544.591523-1-steen.hegelund@microchip.com> References: <20230117085544.591523-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-20230117_005559_730783_08EB399B X-CRM114-Status: GOOD ( 13.95 ) 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 Add a new function that just checks if the VCAP rule id is already used by an existing rule. Signed-off-by: Steen Hegelund --- drivers/net/ethernet/microchip/vcap/vcap_api.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 4e038f96a131..f1dc4fd6bb96 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -920,6 +920,20 @@ int vcap_set_rule_set_actionset(struct vcap_rule *rule, } EXPORT_SYMBOL_GPL(vcap_set_rule_set_actionset); +/* Check if a rule with this id exists */ +static bool vcap_rule_exists(struct vcap_control *vctrl, u32 id) +{ + struct vcap_rule_internal *ri; + struct vcap_admin *admin; + + /* Look for the rule id in all vcaps */ + list_for_each_entry(admin, &vctrl->list, list) + list_for_each_entry(ri, &admin->rules, list) + if (ri->data.id == id) + return true; + return false; +} + /* Find a rule with a provided rule id */ static struct vcap_rule_internal *vcap_lookup_rule(struct vcap_control *vctrl, u32 id) @@ -1866,7 +1880,7 @@ static u32 vcap_set_rule_id(struct vcap_rule_internal *ri) return ri->data.id; for (u32 next_id = 1; next_id < ~0; ++next_id) { - if (!vcap_lookup_rule(ri->vctrl, next_id)) { + if (!vcap_rule_exists(ri->vctrl, next_id)) { ri->data.id = next_id; break; } @@ -2103,7 +2117,7 @@ struct vcap_rule *vcap_alloc_rule(struct vcap_control *vctrl, if (vctrl->vcaps[admin->vtype].rows == 0) return ERR_PTR(-EINVAL); /* Check if a rule with this id already exists */ - if (vcap_lookup_rule(vctrl, id)) + if (vcap_rule_exists(vctrl, id)) return ERR_PTR(-EEXIST); /* Check if there is room for the rule in the block(s) of the VCAP */ maxsize = vctrl->vcaps[admin->vtype].sw_count; /* worst case rule size */