Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp603237rwb; Tue, 29 Nov 2022 03:01:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5C/RIZT8JS+f6+AbvKQRS2j2nz8m2fnzZkoJfuy9a4yJS6QAH648cdH44njSpjQWysw6yH X-Received: by 2002:a05:6a00:3017:b0:56b:ac5c:f3dc with SMTP id ay23-20020a056a00301700b0056bac5cf3dcmr39233767pfb.77.1669719694414; Tue, 29 Nov 2022 03:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669719694; cv=none; d=google.com; s=arc-20160816; b=SlDwiglSFs54SkQJt5Jli1mDf9fuNCq+54MpgVBS8oOgagtWMRn/ukSx/VKqqNoaE4 IUJdJBE4rNSv8tMS7Vwtk/So97R4KjdRCXYm5eH3FyI2sjNqcq0FDkj4oz9r0MbnBQxh IVvzMuJhgPj+kiAKsST/bumFQO8Hf0OfNjdvlr7y4RC26HDJ/y4fg8RSxr/c58SRd2GH Wh+fwlHjzsB/hjcBRRJiY2/VlcBwtKJhZV4NBFJk0af1UgPGD5JlA30+pPzKW5tKocvA H8omEur2ldrItsOe+LvZId5tppqQeeRRp5CHKW0Z0y1y8MelFYnZZxy+urRg5Mrf99ai LqVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YqVVq7J9QyzzhL81tRKVTnIxJRVfZwqzgtJ6cXHgllk=; b=ULqK7UnoIONS7jQLmWZ4k7t8ToOtwOrqlHSpM9ZlMth50FI0MKnFc5dhxjgioGxd9J Ci0tfVRwoXoKdoLJeJVh7QbXiBOYG8zcR5JmdFg3MButaLJpob0IYydjicrB3j2t5EFn kQaDBYcxArmSgiuEQR3vPnt/G7LoyPktuDLuqE5INU5Q9RgUpvR4PryTxJsKib8jVLjJ 2HPmaEqEa11q4CqGXeaGKc03eDtiQW4g6S6JivW96Q7gcxAjuLZIvDtVw8CVDSf70O0s HoeshfHoI5j3PP44A6CxqtY+zUpo+6h8MkDtC44TAIowo8eTctCTRO2SJ9G0rnH4XBCl zclw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="BOe93m/J"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a170902ce8800b0018696ec99e9si16200097plg.492.2022.11.29.03.01.22; Tue, 29 Nov 2022 03:01:34 -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="BOe93m/J"; 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 S232196AbiK2K4D (ORCPT + 84 others); Tue, 29 Nov 2022 05:56:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbiK2K4A (ORCPT ); Tue, 29 Nov 2022 05:56:00 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4695F5F872; Tue, 29 Nov 2022 02:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669719357; x=1701255357; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=14JeKXWHSLqj+2WYk+/+WfhIsZZ1QfsK4ISNpY3uTsc=; b=BOe93m/Jgvz8FLkZ8URJ2uN8AhnakbVuAL+ueVD5nD7HeqIU+m3kpros mLYI4H4DBagzO3hHB015Pc4b9a2BsCwynSP2AP5B1Sff+N9YM0FGsGkHS W4vrm5eAmPU6/nC4f13TNja7PHA2iUiKQS/K4bAOj4SjN+C+FZGEZ7h+7 2RwA/+qK7Ez63EORWqXs2vDYAbRYofqF1rpTRtuNYKNFGcRWnWFcznaGI crFBCmEYLvhOaFqVixzcMRGLiBEh+UrFx3NsjZA0uGdFro97B6ELK6H+Y Ll6wYajSAnLNVQN1j58Uxh3kP6td5p5VGPLTxTBYq02bkp6tBNPw1e30Z Q==; X-IronPort-AV: E=Sophos;i="5.96,202,1665471600"; d="scan'208";a="190964478" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 29 Nov 2022 03:55:56 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) 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.12; Tue, 29 Nov 2022 03:55:55 -0700 Received: from localhost (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Tue, 29 Nov 2022 03:55:55 -0700 Date: Tue, 29 Nov 2022 12:00:58 +0100 From: Horatiu Vultur To: Alexander Lobakin CC: , , , , , , , , , , , Subject: Re: [PATCH net-next] net: microchip: vcap: Change how the rule id is generated Message-ID: <20221129110058.uv2zqjscwyvku46t@soft-dev3-1> References: <20221128142959.8325-1-horatiu.vultur@microchip.com> <20221128144042.2097491-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20221128144042.2097491-1-alexandr.lobakin@intel.com> 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 The 11/28/2022 15:40, Alexander Lobakin wrote: Hi Olek, > > From: Horatiu Vultur > Date: Mon, 28 Nov 2022 15:29:59 +0100 > > > Currently whenever a new rule id is generated, it picks up the next > > number bigger than previous id. So it would always be 1, 2, 3, etc. > > When the rule with id 1 will be deleted and a new rule will be added, > > it will have the id 4 and not id 1. > > In theory this can be a problem if at some point a rule will be added > > and removed ~0 times. Then no more rules can be added because there > > are no more ids. > > > > Change this such that when a new rule is added, search for an empty > > rule id starting with value of 1 as value 0 is reserved. > > > > Fixes: c9da1ac1c212 ("net: microchip: sparx5: Adding initial tc flower support for VCAP API") > > Signed-off-by: Horatiu Vultur > > --- > > drivers/net/ethernet/microchip/vcap/vcap_api.c | 7 +------ > > drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 - > > 2 files changed, 1 insertion(+), 7 deletions(-) > > > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > index b50d002b646dc..b65819f3a927f 100644 > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c > > @@ -974,17 +974,12 @@ static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri) > > /* Assign a unique rule id and autogenerate one if id == 0 */ > > static u32 vcap_set_rule_id(struct vcap_rule_internal *ri) > > { > > - u32 next_id; > > - > > if (ri->data.id != 0) > > return ri->data.id; > > > > - next_id = ri->vctrl->rule_id + 1; > > - > > - for (next_id = ri->vctrl->rule_id + 1; next_id < ~0; ++next_id) { > > + for (u32 next_id = 1; next_id < ~0; ++next_id) { > > if (!vcap_lookup_rule(ri->vctrl, next_id)) { > > Or you can simply use IDA/IDR/XArray which takes care of all this :) Thanks for the great suggestion. From what I can see IDR would be a great match for this. Then we can also change the function 'vcap_lookup_rule' to use IDR. On the other side, we will not continuously add/remove entries from the VCAP, so I was not sure if it is worth bringing the IDR(with the radix tree) for this. Anyway I am open for IDR suggestion. But lets wait for the VCAP maintainer to see what he thinks. > > > > ri->data.id = next_id; > > - ri->vctrl->rule_id = next_id; > > break; > > } > > } > > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h > > index ca4499838306f..689c7270f2a89 100644 > > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h > > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h > > @@ -268,7 +268,6 @@ struct vcap_operations { > > > > /* VCAP API Client control interface */ > > struct vcap_control { > > - u32 rule_id; /* last used rule id (unique across VCAP instances) */ > > struct vcap_operations *ops; /* client supplied operations */ > > const struct vcap_info *vcaps; /* client supplied vcap models */ > > const struct vcap_statistics *stats; /* client supplied vcap stats */ > > -- > > 2.38.0 > > Thanks, > Olek -- /Horatiu