Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1139107lqb; Thu, 18 Apr 2024 00:50:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV44yqtKc1DARI5i1y5MJnab0TyclSqMV3/+k4Llm9D6gO2mbUAjyDOFayM1slP1LwlX7Czy2a4T6O01oUSqZKTzw44LZhoB9t0nJ7H2w== X-Google-Smtp-Source: AGHT+IH9lj5a2hovVBGSW9ssc6RGeKipEEBub8aJuPHCndiGyn/bd7jsSmtmKP/DbbHKb4ZzK5mc X-Received: by 2002:a05:620a:4155:b0:78e:ba10:d445 with SMTP id k21-20020a05620a415500b0078eba10d445mr2359546qko.34.1713426637952; Thu, 18 Apr 2024 00:50:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713426637; cv=pass; d=google.com; s=arc-20160816; b=eC82cVZTKPzRL6ezIZUeJZtStOoIooh6YST/mbfH069+05r09s/T9o57Gm15vnbTz5 M7neDEXvsF46pRZ9N2vDZeKC0UAd15OjlZBE6BMqkpl0a0vHWCggznIfGMb8pfHYfalp qlrI/2gQpe9OL36CmcRdyYp/P+W4xeopKnu22A12+0NtG8WmylW76uagzGbcsGFTN8I+ /gdKDUJ8za5zJNgfEBIWvw1wA2bALCuyBIXZuX1qEoV2l5XBoQD6zYecb9oT5nEbnaFg PgwzqMBRZEbpJmr4YtkUboZpsQYYik0s/xVyno7hvWa+0jzBq4fbtu1BE9Idlx4oB6+3 /IBw== 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=dINELhHXctihUGHRg/OuYTnoFjuk2jBVsW8dfyqtc60=; fh=UQq7t8uvK2iUNO1MW2Ou8S2LAb+LVP9puPAKMbRd+Ns=; b=FcyWQItFRko4Pj9fRLZmr5OzRJbkBwP72S73c+vIcJMUgHQij3jfE1N68dKLGwe9ZJ Dk55kqNI+pwScgpLsEE5J3FllOzQD2KHeHdyAjXsL1O+866A0Ze+uaK+6CY85wiD25Ix lPn9OVWEU6y7qneDFxfy8MR8Xfl7g4GqJbXS5QNFgquRtifcD1yRHptuXVfMpXABvuxC 2FeZ8m5jwPIw+t6uOEZ24phBrsjNrgZT+lblBQsTLS7c8xQtgUQLZu9oxEZ5XuQJrwQS w/NOyy60ORlUQ80DypQlsx9tjJ3S5jxClFIFNzAtlzjfuZIORif3GQznkNrnOnCJ/GNO 3HQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=T1vF3yi3; 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-149676-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149676-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p25-20020a05620a22b900b0078f045012ecsi929368qkh.423.2024.04.18.00.50.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 00:50:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149676-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=T1vF3yi3; 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-149676-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149676-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D42E1C21917 for ; Thu, 18 Apr 2024 07:50:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C30F97C6E3; Thu, 18 Apr 2024 07:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="T1vF3yi3" 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 556A27BB11; Thu, 18 Apr 2024 07:49:56 +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=1713426597; cv=none; b=DErEMfwtSt+AHetPGz1dAcpWMjVGrqQVBAEQqb70Cpu9nhpWV/9IQBlxe7R6JzNFPaH+Y21kzZKA/FfU1YQiGVvI/vXeJ5tCcdDhvbYstrKf7b70mXnVhz9BGs71bnjKeNa7oDIHpxqMAzpzuL2MQhAejDEXEnypAj7KwxiKrkM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713426597; c=relaxed/simple; bh=IhMFtZeQ2T2+WCiGXjtJeBAgi0XYTiLU3yPN8WN07Wg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=QTWWQqovD70GUGsFx8H//r0vgZS/YKBQa+F6rEfowA54HLkg7XQ8931a9iLzrK9fbF+4TShAPnbI2pdHGfNdIiAIFGIkYR/4hdxcQzwb76GTY6kTMtrzIa+ctmzARhCMiU+o2eQsN6c7iGwLDaySVUpp1Y/CR9B+WVoQQBKpxz4= 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=T1vF3yi3; 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=1713426596; x=1744962596; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=IhMFtZeQ2T2+WCiGXjtJeBAgi0XYTiLU3yPN8WN07Wg=; b=T1vF3yi3ReKjJq8GZj23Cq4yyEl3IFBLjWkOCk5CSUsUpfSbP9CvCZfr M5fSpxc4R2iG34URavVaM8aPGT1eSRwysfyX8msCQDcLxxHVpRuFPkzAw I9lp2nCaeRW3ZRZFR01Cq2sy0DgybywM4OXhU2fg+bOwW1mYbfGAycp8D r70k2MWoqtBRUicRu19Fd2Q0n1KQILH/hzBPxIQZUoN19w8JB9HE/vUSW Oano0HJ0fLC4qQ9V85unfgENUtZnnK2J+WNUJg3Wg+HOBxa1l00ELmbT2 Vq5/obBKFr3z7U7bLmzWu2LznB8RrJk55MXZ6QM7N81/ChP6bLe/mbPFo w==; X-CSE-ConnectionGUID: NQdi2Z4DREu4zFI25zkCMA== X-CSE-MsgGUID: Vgijnv27TKmLwt6m/MRV/Q== X-IronPort-AV: E=Sophos;i="6.07,211,1708412400"; d="scan'208";a="21570496" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 18 Apr 2024 00:49:55 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) 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 00:49:47 -0700 Received: from DEN-DL-M70577.microchip.com (10.10.85.11) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 18 Apr 2024 00:49:44 -0700 From: Daniel Machon Date: Thu, 18 Apr 2024 09:49:04 +0200 Subject: [PATCH net-next 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-v1-5-e05c35007c55@microchip.com> References: <20240418-port-mirroring-v1-0-e05c35007c55@microchip.com> In-Reply-To: <20240418-port-mirroring-v1-0-e05c35007c55@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 cfd6fcd3d74e..479f9b163533 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