Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp3848127rwb; Sun, 30 Jul 2023 18:04:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlHDXnYWSqU32AGkoss8hnYJMP9dxTrQTaE3cFV1Npv4979m57tQ+w61rdmmUBG7oHXq0Bdz X-Received: by 2002:a05:6a00:240e:b0:667:85e6:4d1 with SMTP id z14-20020a056a00240e00b0066785e604d1mr11079891pfh.33.1690765489612; Sun, 30 Jul 2023 18:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690765489; cv=none; d=google.com; s=arc-20160816; b=CVvMOGzXwYm6iRlYWTMZVbMYqFTaawO/D+PsnashNz7elnRfeQgLp+mPXxENLVUQ7C AAv4CIvLLUXzs0EKfIzRx4a7bETVXfRypuEOIwoe/mQXvWGcYsrCZM5vjsrnTHvgYb4D 2tEXAel5UtvmVlHB751pd52sCUSorlfR3RSEk2KQfD6svxQV7K1b4lgfb5/PS5dNe1XB l5GMbD6ffOPOo/uUrqW+I77I3oAJ5Lf3KWKDrF9jWGxsMDggseFqYvcugRIpxxpLE9jF zNXXC6cbdhxNZKoR3CyBN3MWg92vtKarTP+E5VAvOtNrH6Mgax+Y6hCToqbQnxHTnmHR 4XkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=EaqBMG6dhTRevszM9xr76lJpr9BL3nE/id+BIQHYhtc=; fh=TKNy1nH7zRYcLW2d6mSP8xWFq72ICqOKfDYOe2O7CQ4=; b=R7Fne6GW748kDirzhm6YjFS7Bkq2VydlP0JTOzDYD+QXHJEUItosRCS2Ate3CTBzg4 fedbu0UQ/9/J08vfAa8JvEgqlQejuIO0F7sxhU0HdK4V8VuHZDND8QoZTJqDdL5OMEsA UqKVVPCay6gyEaIG//GXDGsK3Ob8o9s+PKUekAitcISlG+q1KMDBgaWFwTflbmInjUug Y/YKw6BmDAS/x+m4D8ZQbVBs9AFV4ZSD1dAulMQcW4tIHuZ/MmUVaSwYXkbvoYb/Own9 V3RcMuK5Y9qIC73pZXjv5N7vTVMLpIkQccqHctDPH3a5LP8uGXRDvR6ffMQpk6U3hRP/ KKPQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a056a000acf00b0067a0b355523si6649830pfl.116.2023.07.30.18.04.32; Sun, 30 Jul 2023 18:04:49 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbjGaAZi (ORCPT + 99 others); Sun, 30 Jul 2023 20:25:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjGaAZh (ORCPT ); Sun, 30 Jul 2023 20:25:37 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73131A3; Sun, 30 Jul 2023 17:25:33 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qQGip-0005ue-2B; Mon, 31 Jul 2023 00:25:16 +0000 Date: Mon, 31 Jul 2023 01:24:22 +0100 From: Daniel Golle To: Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net-next v2] net: ethernet: mtk_eth_soc: support per-flow accounting on MT7988 Message-ID: <66032a4e2093ef82d2035966212c5a2ef2b6fdc9.1690762860.git.daniel@makrotopia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 NETSYS_V3 uses 64 bits for each counters while older SoCs were using 48 bits for each counter. Support reading per-flow byte and package counters on NETSYS_V3. Signed-off-by: Daniel Golle --- v2: fix typo bytes_cnt_* -> byte_cnt_* drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 + drivers/net/ethernet/mediatek/mtk_ppe.c | 18 ++++++++++++++---- drivers/net/ethernet/mediatek/mtk_ppe_regs.h | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 05be702f19c5e..1b89f800f6dff 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -5064,6 +5064,7 @@ static const struct mtk_soc_data mt7988_data = { .version = 3, .offload_version = 2, .hash_offset = 4, + .has_accounting = true, .foe_entry_size = MTK_FOE_ENTRY_V3_SIZE, .txrx = { .txd_size = sizeof(struct mtk_tx_dma_v2), diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c index bf1ecb0c1c109..dd2df32b29c3b 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c @@ -107,10 +107,20 @@ static int mtk_mib_entry_read(struct mtk_ppe *ppe, u16 index, u64 *bytes, u64 *p cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1); cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2); - byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0); - byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1); - pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1); - pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2); + if (mtk_is_netsys_v3_or_greater(ppe->eth)) { + /* 64 bit for each counter */ + byte_cnt_low = cnt_r0; + byte_cnt_high = cnt_r1; + pkt_cnt_low = cnt_r2; + pkt_cnt_high = readl(ppe->base + MTK_PPE_MIB_SER_R3); + } else { + /* 48 bit for each counter */ + byte_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R0_BYTE_CNT_LOW, cnt_r0); + byte_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R1_BYTE_CNT_HIGH, cnt_r1); + pkt_cnt_low = FIELD_GET(MTK_PPE_MIB_SER_R1_PKT_CNT_LOW, cnt_r1); + pkt_cnt_high = FIELD_GET(MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH, cnt_r2); + } + *bytes = ((u64)byte_cnt_high << 32) | byte_cnt_low; *packets = (pkt_cnt_high << 16) | pkt_cnt_low; diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h index a2e61b3eb006d..3ce088eef0efd 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe_regs.h +++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h @@ -163,6 +163,8 @@ enum { #define MTK_PPE_MIB_SER_R2 0x348 #define MTK_PPE_MIB_SER_R2_PKT_CNT_HIGH GENMASK(23, 0) +#define MTK_PPE_MIB_SER_R3 0x34c + #define MTK_PPE_MIB_CACHE_CTL 0x350 #define MTK_PPE_MIB_CACHE_CTL_EN BIT(0) #define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2) -- 2.41.0