Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp119470lqt; Thu, 18 Apr 2024 09:58:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWg0BTmMJDBoKs075zCOGTNZkg3FK6gUdSAb89eIsEcdHIwVwBFWtq52JcvwToD9d9vAzewx8M+qYugp3InDM09rsjYwHJNy8M3E1SytA== X-Google-Smtp-Source: AGHT+IGJHQ7fIMHN/bw4W/IVzklIGxdBcXh3xV+Jj/OHzxUnoR0glmKAgIlYGKe7qh6r1tUB/lc+ X-Received: by 2002:a50:d78a:0:b0:565:6c72:40a9 with SMTP id w10-20020a50d78a000000b005656c7240a9mr2192721edi.28.1713459531473; Thu, 18 Apr 2024 09:58:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713459531; cv=pass; d=google.com; s=arc-20160816; b=JzBSS08uHjvfHvPerTBW93ybw+IjKglEqGKBgwwGmZ5TvOTenpFQQmiPYsd31zbDNx TXmYsnOTBL9wGDbrW6dw4fmNM4Ge+433velRLlC/vwDJ8iRQHybJyE+wKZux2YSy94EP T+I5k94kTUuCMd0Er/LjePuyXng7PM7vt5dain/IQjyWOU5XqUV4yvgptDDG31A1EgsN vfKVfhZVsK1JybDbk/og9PGYjeURyF3zLf8wEbkbCyB9sLxZaNjLZo4E1zNBXoLqMWlR B84Hd1X+m8YBDEUWg2tfW5flAJwAji8mKs0zDeKT7OzHWkPb+bcpcg0ODS1JhfZf3GyC QRQg== 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=1Xgb6UQccxIlmVJx4I02AA9Xojv0ofZRYzNU/8fsEW4=; fh=UQq7t8uvK2iUNO1MW2Ou8S2LAb+LVP9puPAKMbRd+Ns=; b=aYl7yfwtvnpYgEnMoDXwvCV+v4NZkEm2AHdxmnqWvTfPXmXcUv5ld2ZzAX0TUmBWos YQcja574N0uyNSRMd0OacRtRi5Szj5IkGjXWeKm1wkg5m5/tdpmIn6mxbyrprEWYHRRq lZZiYwFiINPcbyqzS8YF2zhoCsEwVgc1xJHedAvCyn3eGE+v1gNl1/waggV3yKpid1TN DlBSEQGvMqAOnYXW6zMlGVoRpSnBCB3zwaGFQlw3qCQ0Gu12OeiLzDWTVU3MJxvzCOG7 lkcr5toeLtcAP3KQrpdvyglmZXyszgOkw5wdyAW+/vR9Kir3r0AIjJeKDhJ7ux4lXr71 Nadw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=yoDNJb9I; 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-150526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f1-20020aa7d841000000b0056df50f2746si1082030eds.408.2024.04.18.09.58.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 09:58:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=yoDNJb9I; 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-150526-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150526-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B44E11F221CC for ; Thu, 18 Apr 2024 16:58:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A104017A930; Thu, 18 Apr 2024 16:57:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="yoDNJb9I" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (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 E83B1171E48; Thu, 18 Apr 2024 16:57:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459454; cv=none; b=J0L5RkKNjUhvPpp9fYmEGYlQKlArW8T8YspHChFJCsU3TTg1vXzecrPBQ3uhIPKuwBJcaF5Y4Q5Tp5RgX8JPWvFSNVEvgolGzO5l/8m29H3wG86jyDsMYDtJmUc5D967c5lAFFgWrSXPBbziB2MUd/YB/DQbFXUb5jXc2vqiHqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459454; c=relaxed/simple; bh=z/xAOaDTmqkvVk/hZsD+Z4/Wx9LHmhiX52IaR6bPDLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Jy6NK2mFAH9F6ZBfI621RBiQaSCSyOwnMmqaQ4Lyko/82WlnTFX1BYfem+ub5LCtjD5V8NQqYf9hU7rpdFZ+WvwjmLFVb6qRbJCKaW6nr6hsIGZrFXmDzNmFoUe4ZbRJhzV30NGWNoADii6VJ4zLswHlUzpAuaNuI89enCvwu+w= 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=yoDNJb9I; arc=none smtp.client-ip=68.232.153.233 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=1713459453; x=1744995453; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=z/xAOaDTmqkvVk/hZsD+Z4/Wx9LHmhiX52IaR6bPDLE=; b=yoDNJb9InCIx/9+9z5q6JN/EGdWtzuF/M5Be8SIO/dQh3xoxs7QMtDc5 xeGCzd4a9B31M55fRi8VM231SIfuSJULS51yDbNAXrAG0/AbThiWok/Nq 9lsXFlu6fjUlfoSzje3Xl7EoBvoYQY360WlfJp2CGnreTIO/6cHhw0edG NxUCVvvaYp1Nolvi5jYJlkFlb3Jd3Tyn79dx7e4ItDeNbu0prCkc0eBIJ 2KUn768ZDUNnZozaj1LZS9hbYzPjOraFP2+4TJbVrgfK68vOqH3jDltzO ohPXNfAakqaliqoQrYXliBEWJKuR/NitUdPVj7q0SpzgMfJlp6fQiz8Mv A==; X-CSE-ConnectionGUID: knOBDkbjTBmC3G9PZhVd9w== X-CSE-MsgGUID: RZfgzYGfTOGkmiP2urrtkQ== X-IronPort-AV: E=Sophos;i="6.07,212,1708412400"; d="scan'208";a="252441394" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Apr 2024 09:57:31 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) 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; Thu, 18 Apr 2024 09:57:01 -0700 Received: from DEN-DL-M70577.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 18 Apr 2024 09:56:58 -0700 From: Daniel Machon Date: Thu, 18 Apr 2024 18:56:38 +0200 Subject: [PATCH net-next v2 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: <20240418-port-mirroring-v2-5-20642868b386@microchip.com> References: <20240418-port-mirroring-v2-0-20642868b386@microchip.com> In-Reply-To: <20240418-port-mirroring-v2-0-20642868b386@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 540bde15eeff..9dcc3c22fe49 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mirror.c @@ -194,3 +194,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