From patchwork Wed Nov 9 11:41:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 17501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp285326wru; Wed, 9 Nov 2022 03:43:41 -0800 (PST) X-Google-Smtp-Source: AMsMyM77AtU93AZRaFqsQPqkFTE63Q9MtJbUYmet6uaYThV7o7p0NtiUmJZ9xxxSSG/7KplPn6uV X-Received: by 2002:a17:90b:1948:b0:214:1ae7:a511 with SMTP id nk8-20020a17090b194800b002141ae7a511mr42926171pjb.89.1667994221526; Wed, 09 Nov 2022 03:43:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667994221; cv=none; d=google.com; s=arc-20160816; b=e9GFVQ89Momf/AYKfd8AYXOuMxQIycOBv48axreHbelQQXGP5BV0i0DfTVSfVAXs5J fvFENyCnqLGS3++LTP/8t3Ue7/uAHi/+bQcnQITflnxja38L3/e7qoBO+c638ncnx+SF ceVs2fUapQcwRFos0yYccBFRTwGDDw8D5snCeYcHnDWrsHPBAwdeutevSIt7DTGqmms/ 9jDzSotg2w+Fkm1eZXbTJ7Uun0w5WrZbDOkWoE/bJcRlTxhBW0ygs8Lucx5W2DQ7683C rFoK9HR9L6JaZXg92yB2frbbi+nJmeDyVP1jKoFq67zbXYviizHE8D+O/n1cwmRZsw4u pGfg== 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=qzCU9BSMqnRWwABc00zHbXdZWTPOA2OCiRmypr1XhkE=; b=T4bUm6K38CxShZ6lxfjTo+rqHi0nB+XzNWWvFq7UGetAF66NhH8g9nu2cw0pypHvWa dVmuFQOsC8r1LjMfQ7h8gd+wVYzkrTEGwUu0/fkxZKhI4L1yuupGoVb+AqQsx3MhhaNN eiEiMb25TWDAJ8qHjQu4RITp6YZlC6dG/YVcjPgZ+1RQLcV/8bQLn0fOFJouBvw+L5Pg s8Vq+dYydNKpd+93hOPBfJalbzDqNh7emciBPMneW+3uHdFdgU5BeTvO3EyDZ+Wqvqj6 NZU6Qf0aYyD8GNcAvp/7GOycOH/0CZLbHoFIEra1vgR+j5VIVgyss3YKpK+VreG4QKdt Xaew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=rKT7aeko; 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 q84-20020a632a57000000b0047090f0f5d9si4581983pgq.774.2022.11.09.03.43.28; Wed, 09 Nov 2022 03:43:41 -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=rKT7aeko; 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 S229945AbiKILlz (ORCPT + 99 others); Wed, 9 Nov 2022 06:41:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbiKILlj (ORCPT ); Wed, 9 Nov 2022 06:41:39 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8247D2E9F8; Wed, 9 Nov 2022 03:41:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667994095; x=1699530095; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zg1ZOB9VAKT8wYILwCnjHS5DdA5dyjtXwq8br0fWHdo=; b=rKT7aekojRocC4YtKUAryk08JT75RnMpgcIjVNipp9BHPNMR7s9TZlhx VUUpDRgwy1sivVintA2oROsRjnlEZG4U/S1SRuefLuv8C+qfl8DygyLPc axbuQVfEY1SDL+SIOQVV7mFCpJ+eP/7Ziy7zq3bjmX79drY+fnyjawWkX +ERyNs4viYcMiw6eShyMJU4Hm0uZNZTudzTtc/CLDVhP+blsNLHlQhg6b CwGZk12cWY/B7nWy+VpAs+bORQoUywjrlDadP6gytKajIXRZeuzWp2Ied J49dCGuYqcLmfP5bqG8q3gGbGbr/k6gilmYa9LsKe6NE6aJnGhJbIasyC w==; X-IronPort-AV: E=Sophos;i="5.96,150,1665471600"; d="scan'208";a="186099239" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 09 Nov 2022 04:41:34 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) 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; Wed, 9 Nov 2022 04:41:33 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 9 Nov 2022 04:41:29 -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" , , , , "Daniel Machon" , Horatiu Vultur , Lars Povlsen Subject: [PATCH net-next v6 3/8] net: microchip: sparx5: Find VCAP lookup from chain id Date: Wed, 9 Nov 2022 12:41:11 +0100 Message-ID: <20221109114116.3612477-4-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221109114116.3612477-1-steen.hegelund@microchip.com> References: <20221109114116.3612477-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, 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?1749018708868791534?= X-GMAIL-MSGID: =?utf-8?q?1749018708868791534?= Add a helper function that finds the lookup index in a VCAP instance from the chain id. Signed-off-by: Steen Hegelund --- drivers/net/ethernet/microchip/vcap/vcap_api.c | 17 +++++++++++++++++ .../ethernet/microchip/vcap/vcap_api_client.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index ace2582d8552..d5b62e43d83f 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -644,6 +644,23 @@ static int vcap_write_rule(struct vcap_rule_internal *ri) return 0; } +/* Convert a chain id to a VCAP lookup index */ +int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid) +{ + int lookup_first = admin->vinst * admin->lookups_per_instance; + int lookup_last = lookup_first + admin->lookups_per_instance; + int cid_next = admin->first_cid + VCAP_CID_LOOKUP_SIZE; + int cid = admin->first_cid; + int lookup; + + for (lookup = lookup_first; lookup < lookup_last; ++lookup, + cid += VCAP_CID_LOOKUP_SIZE, cid_next += VCAP_CID_LOOKUP_SIZE) + if (cur_cid >= cid && cur_cid < cid_next) + return lookup; + return 0; +} +EXPORT_SYMBOL_GPL(vcap_chain_id_to_lookup); + /* Lookup a vcap instance using chain id */ struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid) { diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h index 577395402a9a..7d9a227ef834 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h @@ -184,6 +184,8 @@ int vcap_rule_add_action_u32(struct vcap_rule *rule, enum vcap_action_field action, u32 value); /* VCAP lookup operations */ +/* Convert a chain id to a VCAP lookup index */ +int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid); /* Lookup a vcap instance using chain id */ struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid); /* Find information on a key field in a rule */