From patchwork Fri Nov 11 13:05:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 18733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp729215wru; Fri, 11 Nov 2022 05:08:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TmkK9zJzUI/TKjXk2fsvEGUb7nBo5WlGloyLHgSCuFuTyPSOVBqHgDtfHtxLr+oYNaMB3 X-Received: by 2002:a17:906:71d8:b0:7ad:b45c:dbe1 with SMTP id i24-20020a17090671d800b007adb45cdbe1mr1737260ejk.726.1668172113589; Fri, 11 Nov 2022 05:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668172113; cv=none; d=google.com; s=arc-20160816; b=PFX4/hsJFtI3ApSAu9+FrzBkrvn5YtaXHH4ba4jGAEAPyphmZl3aFzmRncGcmxoh1G YhP1bUKNews0ilNHCQCW1GAcSrZHoMq/YdyHt9eg/P5UqMMd3kCNmve9CfYN/W4NrggC wL13c75Ms57vB+8xLEmAiD6z9jwXgHEUhkxyH++TrzMnnBnKUeZeQHAxlXYxsoQdf5oS 1jkFKo/iil3Oov30l8nCRHp5XGxwKxnc2BOSsN5BJqCegWvId7HeET9yVzatC5kXMAOq TRk5+dZCbAVbfiMkU0++wsZWIAqBp+HXXAtVIhl8+5e6OH1yzeh28JO+NImV33h+ZiI8 OxmQ== 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=gHpEW30MzBfDt2eF9wcu2TGUjjHEleFtHrOsdyMAOi8=; b=h/kQQPLSyG3nwOcyg84/6Bq4TsmeNfQmw2TuIvjWXFy3CM+qyQeXSLoq2NN59eteIO YIVoD2O2RiWsxAs6y1MYPZwHdeaGkXbTfvQblg1GAmtdNjmw6cB+HUQ4wXbSif+vDdPb qdsBSHRgA5YcKR5th/yKBrq1NlGwkq1u7dLsVpKDgcmJMnpy5elceDv2AQHvXcAcgaQg kZRsS/GVQL93v9+XhSMEnbc2pfXFaXIn1khTIOkg1zD0xtodPtntRBMKryQm5LgrXIrT tt+XsmOQKc0hXAfKMKTZTjL/6oQidiaQVfbb7+pjjuJzvxH8dpzyJ6Mi4hUWSje5Vn+e TNMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=RX8MhFQd; 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 l12-20020a17090615cc00b0079b9f472d85si1570923ejd.698.2022.11.11.05.08.02; Fri, 11 Nov 2022 05:08:33 -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=RX8MhFQd; 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 S233982AbiKKNGl (ORCPT + 99 others); Fri, 11 Nov 2022 08:06:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbiKKNGd (ORCPT ); Fri, 11 Nov 2022 08:06:33 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8130862F4; Fri, 11 Nov 2022 05:05:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1668171958; x=1699707958; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8XwoBqdgKoM5V3kbMOhCihQp2eLtKE9DTDcoUojaHV4=; b=RX8MhFQdVuAkumfqNqv1sBrTpXU7jlPYgZTTuypDpdw9O6E/KJi6HrUF kztBg2qCQ9VHhJAqDv3qbkucUMXB7k4WiPKHF664ps45s4v9hvsI0qzxM rG4RDbnNyR1jVF9g8T4ne/jwSoAKAdae82pk9ed+GNaD3L/NswqXsivKx Dl8EtUEU5x8mcptjfZ7ZO86weBjaw7RLl5f2tDzrZLVhA5X6SDAUhP39d 2YmQcjvlaQ2l1qitTEESj51qNtDh+W0EUiZ+yjsKU5mLI5LaNBu+SMnx7 UCdpLMG6wcqgcwV56pBxIzQwA4StR015a7ABOlxAj31LDGtirYy4mevvT w==; X-IronPort-AV: E=Sophos;i="5.96,156,1665471600"; d="scan'208";a="123001275" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 11 Nov 2022 06:05:57 -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.12; Fri, 11 Nov 2022 06:05:51 -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.12 via Frontend Transport; Fri, 11 Nov 2022 06:05:47 -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" , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen , Simon Horman , Louis Peens , "Wojciech Drewek" , Baowen Zheng , Maksym Glubokiy , Pablo Neira Ayuso Subject: [PATCH net-next 5/6] net: microchip: sparx5: Add support for TC flower filter statistics Date: Fri, 11 Nov 2022 14:05:18 +0100 Message-ID: <20221111130519.1459549-6-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221111130519.1459549-1-steen.hegelund@microchip.com> References: <20221111130519.1459549-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?1749205242065476979?= X-GMAIL-MSGID: =?utf-8?q?1749205242065476979?= This provides flower filter packet statistics (bytes are not supported) via the dedicated IS2 counter feature. All rules having the same TC cookie will contribute to the packet statistics for the filter as they are considered to be part of the same TC flower filter. Signed-off-by: Steen Hegelund --- .../microchip/sparx5/sparx5_tc_flower.c | 68 +++++++++++++++++++ .../net/ethernet/microchip/vcap/vcap_api.c | 25 +++++++ .../ethernet/microchip/vcap/vcap_api_client.h | 3 + 3 files changed, 96 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c index b76b8fc567bb..a48baeacc1d2 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c @@ -21,6 +21,11 @@ struct sparx5_tc_flower_parse_usage { unsigned int used_keys; }; +struct sparx5_tc_rule_pkt_cnt { + u64 cookie; + u32 pkts; +}; + /* These protocols have dedicated keysets in IS2 and a TC dissector * ETH_P_ARP does not have a TC dissector */ @@ -605,6 +610,20 @@ static int sparx5_tc_flower_action_check(struct vcap_control *vctrl, return 0; } +/* Add a rule counter action - only IS2 is considered for now */ +static int sparx5_tc_add_rule_counter(struct vcap_admin *admin, + struct vcap_rule *vrule) +{ + int err; + + err = vcap_rule_add_action_u32(vrule, VCAP_AF_CNT_ID, vrule->id); + if (err) + return err; + + vcap_rule_set_counter_id(vrule, vrule->id); + return err; +} + static int sparx5_tc_flower_replace(struct net_device *ndev, struct flow_cls_offload *fco, struct vcap_admin *admin) @@ -630,6 +649,11 @@ static int sparx5_tc_flower_replace(struct net_device *ndev, vrule->cookie = fco->cookie; sparx5_tc_use_dissectors(fco, admin, vrule, &l3_proto); + + err = sparx5_tc_add_rule_counter(admin, vrule); + if (err) + goto out; + frule = flow_cls_offload_flow_rule(fco); flow_action_for_each(idx, act, &frule->action) { switch (act->id) { @@ -708,6 +732,48 @@ static int sparx5_tc_flower_destroy(struct net_device *ndev, return err; } +/* Collect packet counts from all rules with the same cookie */ +static int sparx5_tc_rule_counter_cb(void *arg, struct vcap_rule *rule) +{ + struct sparx5_tc_rule_pkt_cnt *rinfo = arg; + struct vcap_counter counter; + int err = 0; + + if (rule->cookie == rinfo->cookie) { + err = vcap_rule_get_counter(rule, &counter); + if (err) + return err; + rinfo->pkts += counter.value; + /* Reset the rule counter */ + counter.value = 0; + vcap_rule_set_counter(rule, &counter); + } + return err; +} + +static int sparx5_tc_flower_stats(struct net_device *ndev, + struct flow_cls_offload *fco, + struct vcap_admin *admin) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5_tc_rule_pkt_cnt rinfo = {}; + struct vcap_control *vctrl; + ulong lastused = 0; + u64 drops = 0; + u32 pkts = 0; + int err; + + rinfo.cookie = fco->cookie; + vctrl = port->sparx5->vcap_ctrl; + err = vcap_rule_iter(vctrl, sparx5_tc_rule_counter_cb, &rinfo); + if (err) + return err; + pkts = rinfo.pkts; + flow_stats_update(&fco->stats, 0x0, pkts, drops, lastused, + FLOW_ACTION_HW_STATS_IMMEDIATE); + return err; +} + int sparx5_tc_flower(struct net_device *ndev, struct flow_cls_offload *fco, bool ingress) { @@ -729,6 +795,8 @@ int sparx5_tc_flower(struct net_device *ndev, struct flow_cls_offload *fco, return sparx5_tc_flower_replace(ndev, fco, admin); case FLOW_CLS_DESTROY: return sparx5_tc_flower_destroy(ndev, fco, admin); + case FLOW_CLS_STATS: + return sparx5_tc_flower_stats(ndev, fco, admin); default: return -EOPNOTSUPP; } diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 9c660e718526..d12c8ec40fe2 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1729,6 +1729,31 @@ void vcap_rule_set_counter_id(struct vcap_rule *rule, u32 counter_id) } EXPORT_SYMBOL_GPL(vcap_rule_set_counter_id); +/* Provide all rules via a callback interface */ +int vcap_rule_iter(struct vcap_control *vctrl, + int (*callback)(void *, struct vcap_rule *), void *arg) +{ + struct vcap_rule_internal *ri; + struct vcap_admin *admin; + int ret; + + ret = vcap_api_check(vctrl); + if (ret) + return ret; + + /* Iterate all rules in each VCAP instance */ + list_for_each_entry(admin, &vctrl->list, list) { + list_for_each_entry(ri, &admin->rules, list) { + ret = callback(arg, &ri->data); + if (ret) + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(vcap_rule_iter); + int vcap_rule_set_counter(struct vcap_rule *rule, struct vcap_counter *ctr) { struct vcap_rule_internal *ri = to_intrule(rule); diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h index c2655045d6d4..654ef8fa6d62 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_client.h +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_client.h @@ -210,6 +210,9 @@ const struct vcap_field *vcap_lookup_keyfield(struct vcap_rule *rule, int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie); /* Is the next chain id in the following lookup, possible in another VCAP */ bool vcap_is_next_lookup(struct vcap_control *vctrl, int cur_cid, int next_cid); +/* Provide all rules via a callback interface */ +int vcap_rule_iter(struct vcap_control *vctrl, + int (*callback)(void *, struct vcap_rule *), void *arg); /* Copy to host byte order */ void vcap_netbytes_copy(u8 *dst, u8 *src, int count);