From patchwork Fri Nov 4 14:18:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 15581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp432246wru; Fri, 4 Nov 2022 07:19:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rCKiOGAdVEMf4EqAEX5+P2HLg/cglfq5lA2DblT7oR2mGjQkUQXTVC13VIsjIgHpntdlW X-Received: by 2002:a05:6a00:1702:b0:56d:7145:dff2 with SMTP id h2-20020a056a00170200b0056d7145dff2mr27425268pfc.34.1667571592891; Fri, 04 Nov 2022 07:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667571592; cv=none; d=google.com; s=arc-20160816; b=k+ldLeqz2IxXNIDerHA5/1lecQReGGjxAGuDUcKNtabxbT9fhCCelz9mu2SJ2Pp+oU eqv8Vfkjf7U7BxNRCRJfEAXpqJgqe6lwcpZ0E3SDtEGDnUbokPGs3IxZr9FlK1TyG0LJ ZWSTtfQMUAOlp/Y8WglSmC63LT0CGTQq3WMzA9Qig327U7aGGK1svg7g30fGXuE/BNxh XwLbTDgBKLju9wDbgL9vkIhOZdU+7HAplqTkW35npyU+qClBy7WJn8gHXZ+nq0/ylc04 6LFtW3neCXfgsHtRPKqBEoz4ambanX0rr68ON+DVTn0rBKNhzTRszN3wQQRJGOdSC9cG DT/Q== 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=kvzQjIegPa1mZfwwPzOcGcsDfb174Ndl+lsVsGrEtcgweo1IYqPdCKos4DLInCyqeN BYct43NImTVcn/oV97PFu9UCQ4xA4BTnz28w4jLXeMyKHMJoiYcNAH6qkelObndX5ioP 6fGtoBbeJv0A/FV0nqkrEzy7Al1JyvQd2z1ZwrEDjKF9qnbyMpePoPxWfLKnvP5yxzPj yqUvGI2j3W6BPOjtfPdIn5mRcyQ/IYlOyqCZZ4GVFlNnXdK90+N/C7czvBZqgPEauQSs Uv1Dzfpydri+sAKYqiyLthpNEYiysXrp8Kk9ImaqT3qMeNUQOOthm0JL/flWLmSBAb9R FIAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=KxKbiKaL; 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 y192-20020a638ac9000000b00441e10f5e3bsi4649484pgd.539.2022.11.04.07.19.39; Fri, 04 Nov 2022 07:19:52 -0700 (PDT) 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=KxKbiKaL; 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 S232033AbiKDOTG (ORCPT + 99 others); Fri, 4 Nov 2022 10:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231756AbiKDOSv (ORCPT ); Fri, 4 Nov 2022 10:18:51 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE7072181; Fri, 4 Nov 2022 07:18:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667571530; x=1699107530; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zg1ZOB9VAKT8wYILwCnjHS5DdA5dyjtXwq8br0fWHdo=; b=KxKbiKaL2EXtNPzxa2HUre783ziAhQvjAP+B2GmZ7EOcCYIfVyRCe4Ff myrOSVD3FPynz0CqSWr+YltW4XXdyhk85GYsTqf90/D9rN2TxB5Al43J4 wfbF4S2vU/Bz8Ik2gx8lEMYgZwtSZAQtkz8CWmXEiVzNjODcwcyQOQ9wy MztZ9QRVSxlTy6rn0EkPMESV9bz2I6ihCWbsfmLSl//NNYaYcsCPwb9iB gP41/0FTuQj85tEtGrJPQCVZtz8YIVUD0O2qbH44iicSmN2r2nTVDWFKe Shm1Io13Tra+ACDCIWgGeHJHoDwBC8ft65COgEfbbWAKXUABlPi+FPow7 A==; X-IronPort-AV: E=Sophos;i="5.96,137,1665471600"; d="scan'208";a="121853227" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 04 Nov 2022 07:18:49 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Fri, 4 Nov 2022 07:18:48 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Fri, 4 Nov 2022 07:18:45 -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 v5 3/8] net: microchip: sparx5: Find VCAP lookup from chain id Date: Fri, 4 Nov 2022 15:18:25 +0100 Message-ID: <20221104141830.1527159-4-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221104141830.1527159-1-steen.hegelund@microchip.com> References: <20221104141830.1527159-1-steen.hegelund@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-5.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?1748575550425035102?= X-GMAIL-MSGID: =?utf-8?q?1748575550425035102?= 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 */