From patchwork Wed Nov 2 11:57:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 14198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3572349wru; Wed, 2 Nov 2022 04:59:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+VsGRNmJUm+yTbTkxouyfQJMujOJUB6pnFD2Hz8AYXiR+wu85JT6FB1/KqM7UHzBdbsvs X-Received: by 2002:a17:906:5a51:b0:7ad:cf9e:bfc6 with SMTP id my17-20020a1709065a5100b007adcf9ebfc6mr16460034ejc.445.1667390361189; Wed, 02 Nov 2022 04:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667390361; cv=none; d=google.com; s=arc-20160816; b=I0zCTgbjoV8pfPVMlGiruv4VI2CNAMCq3Qz686rdwm9pJIV/tIlCUNn6Fz9swOssSh JtlhzGs6UUaLNfMR18oFeEf8RSmTIVd3Sp0V1LxoyUDTqOH4CITaFbUHCB/B2tA0WZDn 1k6uN2DjnVi7txU4NbQFJGjAHxSmzNQn+YaFJO7pOJRB1G2+l6gdGpwL6by9zyVVtQWS qWaoSL/kJZ5NdEvCHVBSAVE6jix0v7OckGpHdtSTfROpr/zCsZud74L5VOxNanZ/Xp1h blfpH5tXbq65ovTg65eSIo/xkqRomnFTQK90WLCJBVqUmDy/2hSsXraKv0ur1f5yLAVH XJ5w== 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=TqAvy4xlvw1sINpWBhylnotXgtAutRWBneWrQUmBH2zk2ZcPxvfbOnnPRDIF29BdNm ELRrtoSM0+1IvFVjx2v0xWU/XbjV9pzdQNbNxNy/Kwt/37l5b/YfbfIb2m93yuuotvm0 qcp6EFp+0IrVb/TjhXbAgBc7uXaPTERox4Y5l/HNbmrMrcyZT5GR6TQsTCUsJEDc0Xp8 hOrvSK7LLdcV4tzO74ojGmF5eEJm1spRWieDf7nb3/Wo571VfysAdOJS+eSsr43m6VJA iOzOPBsk+GE9l2oyRYeoQZIIjZibMWUVf0BCnTZr/97s2tpj6T6QOkVFnjyUfSLCpFGN KmZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=uV57iube; 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 js2-20020a17090797c200b0078d9f02b452si18016948ejc.861.2022.11.02.04.58.58; Wed, 02 Nov 2022 04:59:21 -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=uV57iube; 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 S230397AbiKBL62 (ORCPT + 99 others); Wed, 2 Nov 2022 07:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbiKBL6E (ORCPT ); Wed, 2 Nov 2022 07:58:04 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B9D29C87; Wed, 2 Nov 2022 04:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1667390282; x=1698926282; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zg1ZOB9VAKT8wYILwCnjHS5DdA5dyjtXwq8br0fWHdo=; b=uV57iubeIRPT/474tkSTPZyklZmkZ3fdZKLUC9tSN/2S2CrnQ9Hq/ADm lOXVR5ldg5+b7TGO+LNxbss1NC87z0LY25W0y3NEHU0gJEgJlozT7Kf0p JubOAKSB1Bm/hw6j+GF5F7llh0fPlevXsMttkgP+jiYCV/kC9Qt/cFqXf jX5x1IW3rcKV+DqJfhxbwFfYZF1mbFDxANQoSko57VyHzj4M8VVpfs4fY mw+sKjNhf0jO8OSILW4b76eaP/xkjZHjmYUPsCQMnOYFLqJlq478ix1iZ QeqKV9MuagOE5otpiWjVqkvfXNEXaI+wWq96eTiMXcsl2tPxe6QD6DWao Q==; X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="181583225" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 02 Nov 2022 04:58:01 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 2 Nov 2022 04:57:56 -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, 2 Nov 2022 04:57:53 -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 v4 3/7] net: microchip: sparx5: Find VCAP lookup from chain id Date: Wed, 2 Nov 2022 12:57:33 +0100 Message-ID: <20221102115737.4118808-4-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102115737.4118808-1-steen.hegelund@microchip.com> References: <20221102115737.4118808-1-steen.hegelund@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-5.5 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?1748385515468356226?= X-GMAIL-MSGID: =?utf-8?q?1748385515468356226?= 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 */