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: 44563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1643404wrn; Tue, 17 Jan 2023 01:00:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXtY4UZeAh42BxGtG5ah5xH24m7x/2w5bOljDOW1EgxWzSCXDEo+bXgflpx8VIz4ZUfaZRw2 X-Received: by 2002:a05:6a20:958a:b0:b8:6edc:7eac with SMTP id iu10-20020a056a20958a00b000b86edc7eacmr2311376pzb.39.1673946015890; Tue, 17 Jan 2023 01:00:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673946015; cv=none; d=google.com; s=arc-20160816; b=yQLKWWCxyItZ8bs+xw2nqKZVob3w21OV4pP5YXt+hMbmXlwN0DENaUaiSmSSSS+8de Kmt7q/W+nNerXwB5mSQWvwyVJhW+azTxUrlOPU0PMH/68R1floiCzr9rQOyeY2+gxMLV V6rqMHRSmMgvGS2OEGLxQ67tAFW59/aH3K5k18BZ+bGC4UcXtdgbxGzoFDfYNSdXQLuK MVanpT2X2CBXtHXS0TyDGeB6uZHcscp0DNqyg98ZInPq0oOi4LM5ccfscldEyDhlQ4y3 d9SfZ5hX2Lqc+36wlP7JMfOtmzVG8lSIJlYlzG38+hChVhznJmBa6B3AUVPOtk8SfZti R8Pg== 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=y2r/Ad7ZrxV9pZhwzHT8SDIeV9b9Cqe374h129+Hn5I=; b=yGaKnKSZJvbLCPUrOlGTO9+yPu4O4F/lDRcuvIFRK0wnAOna338Ry/v8zOfYCfSM3H H2nLNOG0Fsov34F5yX2vaIIvXtwLWIJce/o3Kn5C7iIKgtc//WwsLc/G5QJf1AzFFISx q4VIsRmvhZ5LqFCw44Fw7E4nyIow2MSaG4vXT191uuPV0MIhfvSmrt93ELczn9ur82Pu VSXW27dLmz3t+LTPMP/5kFdL0kTqsPk0W4qnz6d31/cRK/1SqfgCduWFy5Rd2fiwcJld qivFx166eZOZm6sbZgpVAmAnfkAroLJornBqiljRY/qqPRLRIJ7VdKfzYbXACDbT58v8 fpDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=TMUOmg1r; 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 p28-20020a056a000a1c00b005768619bd8esi21829802pfh.177.2023.01.17.01.00.03; Tue, 17 Jan 2023 01:00:15 -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=TMUOmg1r; 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 S235791AbjAQI4M (ORCPT + 99 others); Tue, 17 Jan 2023 03:56:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236103AbjAQI4B (ORCPT ); Tue, 17 Jan 2023 03:56:01 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958213C10; Tue, 17 Jan 2023 00:55:59 -0800 (PST) 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-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?1755259617572399078?= X-GMAIL-MSGID: =?utf-8?q?1755259617572399078?= 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 */