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: 13037439 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 A84F3C433FE for ; Wed, 9 Nov 2022 11:43:07 +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=P5RbK4t8tGu6A7Zhtfgk1JKerpaEs/jPsSq6wMgppqk=; b=L+BHf+N7agvwuA bkWvrGydFjvZyM9KRy/VQTvVJZPTNY/MQ6TjlEIizvPU+64fc8oWnU9SeSJRJ5Ht21UKhaOFoTcw0 2ks9hJSWE3WiRMSI9NfKu+K0G1i7Ne6NmVKuvwcCJRVzoD5McU+mrhhW9NcfKJBp8iMxP8dq4pAvG xYXW0AkO1qOYOEfLqfNgriXssLNqn5thTL2ntRfX+3YAqwRbsTyIJ9188bU+bvL+tClVPzZ3l/5U2 XmOF9xt0GMkZ2LsXdPHBE4fK3yE04+XHf6PdMNzOY/yYsPAjzttKqy7KFBGCl00G2TkOvP6Go9KA5 OR1ucOMBwWlMdAczVvtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1osjSy-00D3kK-7s; Wed, 09 Nov 2022 11:42:00 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1osjSZ-00D3Ko-IE for linux-arm-kernel@lists.infradead.org; Wed, 09 Nov 2022 11:41:37 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221109_034135_697018_B9118542 X-CRM114-Status: GOOD ( 11.41 ) 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 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 */