Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1382730lqt; Sat, 20 Apr 2024 12:30:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSwtSFr+91v5nQM7L1IHVt91ihRVBqdK+rna4HWF2iCEDRpw8cIvsEmTBBmUlJbQDY5D60xnKY+2bAPwGacvHzAIT1knpt9gcUGFOoiw== X-Google-Smtp-Source: AGHT+IEpmzIJGWtHxqTZ0a0EHfDJJxSYm+rgyLh2YAeKkdkuIWKBefmnwW4mFc/wMi1MYUcA1a2L X-Received: by 2002:a17:902:dac8:b0:1e4:19e3:56cb with SMTP id q8-20020a170902dac800b001e419e356cbmr9430738plx.12.1713641446546; Sat, 20 Apr 2024 12:30:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713641446; cv=pass; d=google.com; s=arc-20160816; b=ebyEgfhsD0QHSwe2ZXPZutLB82+XMasGuE2XmuXbl7gp6tcjvT27Le7bS6EgfpJuBd PDGXR0nboMRHicOn7ilexzLAuZc4Xa2Wv2H4nSz0DySpCSNEt/I0fTezmbiZj+JQxmvN 7ULEqJNen7wK4Sc+7xetD5uhC2hW15HQCcAV1Iano0AQQnFkoeCaidBXtBhvrg6HVCQP gvnYFj1zhQexGV4UAMuDTb9pnz6PESfWf+iThYVvj4B/Jtt0zAO7Xs0I7FEr99b/Ot83 HyNq+m20BMwAj2UspnqbWbjBQuklYxLnaI78rJyc9VRAdsR0WMYQTN80JZTagLpvk8qE FMQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=pazu/To4mKx0Xk+n3XnkSCGQAVWAVmK3d0ocgPc8C8M=; fh=UQq7t8uvK2iUNO1MW2Ou8S2LAb+LVP9puPAKMbRd+Ns=; b=W+1ZZR2/0nt/sR/QTIsk7NQJ8Ca1czAMkLkJ15yA73VTgIhnKTKRR0RFf6yWs7lyu2 1d/EcmsD4dVEDT6EHGyfQeRetQxiSRnGy6qxXx3k1GUW72IBWVBgkTGzmled1pwmIUhD JtW0b4YOEw27Wjzwsv/8odD6X5sZPR5Gx3mH2buGSKYdtrVtIy4nF+3oIEhV37TC/X5D Uu8PK2tiQoNrtM+R1gt4cTIfNvBPQNdjoTTXz1YDCRGrT2kRAIugLpgtrIs87tvJ6XVR 70WPz2vqWNE5qURuEXBO6AUQqRSALFCp0qWiW+7v/h9NbGG2vSxv/x+0UN6h11WNnY8h WpMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=z11g4UwU; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-152362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s2-20020a170902ea0200b001e4b14b6a6dsi5315033plg.41.2024.04.20.12.30.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 12:30:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=z11g4UwU; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-152362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B1A6A281A01 for ; Sat, 20 Apr 2024 19:30:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 303214DA16; Sat, 20 Apr 2024 19:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="z11g4UwU" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B95C46441; Sat, 20 Apr 2024 19:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713641397; cv=none; b=g09CeIKGyB9nMckPF7l4sbF0J61PpZ8wSAIXD76PF0df2s0p8MAlZuu3dhDi6x1V6cnJG/HVIKdqYvBk824pNnX/kBO9D/e1X/q3UF9uY4NCjl3s4RBPvTDeMapSIjBcxPZCx/LvVr3W9hkOS0cM605zLOdCXyuC6Wv9/OzWvrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713641397; c=relaxed/simple; bh=FrLjMd7WgXxrkhcJPa3dqPPJxrUeznyOVxvRW+RY4K0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=NZDZDtDciIynBwo9pmmjUP6xfyD1oHYBDXU/ouu80cASiupfcFcrylTjO+dGtRj9uYV8lwrqcAZETc30vbAehQ92W9sC4sj+gjtyBiPZQHt1CMrN8sNTSjv4t7sawqSQiWvs2moANpXcRtRZTh+H7bbeV60DiT0r3Od8lBNuQZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=z11g4UwU; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1713641395; x=1745177395; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=FrLjMd7WgXxrkhcJPa3dqPPJxrUeznyOVxvRW+RY4K0=; b=z11g4UwUBnIShGtP0ylXb+c1HVm/zbKB8/fad1EDR1FTkhieahiOu1U8 u67se5tt4/iB9jeLny3mgsdJ5WnYzCsqDQhcLpfF+FbLkV6yJrDx6Q2p3 chGzXwkqEh9LhTNI0/0uL0VzgWZ4GuER2JRUiDu3KkqPji5MrCqN6J8de uy5QUrg+Ahkh3d+YpP89URSpJT8YcmlY/ut/njMCSR8hjoxwWmfvxraFP OoJTqyc3An0XqJAMGlfmeewJZI8zow5v2muyVvRMA9C6Nm9I3JQc0DCx4 KEfmtL7CgEckvvsbjV2TvEoCvlJhzBvUutKlhhmNpbpcSk5KOptPf9AEu g==; X-CSE-ConnectionGUID: r3PO+GVPQoGyYBK6996e2w== X-CSE-MsgGUID: JpnCkACNSVS4oSYVFiQsyw== X-IronPort-AV: E=Sophos;i="6.07,217,1708412400"; d="scan'208";a="22513533" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 20 Apr 2024 12:29:52 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) 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.35; Sat, 20 Apr 2024 12:29:37 -0700 Received: from DEN-DL-M70577.microchip.com (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Sat, 20 Apr 2024 12:29:33 -0700 From: Daniel Machon Date: Sat, 20 Apr 2024 21:29:14 +0200 Subject: [PATCH net-next v3 5/5] net: sparx5: add support for matchall mirror stats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240420-port-mirroring-v3-5-0fe3ac52006d@microchip.com> References: <20240420-port-mirroring-v3-0-0fe3ac52006d@microchip.com> In-Reply-To: <20240420-port-mirroring-v3-0-0fe3ac52006d@microchip.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Lars Povlsen , "Steen Hegelund" , , Russell King CC: , , , Horatiu Vultur , "Russell King (Oracle)" , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Vladimir Oltean , Yue Haibing , Daniel Machon X-Mailer: b4 0.14-dev Add support for tc matchall mirror stats. When a new matchall mirror rule is added, the baseline stats for that port is saved. Signed-off-by: Daniel Machon Reviewed-by: Steen Hegelund --- .../net/ethernet/microchip/sparx5/sparx5_main.h | 3 ++ .../net/ethernet/microchip/sparx5/sparx5_mirror.c | 37 ++++++++++++++++++++++ .../ethernet/microchip/sparx5/sparx5_tc_matchall.c | 27 ++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h index 5d026e1670f5..1982ae03b4fe 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.h +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.h @@ -174,6 +174,7 @@ struct sparx5_port { struct phylink_config phylink_config; struct phylink *phylink; struct phylink_pcs phylink_pcs; + struct flow_stats mirror_stats; u16 portno; /* Ingress default VLAN (pvid) */ u16 pvid; @@ -562,6 +563,8 @@ void sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time, /* sparx5_mirror.c */ int sparx5_mirror_add(struct sparx5_mall_entry *entry); void sparx5_mirror_del(struct sparx5_mall_entry *entry); +void sparx5_mirror_stats(struct sparx5_mall_entry *entry, + struct flow_stats *fstats); /* Clock period in picoseconds */ static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c index f029634a6a42..15db423be4aa 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c @@ -196,3 +196,40 @@ void sparx5_mirror_del(struct sparx5_mall_entry *entry) mirror_idx, SPX5_MIRROR_MONITOR_PORT_DEFAULT); } + +void sparx5_mirror_stats(struct sparx5_mall_entry *entry, + struct flow_stats *fstats) +{ + struct sparx5_port *port = entry->port; + struct rtnl_link_stats64 new_stats; + struct flow_stats *old_stats; + + old_stats = &entry->port->mirror_stats; + sparx5_get_stats64(port->ndev, &new_stats); + + if (entry->ingress) { + flow_stats_update(fstats, + new_stats.rx_bytes - old_stats->bytes, + new_stats.rx_packets - old_stats->pkts, + new_stats.rx_dropped - old_stats->drops, + old_stats->lastused, + FLOW_ACTION_HW_STATS_IMMEDIATE); + + old_stats->bytes = new_stats.rx_bytes; + old_stats->pkts = new_stats.rx_packets; + old_stats->drops = new_stats.rx_dropped; + old_stats->lastused = jiffies; + } else { + flow_stats_update(fstats, + new_stats.tx_bytes - old_stats->bytes, + new_stats.tx_packets - old_stats->pkts, + new_stats.tx_dropped - old_stats->drops, + old_stats->lastused, + FLOW_ACTION_HW_STATS_IMMEDIATE); + + old_stats->bytes = new_stats.tx_bytes; + old_stats->pkts = new_stats.tx_packets; + old_stats->drops = new_stats.tx_dropped; + old_stats->lastused = jiffies; + } +} diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c index 4f9ae026fa47..6b4d1d7b9730 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c @@ -96,6 +96,8 @@ static int sparx5_tc_matchall_replace(struct net_device *ndev, } return err; } + /* Get baseline stats for this port */ + sparx5_mirror_stats(mall_entry, &tmo->stats); break; case FLOW_ACTION_GOTO: err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, @@ -162,6 +164,29 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev, return err; } +static int sparx5_tc_matchall_stats(struct net_device *ndev, + struct tc_cls_matchall_offload *tmo, + bool ingress) +{ + struct sparx5_port *port = netdev_priv(ndev); + struct sparx5 *sparx5 = port->sparx5; + struct sparx5_mall_entry *entry; + + entry = sparx5_tc_matchall_entry_find(&sparx5->mall_entries, + tmo->cookie); + if (!entry) + return -ENOENT; + + if (entry->type == FLOW_ACTION_MIRRED) { + sparx5_mirror_stats(entry, &tmo->stats); + } else { + NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); + return -EOPNOTSUPP; + } + + return 0; +} + int sparx5_tc_matchall(struct net_device *ndev, struct tc_cls_matchall_offload *tmo, bool ingress) @@ -171,6 +196,8 @@ int sparx5_tc_matchall(struct net_device *ndev, return sparx5_tc_matchall_replace(ndev, tmo, ingress); case TC_CLSMATCHALL_DESTROY: return sparx5_tc_matchall_destroy(ndev, tmo, ingress); + case TC_CLSMATCHALL_STATS: + return sparx5_tc_matchall_stats(ndev, tmo, ingress); default: return -EOPNOTSUPP; } -- 2.34.1