From patchwork Tue Mar 7 13:40:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 65511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2444874wrd; Tue, 7 Mar 2023 06:02:10 -0800 (PST) X-Google-Smtp-Source: AK7set/Gvqhk63Ubc8ENU0XBmSJaJRiVq8abNX1CyRhDx/W89wOj2vDy8M8Na8b9S9PMJoEbFTMo X-Received: by 2002:a05:6402:3d9:b0:4af:69e2:529f with SMTP id t25-20020a05640203d900b004af69e2529fmr15292113edw.27.1678197729743; Tue, 07 Mar 2023 06:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678197729; cv=none; d=google.com; s=arc-20160816; b=OTvxeFWAzL6ge5zSwzRAXrhwhJSJ6Hp6v1lwmaRvMxBtuP7WBgKrW6sgV2L1K2g6gK 3ZxRxAyYdBedV7neV4BY77emBe5Ik8G0UxwFkh2bnq5jjPXOo2wLH7bJbZ/nhHK0OrD/ RFAwWVIbSEAIa40yvmdDEzqn7grINb6VWSzYvXu4WfJD7Olmmsk6vT5XYDeB/dz8N3A4 sQT4vzq4EwD8AO3qeeV9IFwOXKtTsn418+5Gd+IRG1EAgwQRjvboANPt7o9hngRvK2Ub FNQvtOn/QysEKYmjkdP9mk+sL/sk3SGM5iW1Thx1z3bbrx6LJEdMuvw0ec7C2vwiRRuY 4xxg== 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=2Ol7IYKXSZjYoBT7ecxnVdjM/+CTMk4kzZLZVLFgpjU=; b=jmRzS2ihqRHNifxZIm8Y+MSpiHkbHv9B93v+YtyBcbE1KahMbR08GSMFkSPwSi4P40 3O0B21TD3zz/MlmJn7QscK8uM60tI5IgFtUMpNmmSd0WaQPyjk99AlQc9ImpF/x4CzAD NOCkHJ3cd2001rvR/njEoOWTUC3Qc1+YiE98EwQiEf3334WtDcm9/ZBijSj5sHMhBUJV gAU6xYgHop7hkpeHi/puzFTLohWR/KN/7yWHgXlUkRWMcVl7ztWbfoYSDjP4fnaK9hA8 2rWuDTKCsDq7qqmaF983CxD1Yx+W2tgH44j5MXn3J/T52WAApEqNeIkvZAszeVsqZ1wX l4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="i/nlkkmS"; 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 h9-20020a170906260900b008dbaff7a686si12014662ejc.634.2023.03.07.06.01.43; Tue, 07 Mar 2023 06:02:09 -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="i/nlkkmS"; 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 S230240AbjCGNm3 (ORCPT + 99 others); Tue, 7 Mar 2023 08:42:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231289AbjCGNlp (ORCPT ); Tue, 7 Mar 2023 08:41:45 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE7984F52; Tue, 7 Mar 2023 05:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1678196481; x=1709732481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cdS6mHiBTixmTNOVf/8YRXIdd/vQ3albcHU65V9xm3g=; b=i/nlkkmS/Nzx7ml/TVKpw2BC2p9hcknKzzvHKMTxrd7o0NGkfrw8W1p3 liwtMr75XIAes1egq7gXFwe7QtvQzv9Y/In8xYPKEd2+HCjkIQpTjiZd7 dIIh20PT2YJa1JddtXPqmIZ8Y6rE+IUZDlNYKWQiu+fbYfNnbeKvKW7NR Do2QsOfoRGV+sqY0mEAvbDSlYa3vVOGhsMWB9JFgPgzivXcilWKH+coAB rloKBueW9+Yt1VUGNNcMjp8WM2cEklFkiBxlpVUxfBF49bIs14mMI9rB0 4K1vVygnV2TD1Y9lpYoXZAO30Y0vnHvY7zP1oQ9GYGmTIqTrQajyzHsNz w==; X-IronPort-AV: E=Sophos;i="5.98,241,1673938800"; d="scan'208";a="140729354" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Mar 2023 06:41:20 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 7 Mar 2023 06:41:18 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 7 Mar 2023 06:41:14 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Russell King , Randy Dunlap , "Casper Andersson" , Nathan Huckleberry , Dan Carpenter , Michael Walle , "Wan Jiabing" , Qiheng Lin , "Shang XiaoJing" , Simon Horman Subject: [PATCH net-next 1/5] net: microchip: sparx5: Correct the spelling of the keysets in debugfs Date: Tue, 7 Mar 2023 14:40:59 +0100 Message-ID: <20230307134103.2042975-2-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307134103.2042975-1-steen.hegelund@microchip.com> References: <20230307134103.2042975-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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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?1759717862446364380?= X-GMAIL-MSGID: =?utf-8?q?1759717862446364380?= Correct the name used in the debugfs output. Signed-off-by: Steen Hegelund --- drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c index 07b472c84a47..12722f728ef7 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c @@ -198,7 +198,7 @@ static void sparx5_vcap_is2_port_keys(struct sparx5 *sparx5, out->prf(out->dst, "ip6_std"); break; case VCAP_IS2_PS_IPV6_MC_IP4_TCP_UDP_OTHER: - out->prf(out->dst, "ip4_tcp_udp ipv4_other"); + out->prf(out->dst, "ip4_tcp_udp ip4_other"); break; } out->prf(out->dst, "\n ipv6_uc: "); From patchwork Tue Mar 7 13:41:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 65507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2436496wrd; Tue, 7 Mar 2023 05:45:15 -0800 (PST) X-Google-Smtp-Source: AK7set/CSi7/FUhz5HNUc3cgmQ0C8/J+6cDVVVTkvTvRlVZCF8k3J62uWEyRPKK/fyxjs+azLTdP X-Received: by 2002:a05:6402:350:b0:4c0:eab4:af12 with SMTP id r16-20020a056402035000b004c0eab4af12mr13143584edw.12.1678196715642; Tue, 07 Mar 2023 05:45:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678196715; cv=none; d=google.com; s=arc-20160816; b=s7MH7Q+WPCYh8xDPa2gCAmQjOmwv5X9IuD5kMVz1lKlj8vzBqoFIDME1FLCI/Fr33N N5BnOYo+Krgw4XUHgpWq0fXFDBPmFFnrOFCsRhN97hXflZ0xoVcUyU1CcMzsGirMNneU tv6PJh6l/80tnF0hLL2nc4gT0L0FMzUMQzgBqU4F0WOoeAByfskFKJavrGnVqXccVOtE sniOp+tpF8Fek/15G84VqhVWw+AbW4PvXqDf8ajz68NoaQVDemwvsvMethiq9IW2uMn7 Nbyeh83210LFqfdGxDwpfWdqkULi2k8qtxKpdLkQGv9JiraypQYQq1n+VozBkH75vTsc z9ww== 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=QgkCVaGiKY69Sow8RE7AiGxHYOt/IndycZOCeiGcv0o=; b=TAQb9aZPIBSjt6YRX9tDcZJ8Mu/rXx2t7AxpRadktWKodirKg9+HTxfbsG3BXhrqYl xhEVmsDePktvag2NjgzllHNaFSBwRXKDbw+9bjr6E7Z5Z7JXhYnDGZzI4TvHIwZ+Q8w9 HaoxDTT5R4jB6tviVJsRlo8M+ufG+seVQGSL0/TQNtUqMNI78yk1axXxNAPDn/3Ge/0E oOAyI7vjs/a/nX3Ax4l0AtrYV7skvYFFDhXKZGiSeyeLzDy3WvmiILBayLYSCbGXF3os wZ8YMvC1/VEVmMMUqqcj8D8rUYf7jVsn2C3Kz7L31tU1yqiGUPTRfisbNnCOONHJE/H3 dxzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=ek6I+TdZ; 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 bv18-20020a170906b1d200b008deaca3a01csi12317157ejb.221.2023.03.07.05.44.52; Tue, 07 Mar 2023 05:45:15 -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=ek6I+TdZ; 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 S229869AbjCGNmW (ORCPT + 99 others); Tue, 7 Mar 2023 08:42:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbjCGNlr (ORCPT ); Tue, 7 Mar 2023 08:41:47 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 912FD8C940; Tue, 7 Mar 2023 05:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1678196484; x=1709732484; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F+3Zg9F1bICYM3YH1kFtL3Wm1Mck5R3cuhQLjOKAcZM=; b=ek6I+TdZzx/3HcgJnwT1JwyIzKLam+vgYKLlRwNnxEIbfH8sKVn2dFg/ wFsbJn+awQpD6dKXjFTMD1s0JWJGWEd649BWSRyWcjUMqoAtNS/fvFIFG Ik7rU3rAlUzbCvOgO9529OLbfHeXN2jhT5nGJGJUVqf5l3V3DbCDnxFgU DRlahmQCxgHF/TawHJBNZEegNcpZdrW5G8nztex7RWFuXliKSzLjW+K42 PMRfpl4XF7E1BURo3KULJvnWFCYaOcei9fbWSpyhCXb+JmRe2Uj6btpya rGDu0gGP0kv+gam/ka31W4D9ITZ/1dqiY4xWpOrKHf6EhfHx8Tl1DSswq w==; X-IronPort-AV: E=Sophos;i="5.98,241,1673938800"; d="scan'208";a="215163089" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Mar 2023 06:41:23 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 7 Mar 2023 06:41:22 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 7 Mar 2023 06:41:18 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Russell King , Randy Dunlap , "Casper Andersson" , Nathan Huckleberry , Dan Carpenter , Michael Walle , "Wan Jiabing" , Qiheng Lin , "Shang XiaoJing" , Simon Horman Subject: [PATCH net-next 2/5] net: microchip: sparx5: Provide rule count, key removal and keyset select Date: Tue, 7 Mar 2023 14:41:00 +0100 Message-ID: <20230307134103.2042975-3-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307134103.2042975-1-steen.hegelund@microchip.com> References: <20230307134103.2042975-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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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?1759716799424897270?= X-GMAIL-MSGID: =?utf-8?q?1759716799424897270?= This provides these 3 functions in the VCAP API: - Count the number of rules in a VCAP lookup (chain) - Remove a key from a VCAP rule - Find the keyset that gives the smallest rule list from a list of keysets Signed-off-by: Steen Hegelund --- .../net/ethernet/microchip/vcap/vcap_api.c | 61 +++++++++++++++++++ .../ethernet/microchip/vcap/vcap_api_client.h | 11 ++++ 2 files changed, 72 insertions(+) diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 4847d0d99ec9..5675b0962bc3 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -976,6 +976,25 @@ int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie) } EXPORT_SYMBOL_GPL(vcap_lookup_rule_by_cookie); +/* Get number of rules in a vcap instance lookup chain id range */ +int vcap_admin_rule_count(struct vcap_admin *admin, int cid) +{ + int max_cid = roundup(cid + 1, VCAP_CID_LOOKUP_SIZE); + int min_cid = rounddown(cid, VCAP_CID_LOOKUP_SIZE); + struct vcap_rule_internal *elem; + int count = 0; + + list_for_each_entry(elem, &admin->rules, list) { + mutex_lock(&admin->lock); + if (elem->data.vcap_chain_id >= min_cid && + elem->data.vcap_chain_id < max_cid) + ++count; + mutex_unlock(&admin->lock); + } + return count; +} +EXPORT_SYMBOL_GPL(vcap_admin_rule_count); + /* Make a copy of the rule, shallow or full */ static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri, bool full) @@ -3403,6 +3422,25 @@ int vcap_rule_mod_key_u32(struct vcap_rule *rule, enum vcap_key_field key, } EXPORT_SYMBOL_GPL(vcap_rule_mod_key_u32); +/* Remove a key field with value and mask in the rule */ +int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key) +{ + struct vcap_rule_internal *ri = to_intrule(rule); + struct vcap_client_keyfield *field; + + field = vcap_find_keyfield(rule, key); + if (!field) { + pr_err("%s:%d: key %s is not in the rule\n", + __func__, __LINE__, vcap_keyfield_name(ri->vctrl, key)); + return -EINVAL; + } + /* Deallocate the key field */ + list_del(&field->ctrl.list); + kfree(field); + return 0; +} +EXPORT_SYMBOL_GPL(vcap_rule_rem_key); + static int vcap_rule_mod_action(struct vcap_rule *rule, enum vcap_action_field action, enum vcap_field_type ftype, @@ -3475,6 +3513,29 @@ int vcap_filter_rule_keys(struct vcap_rule *rule, } EXPORT_SYMBOL_GPL(vcap_filter_rule_keys); +/* Select the keyset from the list that results in the smallest rule size */ +enum vcap_keyfield_set +vcap_select_min_rule_keyset(struct vcap_control *vctrl, + enum vcap_type vtype, + struct vcap_keyset_list *kslist) +{ + enum vcap_keyfield_set ret = VCAP_KFS_NO_VALUE; + const struct vcap_set *kset; + int max = 100, idx; + + for (idx = 0; idx < kslist->cnt; ++idx) { + kset = vcap_keyfieldset(vctrl, vtype, kslist->keysets[idx]); + if (!kset) + continue; + if (kset->sw_per_item >= max) + continue; + max = kset->sw_per_item; + ret = kslist->keysets[idx]; + } + return ret; +} +EXPORT_SYMBOL_GPL(vcap_select_min_rule_keyset); + /* Make a full copy of an existing rule with a new rule id */ struct vcap_rule *vcap_copy_rule(struct vcap_rule *erule) { diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h index 417af9754bcc..d9d1f7c9d762 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h @@ -201,6 +201,9 @@ int vcap_rule_add_action_bit(struct vcap_rule *rule, int vcap_rule_add_action_u32(struct vcap_rule *rule, enum vcap_action_field action, u32 value); +/* Get number of rules in a vcap instance lookup chain id range */ +int vcap_admin_rule_count(struct vcap_admin *admin, int cid); + /* VCAP rule counter operations */ int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl, struct vcap_counter *ctr, u64 cookie); @@ -269,6 +272,14 @@ int vcap_rule_mod_action_u32(struct vcap_rule *rule, int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key, u32 *value, u32 *mask); +/* Remove a key field with value and mask in the rule */ +int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key); + +/* Select the keyset from the list that results in the smallest rule size */ +enum vcap_keyfield_set +vcap_select_min_rule_keyset(struct vcap_control *vctrl, enum vcap_type vtype, + struct vcap_keyset_list *kslist); + struct vcap_client_actionfield * vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act); #endif /* __VCAP_API_CLIENT__ */ From patchwork Tue Mar 7 13:41:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 65520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2448971wrd; Tue, 7 Mar 2023 06:07:45 -0800 (PST) X-Google-Smtp-Source: AK7set/KzCX4ANaOkL3931OXiXkQ+AbBKc4KknqM6rjwiB7FSqF8jS/sL9/EnepNeB3yG5jMEwjv X-Received: by 2002:a05:6a21:9998:b0:cc:d514:62ce with SMTP id ve24-20020a056a21999800b000ccd51462cemr18125833pzb.44.1678198065040; Tue, 07 Mar 2023 06:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678198065; cv=none; d=google.com; s=arc-20160816; b=u0t0JsqRU+ZE0NMcLXC83buoE+UaZhaZnbIhju/Jcu5sewgVVEQHtHcjjBLnX2f4O1 Zf12TBCV6M0M4BQu+bLa//xXJMGul3SD/EiSE2hvIjRcioOO8BcggNk3MgvYWTNzQBVL TnEXhHAb4kpba9L+ci1aoSEfXm/M9KrQ/9DeOJmCOzh7AjHcRP9WjjQOuSvQ6A09pwX3 BJ05beb6jGfPSl+B3nvkaceS8dLiRldB4AFeUevztcFtiH2kdaLtV4ypiR/y4Tuz3Pdi wic2giYadTGM00Xv6i2TqEfJlzkzUYJIgBVmC3ySwvvrrTjGTgAqje35i9WXS7iz0RO6 nN9Q== 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=udVrtwpDgQidsraWkiTU3sYon+gPZjGt3QM9xlpO0rM=; b=tQFNc1AwmTOpDkcPU6hjH29XKvkh96QgySDX/Y/KNSbXstHMFdnu1YNeZdsIsHzsJI 8PY5Th5w1TXHouxGIRx1yMZG/KY2TNsGtKFyLOsgqhua9l1oTOKDLdhu9QCUjthedHdi ZAXcKKiK2977S/azU5C4j/X3piJEIWCdQrxW3bq7pP0vF/0NJZjKSyw4OknKO1aO7bO/ mjr7jymvfFkPqqon9NWel4J0ZJLbRuFyEjCkiZBnVxDVjElaw6gJQLxBo6+iUO7pDAVT cqFBGM5T0yfjo2j1RZerjOmYB14uvpcb0TkGSSFdOMNDUw0wgXV0Ns2ors2KRV1yWuj2 avTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=RL+ABgQx; 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 u186-20020a6385c3000000b004dab94e3f03si11823943pgd.758.2023.03.07.06.07.32; Tue, 07 Mar 2023 06:07:44 -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=RL+ABgQx; 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 S230147AbjCGNmZ (ORCPT + 99 others); Tue, 7 Mar 2023 08:42:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCGNl6 (ORCPT ); Tue, 7 Mar 2023 08:41:58 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C603C84F60; Tue, 7 Mar 2023 05:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1678196489; x=1709732489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PUBammHDKP0GgvUkYvFBhMxkRR+HIg6jyMG8E73e+pA=; b=RL+ABgQx7W/tnX3wunnMcZZhdmpWQdRVQmefEq+hoPbWRcVd4ko1OS2i 5omxQnZpicwAx/xBUT2YYEecCTir2e/4xqcdMGQMcYoXnOuaEk81d+hD3 T1MBqL++QZCBUGzw9lqaqrqW57i3+GFkOTnCtr3RKyNWjuj3xstewRJxv ZjlC4iGk32lc+lOyYrohtQVOFqlX7SO5nikDpzc0Mh/DTYZf7Kv1m/73S Mt2kVHvszRqhSGUFsSTAbnKj5dP/tq6FGMprjhU9pyBdf0ytWJPtiWg9G hjOXMKiPkb/LSGnHNq3HTdl1KgRZKedf67Z/WJ4kA2WLInvGMElNWpzhf g==; X-IronPort-AV: E=Sophos;i="5.98,241,1673938800"; d="scan'208";a="200373254" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Mar 2023 06:41:28 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Tue, 7 Mar 2023 06:41:27 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 7 Mar 2023 06:41:23 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Russell King , Randy Dunlap , "Casper Andersson" , Nathan Huckleberry , Dan Carpenter , Michael Walle , "Wan Jiabing" , Qiheng Lin , "Shang XiaoJing" , Simon Horman Subject: [PATCH net-next 3/5] net: microchip: sparx5: Add TC template list to a port Date: Tue, 7 Mar 2023 14:41:01 +0100 Message-ID: <20230307134103.2042975-4-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307134103.2042975-1-steen.hegelund@microchip.com> References: <20230307134103.2042975-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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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?1759718214042756000?= X-GMAIL-MSGID: =?utf-8?q?1759718214042756000?= This adds a list that is used to collect the templates that are active on a port. This allows the template creation to change the port configuration and the template destruction to change it back. Signed-off-by: Steen Hegelund --- drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 1 + drivers/net/ethernet/microchip/sparx5/sparx5_main.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c index 42b77ba9b572..a7edf524eedb 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c @@ -282,6 +282,7 @@ static int sparx5_create_port(struct sparx5 *sparx5, spx5_port->phylink_pcs.poll = true; spx5_port->phylink_pcs.ops = &sparx5_phylink_pcs_ops; spx5_port->is_mrouter = false; + INIT_LIST_HEAD(&spx5_port->tc_templates); sparx5->ports[config->portno] = spx5_port; err = sparx5_port_init(sparx5, spx5_port, &config->conf); diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 72e7928912eb..62c85463b634 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -192,6 +192,7 @@ struct sparx5_port { u16 ts_id; struct sk_buff_head tx_skbs; bool is_mrouter; + struct list_head tc_templates; /* list of TC templates on this port */ }; enum sparx5_core_clockfreq { From patchwork Tue Mar 7 13:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 65521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2448968wrd; Tue, 7 Mar 2023 06:07:45 -0800 (PST) X-Google-Smtp-Source: AK7set9aizY7XqK1fpm5ZG3GEGMIBxvLT0U+eB6MhwyiJY2R3H787dLsbaSs+/FkQ+cEzsVPCnyQ X-Received: by 2002:a17:903:41c3:b0:19c:e449:bbaa with SMTP id u3-20020a17090341c300b0019ce449bbaamr17613398ple.28.1678198064973; Tue, 07 Mar 2023 06:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678198064; cv=none; d=google.com; s=arc-20160816; b=CXPiyd1w097WOhzCwmzABjyFzwc5v45zCx8oJYv6E0e2tBJkXOlVOw8ll1sKCaUWMp DzLj19jg6KMTVJplG9bBCcgqw6N3in7px0fzs3D8hFKFOLJrTLyXYe/e3LWzy6MBkjTd jUxBJXilY2BGzN3AB+iKBMKOGdCrDxD3h9ObUgbobEvC9M1EvZYAe1XUzVwMWr1BImN1 2nOam94bLNHwxiitBnHC2AT+YUjotd+I956RDqcKDL56u7/9h8VRhdukBCowvPj6Wqo+ e0tV5wF4uYplQARG0O3PrIX+W+glwix4JfCTTJ4OyN5KuYhn+VdbHln2/4GjoYFrmvNF e+vA== 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=tPY+hcd/hK/ovXjBvyxF3CRvi/d7CtfeuZOnvCp1zTs=; b=TnXh2+LT6anwzt12EBfqqH4atlHkh0xJDozkmB+qmdXU/7ua3ojTG7gViZu1E8CQWs e6FSuyGYcoie0ZFI1f1nizPhCSy1+dEFznOivQHp8Uv6RFSrDh195xg7llBdxDs4aT8s mLNRV+zGe9xQiaEitNgc+uprLcU+dMtq5/PnsaRVMMUmjDLux104oCB09HhmA5/8N1bM SmoTtMewXn6sEtNnwQdcvZF5vPZbTS8QELoMLAbSjlzi32LksDq1U4VqXJ9Tn7V0PLXS xkN2DVVGVtSmul5yprIK50jcVuImCJV7G/ARdaZMTsP2CbbzfHgCicVklveem2CPiZo3 IJSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=whCn5Ei3; 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 q14-20020a170902eb8e00b0019a88f51635si11578702plg.534.2023.03.07.06.07.32; Tue, 07 Mar 2023 06:07:44 -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=whCn5Ei3; 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 S230119AbjCGNnC (ORCPT + 99 others); Tue, 7 Mar 2023 08:43:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjCGNmH (ORCPT ); Tue, 7 Mar 2023 08:42:07 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BC6B7FD66; Tue, 7 Mar 2023 05:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1678196499; x=1709732499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fLji4dHXnCuZYsTfpuhtMbbvzTNBhsv65gZkXAHwuBs=; b=whCn5Ei3BuTiFRt263sSH49LQayDl58ko3fKPnZ6WavUBy8t3+0ljPnm UNhaEsz2eQite07VSyvQsGYZQcbE+1SxPCfHRMX+P2cBG3K+zof9n8R8i RAY43DDPnwa774h2w3h8p8DLAuAOeN1R4qciuhL+hzF/0fBMPq6pDV05L oib7+yoMfV6ztb6uxZvKq9LzrcgmOMh+z3v44XeIEDN/7sQWNMSC4lz+h laQ+zlke8wVCRP3Y8ak9EMmyTu7JME+dZ6MPgMPKzisoJ2rMTrGfsHBk7 9nJBpeAPVlIHcLkIcCjMe/1j8Vyw1c2CsUzsqyMvMDZi7hlM5OnRUiPA/ Q==; X-IronPort-AV: E=Sophos;i="5.98,241,1673938800"; d="scan'208";a="200373261" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Mar 2023 06:41:38 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) 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.16; Tue, 7 Mar 2023 06:41:31 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 7 Mar 2023 06:41:27 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Russell King , Randy Dunlap , "Casper Andersson" , Nathan Huckleberry , Dan Carpenter , Michael Walle , "Wan Jiabing" , Qiheng Lin , "Shang XiaoJing" , Simon Horman Subject: [PATCH net-next 4/5] net: microchip: sparx5: Add port keyset changing functionality Date: Tue, 7 Mar 2023 14:41:02 +0100 Message-ID: <20230307134103.2042975-5-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307134103.2042975-1-steen.hegelund@microchip.com> References: <20230307134103.2042975-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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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?1759718214267993483?= X-GMAIL-MSGID: =?utf-8?q?1759718214267993483?= With this its is now possible for clients (like TC) to change the port keyset configuration in the Sparx5 VCAPs. This is typically done per traffic class which is guided with the L3 protocol information. Before the change the current keyset configuration is collected in a list that is handed back to the client. Signed-off-by: Steen Hegelund --- .../microchip/sparx5/sparx5_vcap_impl.c | 270 ++++++++++++++++++ .../microchip/sparx5/sparx5_vcap_impl.h | 6 + 2 files changed, 276 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c index d0d4e0385ac7..187efa1fc904 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c @@ -1519,6 +1519,276 @@ static struct vcap_operations sparx5_vcap_ops = { .port_info = sparx5_port_info, }; +static u32 sparx5_vcap_is0_keyset_to_etype_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_NORMAL_7TUPLE: + return VCAP_IS0_PS_ETYPE_NORMAL_7TUPLE; + case VCAP_KFS_NORMAL_5TUPLE_IP4: + return VCAP_IS0_PS_ETYPE_NORMAL_5TUPLE_IP4; + default: + return VCAP_IS0_PS_ETYPE_NORMAL_7TUPLE; + } +} + +static void sparx5_vcap_is0_set_port_keyset(struct net_device *ndev, int lookup, + enum vcap_keyfield_set keyset, + int l3_proto) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5 *sparx5 = port->sparx5; + int portno = port->portno; + u32 value; + + switch (l3_proto) { + case ETH_P_IP: + value = sparx5_vcap_is0_keyset_to_etype_ps(keyset); + spx5_rmw(ANA_CL_ADV_CL_CFG_IP4_CLM_KEY_SEL_SET(value), + ANA_CL_ADV_CL_CFG_IP4_CLM_KEY_SEL, + sparx5, + ANA_CL_ADV_CL_CFG(portno, lookup)); + break; + case ETH_P_IPV6: + value = sparx5_vcap_is0_keyset_to_etype_ps(keyset); + spx5_rmw(ANA_CL_ADV_CL_CFG_IP6_CLM_KEY_SEL_SET(value), + ANA_CL_ADV_CL_CFG_IP6_CLM_KEY_SEL, + sparx5, + ANA_CL_ADV_CL_CFG(portno, lookup)); + break; + default: + value = sparx5_vcap_is0_keyset_to_etype_ps(keyset); + spx5_rmw(ANA_CL_ADV_CL_CFG_ETYPE_CLM_KEY_SEL_SET(value), + ANA_CL_ADV_CL_CFG_ETYPE_CLM_KEY_SEL, + sparx5, + ANA_CL_ADV_CL_CFG(portno, lookup)); + break; + } +} + +static u32 sparx5_vcap_is2_keyset_to_arp_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_ARP: + return VCAP_IS2_PS_ARP_ARP; + default: + return VCAP_IS2_PS_ARP_MAC_ETYPE; + } +} + +static u32 sparx5_vcap_is2_keyset_to_ipv4_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_MAC_ETYPE: + return VCAP_IS2_PS_IPV4_UC_MAC_ETYPE; + case VCAP_KFS_IP4_OTHER: + case VCAP_KFS_IP4_TCP_UDP: + return VCAP_IS2_PS_IPV4_UC_IP4_TCP_UDP_OTHER; + case VCAP_KFS_IP_7TUPLE: + return VCAP_IS2_PS_IPV4_UC_IP_7TUPLE; + default: + return VCAP_KFS_NO_VALUE; + } +} + +static u32 sparx5_vcap_is2_keyset_to_ipv6_uc_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_MAC_ETYPE: + return VCAP_IS2_PS_IPV6_UC_MAC_ETYPE; + case VCAP_KFS_IP4_OTHER: + case VCAP_KFS_IP4_TCP_UDP: + return VCAP_IS2_PS_IPV6_UC_IP4_TCP_UDP_OTHER; + case VCAP_KFS_IP_7TUPLE: + return VCAP_IS2_PS_IPV6_UC_IP_7TUPLE; + default: + return VCAP_KFS_NO_VALUE; + } +} + +static u32 sparx5_vcap_is2_keyset_to_ipv6_mc_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_MAC_ETYPE: + return VCAP_IS2_PS_IPV6_MC_MAC_ETYPE; + case VCAP_KFS_IP4_OTHER: + case VCAP_KFS_IP4_TCP_UDP: + return VCAP_IS2_PS_IPV6_MC_IP4_TCP_UDP_OTHER; + case VCAP_KFS_IP_7TUPLE: + return VCAP_IS2_PS_IPV6_MC_IP_7TUPLE; + default: + return VCAP_KFS_NO_VALUE; + } +} + +static void sparx5_vcap_is2_set_port_keyset(struct net_device *ndev, int lookup, + enum vcap_keyfield_set keyset, + int l3_proto) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5 *sparx5 = port->sparx5; + int portno = port->portno; + u32 value; + + switch (l3_proto) { + case ETH_P_ARP: + value = sparx5_vcap_is2_keyset_to_arp_ps(keyset); + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_ARP_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_ARP_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + break; + case ETH_P_IP: + value = sparx5_vcap_is2_keyset_to_ipv4_ps(keyset); + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_IP4_UC_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_IP4_UC_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_IP4_MC_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_IP4_MC_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + break; + case ETH_P_IPV6: + value = sparx5_vcap_is2_keyset_to_ipv6_uc_ps(keyset); + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_IP6_UC_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_IP6_UC_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + value = sparx5_vcap_is2_keyset_to_ipv6_mc_ps(keyset); + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_IP6_MC_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_IP6_MC_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + break; + default: + value = VCAP_IS2_PS_NONETH_MAC_ETYPE; + spx5_rmw(ANA_ACL_VCAP_S2_KEY_SEL_NON_ETH_KEY_SEL_SET(value), + ANA_ACL_VCAP_S2_KEY_SEL_NON_ETH_KEY_SEL, + sparx5, + ANA_ACL_VCAP_S2_KEY_SEL(portno, lookup)); + break; + } +} + +static u32 sparx5_vcap_es2_keyset_to_arp_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_ARP: + return VCAP_ES2_PS_ARP_ARP; + default: + return VCAP_ES2_PS_ARP_MAC_ETYPE; + } +} + +static u32 sparx5_vcap_es2_keyset_to_ipv4_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_MAC_ETYPE: + return VCAP_ES2_PS_IPV4_MAC_ETYPE; + case VCAP_KFS_IP_7TUPLE: + return VCAP_ES2_PS_IPV4_IP_7TUPLE; + case VCAP_KFS_IP4_TCP_UDP: + return VCAP_ES2_PS_IPV4_IP4_TCP_UDP_OTHER; + case VCAP_KFS_IP4_OTHER: + return VCAP_ES2_PS_IPV4_IP4_OTHER; + default: + return VCAP_ES2_PS_IPV4_MAC_ETYPE; + } +} + +static u32 sparx5_vcap_es2_keyset_to_ipv6_ps(enum vcap_keyfield_set keyset) +{ + switch (keyset) { + case VCAP_KFS_MAC_ETYPE: + return VCAP_ES2_PS_IPV6_MAC_ETYPE; + case VCAP_KFS_IP4_TCP_UDP: + case VCAP_KFS_IP4_OTHER: + return VCAP_ES2_PS_IPV6_IP4_DOWNGRADE; + case VCAP_KFS_IP_7TUPLE: + return VCAP_ES2_PS_IPV6_IP_7TUPLE; + case VCAP_KFS_IP6_STD: + return VCAP_ES2_PS_IPV6_IP6_STD; + default: + return VCAP_ES2_PS_IPV6_MAC_ETYPE; + } +} + +static void sparx5_vcap_es2_set_port_keyset(struct net_device *ndev, int lookup, + enum vcap_keyfield_set keyset, + int l3_proto) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5 *sparx5 = port->sparx5; + int portno = port->portno; + u32 value; + + switch (l3_proto) { + case ETH_P_IP: + value = sparx5_vcap_es2_keyset_to_ipv4_ps(keyset); + spx5_rmw(EACL_VCAP_ES2_KEY_SEL_IP4_KEY_SEL_SET(value), + EACL_VCAP_ES2_KEY_SEL_IP4_KEY_SEL, + sparx5, + EACL_VCAP_ES2_KEY_SEL(portno, lookup)); + break; + case ETH_P_IPV6: + value = sparx5_vcap_es2_keyset_to_ipv6_ps(keyset); + spx5_rmw(EACL_VCAP_ES2_KEY_SEL_IP6_KEY_SEL_SET(value), + EACL_VCAP_ES2_KEY_SEL_IP6_KEY_SEL, + sparx5, + EACL_VCAP_ES2_KEY_SEL(portno, lookup)); + break; + case ETH_P_ARP: + value = sparx5_vcap_es2_keyset_to_arp_ps(keyset); + spx5_rmw(EACL_VCAP_ES2_KEY_SEL_ARP_KEY_SEL_SET(value), + EACL_VCAP_ES2_KEY_SEL_ARP_KEY_SEL, + sparx5, + EACL_VCAP_ES2_KEY_SEL(portno, lookup)); + break; + } +} + +/* Change the port keyset for the lookup and protocol */ +void sparx5_vcap_set_port_keyset(struct net_device *ndev, + struct vcap_admin *admin, + int cid, + u16 l3_proto, + enum vcap_keyfield_set keyset, + struct vcap_keyset_list *orig) +{ + struct sparx5_port *port; + int lookup; + + switch (admin->vtype) { + case VCAP_TYPE_IS0: + lookup = sparx5_vcap_is0_cid_to_lookup(cid); + if (orig) + sparx5_vcap_is0_get_port_keysets(ndev, lookup, orig, + l3_proto); + sparx5_vcap_is0_set_port_keyset(ndev, lookup, keyset, l3_proto); + break; + case VCAP_TYPE_IS2: + lookup = sparx5_vcap_is2_cid_to_lookup(cid); + if (orig) + sparx5_vcap_is2_get_port_keysets(ndev, lookup, orig, + l3_proto); + sparx5_vcap_is2_set_port_keyset(ndev, lookup, keyset, l3_proto); + break; + case VCAP_TYPE_ES0: + break; + case VCAP_TYPE_ES2: + lookup = sparx5_vcap_es2_cid_to_lookup(cid); + if (orig) + sparx5_vcap_es2_get_port_keysets(ndev, lookup, orig, + l3_proto); + sparx5_vcap_es2_set_port_keyset(ndev, lookup, keyset, l3_proto); + break; + default: + port = netdev_priv(ndev); + sparx5_vcap_type_err(port->sparx5, admin, __func__); + break; + } +} + /* Enable IS0 lookups per port and set the keyset generation */ static void sparx5_vcap_is0_port_key_selection(struct sparx5 *sparx5, struct vcap_admin *admin) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.h b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.h index 3260ab5e3a82..2684d9199b05 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.h @@ -195,6 +195,12 @@ int sparx5_vcap_get_port_keyset(struct net_device *ndev, u16 l3_proto, struct vcap_keyset_list *kslist); +/* Change the port keyset for the lookup and protocol */ +void sparx5_vcap_set_port_keyset(struct net_device *ndev, + struct vcap_admin *admin, int cid, + u16 l3_proto, enum vcap_keyfield_set keyset, + struct vcap_keyset_list *orig); + /* Check if the ethertype is supported by the vcap port classification */ bool sparx5_vcap_is_known_etype(struct vcap_admin *admin, u16 etype); From patchwork Tue Mar 7 13:41:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 65517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2448605wrd; Tue, 7 Mar 2023 06:07:14 -0800 (PST) X-Google-Smtp-Source: AK7set8VeilMrKvcVbX15dZIR/RMJPyeuUdmUkflHSOWnaCSvQDprS5rno/rRkcu180y28e20y3I X-Received: by 2002:a17:90b:4c0c:b0:237:f8f9:8a2a with SMTP id na12-20020a17090b4c0c00b00237f8f98a2amr15560166pjb.25.1678198034611; Tue, 07 Mar 2023 06:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678198034; cv=none; d=google.com; s=arc-20160816; b=adynGRKhW2xk//r7VapWi+u1coq4WAD+lcAMIR02edgnV06FG0e8BjpC7t4XoPqY7K LoBe4PNwM7D38B7v6NiOEXk/4qnQ3k0MCMb4Ig/CpL7/cvN9oSvbwigu7GDEzTTJEAPq XLoDSQIZpMXl3fzB4nxq95rK4TVjGz16uOL0LNipV65QVlLzSNH14j/mwiys0672YPVv VN/KTJz6sA46LTJTz5QNWU7f66WVKMRcw5DxCC52Yg5EzLo8I9NGvmf2FKJ+1bpc4MYv mriJX/rlC75zAS5j5ShjehxMYKCJY/9HBSjF0+NOtBgV8jGqlKisdk3S2qiG3GftoCLj X3bw== 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=au/tZpHoL9RbjhtIYkhaw6+24cJTQJk2IdNVGhIMXf0=; b=XfewaAqFqWgfgSE0JPFmFa1VwddEgzrQDWf6/hncG5RCk0vjnM/UcoMw/JFKrSZd00 gPa8PhlVU9/ZC7Qgj+ZPZTSL70AI4QzrAgRTz8EqYXmJDlGNWGH9uCxvRiW0VxA9yeHN MQ/RH4DHoCsICv24AvwqPGGeVMD/yxQfAmSIHNGc9gOXUEDl7JqY7tjomjOv494jIJPP mTcq2y9sZP6rWSX3jRpUlD1mNbZZKypBODDfC7ChFMuexNVfWT5I6DdgQyIQI8m9pie8 +PnMo4GEDTLGQqRBpNHNy3PmefDmb3bL9fDvYDB8cSA0TZMWkMmS0r71gZ23eLvGuuKh B/EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=mXjy85rH; 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 84-20020a630557000000b00502e4676ac9si11382861pgf.584.2023.03.07.06.07.01; Tue, 07 Mar 2023 06:07:14 -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=mXjy85rH; 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 S230190AbjCGNnF (ORCPT + 99 others); Tue, 7 Mar 2023 08:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjCGNmJ (ORCPT ); Tue, 7 Mar 2023 08:42:09 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D361F58C1C; Tue, 7 Mar 2023 05:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1678196500; x=1709732500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VCZYVPWTpYIthRDpRzPvQJ5YjZk4hP1f2XCh2XaN/I4=; b=mXjy85rHdFQVHMIFb556ys+wE6Kx5GH6dG7QA0b7zp+unAl07R1t0KGo 7S0J2RRoU9hwu57Gf25xc1hSuhaXTTQO45YRPdF7fZxmGEnRvhCDl2/8S 1TZs+/CBT9xO7hL97xWp9fbUNmCQdK86ODCPllYMwsM8QvR7aBAmKe9P1 8vpGQ6WpxQ6VgpcxKJ9nPG0OtRSbFvAMGdnuNiX2Ub0Pl/t9bVvUM8ui0 akCpIbodXvluBX3AhW69zxAcMS8GG65VTwyEQsIMaYlpa2vn09a0O7I3W PONyK0iKzvBpxnxAzwG9mgA/3Hr2H2Bot8tjmfyYQTkATTza6lSd6nnU4 w==; X-IronPort-AV: E=Sophos;i="5.98,241,1673938800"; d="scan'208";a="215163113" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 07 Mar 2023 06:41:39 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) 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.16; Tue, 7 Mar 2023 06:41:35 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Tue, 7 Mar 2023 06:41:31 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Russell King , Randy Dunlap , "Casper Andersson" , Nathan Huckleberry , Dan Carpenter , Michael Walle , "Wan Jiabing" , Qiheng Lin , "Shang XiaoJing" , Simon Horman Subject: [PATCH net-next 5/5] net: microchip: sparx5: Add TC template support Date: Tue, 7 Mar 2023 14:41:03 +0100 Message-ID: <20230307134103.2042975-6-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307134103.2042975-1-steen.hegelund@microchip.com> References: <20230307134103.2042975-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, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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?1759718182235682039?= X-GMAIL-MSGID: =?utf-8?q?1759718182235682039?= This adds support for using the "template add" and "template destroy" functionality to change the port keyset configuration. If the VCAP lookup already contains rules, the port keyset is left unchanged, as a change would make these rules unusable. When the template is destroyed the port keyset configuration is restored. The filters using the template chain will automatically be deleted by the TC framework. Signed-off-by: Steen Hegelund --- .../microchip/sparx5/sparx5_tc_flower.c | 209 +++++++++++++++++- 1 file changed, 202 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c index b36819aafaca..3f87a5285a6d 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c @@ -28,6 +28,14 @@ struct sparx5_multiple_rules { struct sparx5_wildcard_rule rule[SPX5_MAX_RULE_SIZE]; }; +struct sparx5_tc_flower_template { + struct list_head list; /* for insertion in the list of templates */ + int cid; /* chain id */ + enum vcap_keyfield_set orig; /* keyset used before the template */ + enum vcap_keyfield_set keyset; /* new keyset used by template */ + u16 l3_proto; /* protocol specified in the template */ +}; + static int sparx5_tc_flower_es0_tpid(struct vcap_tc_flower_parse_usage *st) { @@ -382,7 +390,7 @@ static int sparx5_tc_select_protocol_keyset(struct net_device *ndev, /* Find the keysets that the rule can use */ matches.keysets = keysets; matches.max = ARRAY_SIZE(keysets); - if (vcap_rule_find_keysets(vrule, &matches) == 0) + if (!vcap_rule_find_keysets(vrule, &matches)) return -EINVAL; /* Find the keysets that the port configuration supports */ @@ -996,6 +1004,73 @@ static int sparx5_tc_action_vlan_push(struct vcap_admin *admin, return err; } +/* Remove rule keys that may prevent templates from matching a keyset */ +static void sparx5_tc_flower_simplify_rule(struct vcap_admin *admin, + struct vcap_rule *vrule, + u16 l3_proto) +{ + switch (admin->vtype) { + case VCAP_TYPE_IS0: + vcap_rule_rem_key(vrule, VCAP_KF_ETYPE); + switch (l3_proto) { + case ETH_P_IP: + break; + case ETH_P_IPV6: + vcap_rule_rem_key(vrule, VCAP_KF_IP_SNAP_IS); + break; + default: + break; + } + break; + case VCAP_TYPE_ES2: + switch (l3_proto) { + case ETH_P_IP: + if (vrule->keyset == VCAP_KFS_IP4_OTHER) + vcap_rule_rem_key(vrule, VCAP_KF_TCP_IS); + break; + case ETH_P_IPV6: + if (vrule->keyset == VCAP_KFS_IP6_STD) + vcap_rule_rem_key(vrule, VCAP_KF_TCP_IS); + vcap_rule_rem_key(vrule, VCAP_KF_IP4_IS); + break; + default: + break; + } + break; + case VCAP_TYPE_IS2: + switch (l3_proto) { + case ETH_P_IP: + case ETH_P_IPV6: + vcap_rule_rem_key(vrule, VCAP_KF_IP4_IS); + break; + default: + break; + } + break; + default: + break; + } +} + +static bool sparx5_tc_flower_use_template(struct net_device *ndev, + struct flow_cls_offload *fco, + struct vcap_admin *admin, + struct vcap_rule *vrule) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5_tc_flower_template *ftp; + + list_for_each_entry(ftp, &port->tc_templates, list) { + if (ftp->cid != fco->common.chain_index) + continue; + + vcap_set_rule_set_keyset(vrule, ftp->keyset); + sparx5_tc_flower_simplify_rule(admin, vrule, ftp->l3_proto); + return true; + } + return false; +} + static int sparx5_tc_flower_replace(struct net_device *ndev, struct flow_cls_offload *fco, struct vcap_admin *admin, @@ -1122,12 +1197,14 @@ static int sparx5_tc_flower_replace(struct net_device *ndev, goto out; } - err = sparx5_tc_select_protocol_keyset(ndev, vrule, admin, - state.l3_proto, &multi); - if (err) { - NL_SET_ERR_MSG_MOD(fco->common.extack, - "No matching port keyset for filter protocol and keys"); - goto out; + if (!sparx5_tc_flower_use_template(ndev, fco, admin, vrule)) { + err = sparx5_tc_select_protocol_keyset(ndev, vrule, admin, + state.l3_proto, &multi); + if (err) { + NL_SET_ERR_MSG_MOD(fco->common.extack, + "No matching port keyset for filter protocol and keys"); + goto out; + } } /* provide the l3 protocol to guide the keyset selection */ @@ -1259,6 +1336,120 @@ static int sparx5_tc_flower_stats(struct net_device *ndev, return err; } +static int sparx5_tc_flower_template_create(struct net_device *ndev, + struct flow_cls_offload *fco, + struct vcap_admin *admin) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct vcap_tc_flower_parse_usage state = { + .fco = fco, + .l3_proto = ETH_P_ALL, + .admin = admin, + }; + struct sparx5_tc_flower_template *ftp; + struct vcap_keyset_list kslist = {}; + enum vcap_keyfield_set keysets[10]; + struct vcap_control *vctrl; + struct vcap_rule *vrule; + int count, err; + + if (admin->vtype == VCAP_TYPE_ES0) { + pr_err("%s:%d: %s\n", __func__, __LINE__, + "VCAP does not support templates"); + return -EINVAL; + } + + count = vcap_admin_rule_count(admin, fco->common.chain_index); + if (count > 0) { + pr_err("%s:%d: %s\n", __func__, __LINE__, + "Filters are already present"); + return -EBUSY; + } + + ftp = kzalloc(sizeof(*ftp), GFP_KERNEL); + if (!ftp) + return -ENOMEM; + + ftp->cid = fco->common.chain_index; + ftp->orig = VCAP_KFS_NO_VALUE; + ftp->keyset = VCAP_KFS_NO_VALUE; + + vctrl = port->sparx5->vcap_ctrl; + vrule = vcap_alloc_rule(vctrl, ndev, fco->common.chain_index, + VCAP_USER_TC, fco->common.prio, 0); + if (IS_ERR(vrule)) { + err = PTR_ERR(vrule); + goto err_rule; + } + + state.vrule = vrule; + state.frule = flow_cls_offload_flow_rule(fco); + err = sparx5_tc_use_dissectors(&state, admin, vrule); + if (err) { + pr_err("%s:%d: key error: %d\n", __func__, __LINE__, err); + goto out; + } + + ftp->l3_proto = state.l3_proto; + + sparx5_tc_flower_simplify_rule(admin, vrule, state.l3_proto); + + /* Find the keysets that the rule can use */ + kslist.keysets = keysets; + kslist.max = ARRAY_SIZE(keysets); + if (!vcap_rule_find_keysets(vrule, &kslist)) { + pr_err("%s:%d: %s\n", __func__, __LINE__, + "Could not find a suitable keyset"); + err = -ENOENT; + goto out; + } + + ftp->keyset = vcap_select_min_rule_keyset(vctrl, admin->vtype, &kslist); + kslist.cnt = 0; + sparx5_vcap_set_port_keyset(ndev, admin, fco->common.chain_index, + state.l3_proto, + ftp->keyset, + &kslist); + + if (kslist.cnt > 0) + ftp->orig = kslist.keysets[0]; + + /* Store new template */ + list_add_tail(&ftp->list, &port->tc_templates); + vcap_free_rule(vrule); + return 0; + +out: + vcap_free_rule(vrule); +err_rule: + kfree(ftp); + return err; +} + +static int sparx5_tc_flower_template_destroy(struct net_device *ndev, + struct flow_cls_offload *fco, + struct vcap_admin *admin) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5_tc_flower_template *ftp, *tmp; + int err = -ENOENT; + + /* Rules using the template are removed by the tc framework */ + list_for_each_entry_safe(ftp, tmp, &port->tc_templates, list) { + if (ftp->cid != fco->common.chain_index) + continue; + + sparx5_vcap_set_port_keyset(ndev, admin, + fco->common.chain_index, + ftp->l3_proto, ftp->orig, + NULL); + list_del(&ftp->list); + kfree(ftp); + break; + } + return err; +} + int sparx5_tc_flower(struct net_device *ndev, struct flow_cls_offload *fco, bool ingress) { @@ -1282,6 +1473,10 @@ int sparx5_tc_flower(struct net_device *ndev, struct flow_cls_offload *fco, return sparx5_tc_flower_destroy(ndev, fco, admin); case FLOW_CLS_STATS: return sparx5_tc_flower_stats(ndev, fco, admin); + case FLOW_CLS_TMPLT_CREATE: + return sparx5_tc_flower_template_create(ndev, fco, admin); + case FLOW_CLS_TMPLT_DESTROY: + return sparx5_tc_flower_template_destroy(ndev, fco, admin); default: return -EOPNOTSUPP; }