From patchwork Thu Jul 13 22:19:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13312688 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 14A3E2418D for ; Thu, 13 Jul 2023 22:20:10 +0000 (UTC) Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850B735A9 for ; Thu, 13 Jul 2023 15:19:39 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6378cec43ddso7168296d6.2 for ; Thu, 13 Jul 2023 15:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1689286774; x=1691878774; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=Kej39783NiqpxOu+JeaKHNGom0P3VxcHyTER3AtQhw4=; b=Wvc4wX7RJ+sCmH/PfajKVWc7cAVcTpfEbviAKCOw6DItH+//gCyA1sQSF/bDlvSLXz c/qHLfq5oGKNb6SSXpIZZcn627tlFrx5IjbXYYm0EbaRlX5ugfvlfINNZAJTu5KV7NbJ 1Vli9WcbudEaC+g+aTQa3ttFWym/SNp3G42Hg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689286774; x=1691878774; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Kej39783NiqpxOu+JeaKHNGom0P3VxcHyTER3AtQhw4=; b=XCiBQOncvmDsOhpG4J2gqky8iNZXsh+iOzN1rWEAfseOhBkJ6qih8wb3k5l8OjZcIp CC0PaHmQ5Av0fLtXiR0aFsdapc2d9wLnNQYbC7DwsE7v+zu3+qaJq6owS7hyCu9ElHKn cOeBvfNNAkBnqY0G75aV8wIyOqC3HeiZ6irWR6G7vT2gIxoes6M5oedKFyO5/JB0Upst 6QYgId0GY/zFDojMxGYWgbhQ9pYg9bjefYpPqbRZ2g6cMLy+2D57cZ/wZ4pn7IBPSY89 GcAyUsDfVBiWTi3ZBt8p6wqFP+bl+8Jhb5whmz/KgFQBKPuv4klniIFtrrz7WoiIR1k0 RMog== X-Gm-Message-State: ABy/qLbWDPVdM6trAb0YC72RlJDdoWNRWUygdH9oXy0n36Kk2KvjMelh x8gKdzGKCOWe3iUlC7RhY1ZDu0cZb0ALiBN8aOKGzfozt0+V2h+07G33WvUzCvdUmEdQqYPQXmO uIsRldem/iWg3eCUPdb03KzBSMZWZBUx4EV93ZB6FkpOXvQualvdMgW8+Fy9C3Q5BNm6vMepZpF ftPsN6SuRi X-Google-Smtp-Source: APBJJlHbdFK+xblDJeeKeCHfDtz7gF3ItA55uYsh9Em++8uNsRXrmat//0VkSWrzyBSj0WruH+55BQ== X-Received: by 2002:a05:6214:5146:b0:635:4113:bb07 with SMTP id kh6-20020a056214514600b006354113bb07mr2538292qvb.16.1689286774494; Thu, 13 Jul 2023 15:19:34 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id i14-20020a0cf38e000000b006262de12a8csm427623qvk.65.2023.07.13.15.19.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2023 15:19:34 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, bcm-kernel-feedback-list@broadcom.com Cc: florian.fainelli@broadcom.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, opendmb@gmail.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com, sumit.semwal@linaro.org, simon.horman@corigine.com, christian.koenig@amd.com, Justin Chen Subject: [net-next v9 08/11] net: bcmasp: Add support for ethtool driver stats Date: Thu, 13 Jul 2023 15:19:03 -0700 Message-Id: <1689286746-43609-9-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1689286746-43609-1-git-send-email-justin.chen@broadcom.com> References: <1689286746-43609-1-git-send-email-justin.chen@broadcom.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_HEADER_CTYPE_ONLY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS 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 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org Add support for ethernet driver specific stats. Signed-off-by: Justin Chen --- v9 - Removed tx_realloc_offload, this stat is no longer relevant with skb_cow_head(). - Added tx_timeout_cnt v8 - Address maybe uninit variable warning drivers/net/ethernet/broadcom/asp2/bcmasp.c | 4 +- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 21 +++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 160 +++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 18 ++- 4 files changed, 199 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c index 92dfea961add..a9984efff6d1 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c @@ -895,8 +895,10 @@ int bcmasp_set_en_mda_filter(struct bcmasp_intf *intf, unsigned char *addr, /* Attempt to combine filters */ ret = bcmasp_combine_set_filter(intf, addr, mask, i); - if (!ret) + if (!ret) { + intf->mib.filters_combine_cnt++; return 0; + } } /* Create new filter if possible */ diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h index 18a44044ad93..6bfcaa7f95a8 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h @@ -244,6 +244,26 @@ struct bcmasp_intf_stats64 { struct u64_stats_sync syncp; }; +struct bcmasp_mib_counters { + u32 edpkt_ts; + u32 edpkt_rx_pkt_cnt; + u32 edpkt_hdr_ext_cnt; + u32 edpkt_hdr_out_cnt; + u32 umac_frm_cnt; + u32 fb_frm_cnt; + u32 fb_rx_fifo_depth; + u32 fb_out_frm_cnt; + u32 fb_filt_out_frm_cnt; + u32 alloc_rx_skb_failed; + u32 tx_dma_failed; + u32 mc_filters_full_cnt; + u32 uc_filters_full_cnt; + u32 filters_combine_cnt; + u32 promisc_filters_cnt; + u32 tx_realloc_offload_failed; + u32 tx_timeout_cnt; +}; + struct bcmasp_intf_ops { unsigned long (*rx_desc_read)(struct bcmasp_intf *intf); void (*rx_buffer_write)(struct bcmasp_intf *intf, dma_addr_t addr); @@ -309,6 +329,7 @@ struct bcmasp_intf { /* Statistics */ struct bcmasp_intf_stats64 stats64; + struct bcmasp_mib_counters mib; u32 wolopts; u8 sopass[SOPASS_MAX]; diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c index 59d853c2293c..c4f1604d5ab3 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #define pr_fmt(fmt) "bcmasp_ethtool: " fmt +#include #include #include #include @@ -8,6 +9,162 @@ #include "bcmasp.h" #include "bcmasp_intf_defs.h" +enum bcmasp_stat_type { + BCMASP_STAT_RX_EDPKT, + BCMASP_STAT_RX_CTRL, + BCMASP_STAT_RX_CTRL_PER_INTF, + BCMASP_STAT_SOFT, +}; + +struct bcmasp_stats { + char stat_string[ETH_GSTRING_LEN]; + enum bcmasp_stat_type type; + u32 reg_offset; +}; + +#define STAT_BCMASP_SOFT_MIB(str) { \ + .stat_string = str, \ + .type = BCMASP_STAT_SOFT, \ +} + +#define STAT_BCMASP_OFFSET(str, _type, offset) { \ + .stat_string = str, \ + .type = _type, \ + .reg_offset = offset, \ +} + +#define STAT_BCMASP_RX_EDPKT(str, offset) \ + STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_EDPKT, offset) +#define STAT_BCMASP_RX_CTRL(str, offset) \ + STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL, offset) +#define STAT_BCMASP_RX_CTRL_PER_INTF(str, offset) \ + STAT_BCMASP_OFFSET(str, BCMASP_STAT_RX_CTRL_PER_INTF, offset) + +/* Must match the order of struct bcmasp_mib_counters */ +static const struct bcmasp_stats bcmasp_gstrings_stats[] = { + /* EDPKT counters */ + STAT_BCMASP_RX_EDPKT("RX Time Stamp", ASP_EDPKT_RX_TS_COUNTER), + STAT_BCMASP_RX_EDPKT("RX PKT Count", ASP_EDPKT_RX_PKT_CNT), + STAT_BCMASP_RX_EDPKT("RX PKT Buffered", ASP_EDPKT_HDR_EXTR_CNT), + STAT_BCMASP_RX_EDPKT("RX PKT Pushed to DRAM", ASP_EDPKT_HDR_OUT_CNT), + /* ASP RX control */ + STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Unimac", + ASP_RX_CTRL_UMAC_0_FRAME_COUNT), + STAT_BCMASP_RX_CTRL_PER_INTF("Frames From Port", + ASP_RX_CTRL_FB_0_FRAME_COUNT), + STAT_BCMASP_RX_CTRL_PER_INTF("RX Buffer FIFO Depth", + ASP_RX_CTRL_FB_RX_FIFO_DEPTH), + STAT_BCMASP_RX_CTRL("Frames Out(Buffer)", + ASP_RX_CTRL_FB_OUT_FRAME_COUNT), + STAT_BCMASP_RX_CTRL("Frames Out(Filters)", + ASP_RX_CTRL_FB_FILT_OUT_FRAME_COUNT), + /* Software maintained statistics */ + STAT_BCMASP_SOFT_MIB("RX SKB Alloc Failed"), + STAT_BCMASP_SOFT_MIB("TX DMA Failed"), + STAT_BCMASP_SOFT_MIB("Multicast Filters Full"), + STAT_BCMASP_SOFT_MIB("Unicast Filters Full"), + STAT_BCMASP_SOFT_MIB("MDA Filters Combined"), + STAT_BCMASP_SOFT_MIB("Promisc Filter Set"), + STAT_BCMASP_SOFT_MIB("TX Realloc For Offload Failed"), + STAT_BCMASP_SOFT_MIB("Tx Timeout Count"), +}; + +#define BCMASP_STATS_LEN ARRAY_SIZE(bcmasp_gstrings_stats) + +static u16 bcmasp_stat_fixup_offset(struct bcmasp_intf *intf, + const struct bcmasp_stats *s) +{ + struct bcmasp_priv *priv = intf->parent; + + if (!strcmp("Frames Out(Buffer)", s->stat_string)) + return priv->hw_info->rx_ctrl_fb_out_frame_count; + + if (!strcmp("Frames Out(Filters)", s->stat_string)) + return priv->hw_info->rx_ctrl_fb_filt_out_frame_count; + + if (!strcmp("RX Buffer FIFO Depth", s->stat_string)) + return priv->hw_info->rx_ctrl_fb_rx_fifo_depth; + + return s->reg_offset; +} + +static int bcmasp_get_sset_count(struct net_device *dev, int string_set) +{ + switch (string_set) { + case ETH_SS_STATS: + return BCMASP_STATS_LEN; + default: + return -EOPNOTSUPP; + } +} + +static void bcmasp_get_strings(struct net_device *dev, u32 stringset, + u8 *data) +{ + unsigned int i; + + switch (stringset) { + case ETH_SS_STATS: + for (i = 0; i < BCMASP_STATS_LEN; i++) { + memcpy(data + i * ETH_GSTRING_LEN, + bcmasp_gstrings_stats[i].stat_string, + ETH_GSTRING_LEN); + } + break; + default: + return; + } +} + +static void bcmasp_update_mib_counters(struct bcmasp_intf *intf) +{ + unsigned int i; + + for (i = 0; i < BCMASP_STATS_LEN; i++) { + const struct bcmasp_stats *s; + u32 offset, val; + char *p; + + s = &bcmasp_gstrings_stats[i]; + offset = bcmasp_stat_fixup_offset(intf, s); + switch (s->type) { + case BCMASP_STAT_SOFT: + continue; + case BCMASP_STAT_RX_EDPKT: + val = rx_edpkt_core_rl(intf->parent, offset); + break; + case BCMASP_STAT_RX_CTRL: + val = rx_ctrl_core_rl(intf->parent, offset); + break; + case BCMASP_STAT_RX_CTRL_PER_INTF: + offset += sizeof(u32) * intf->port; + val = rx_ctrl_core_rl(intf->parent, offset); + break; + default: + continue; + } + p = (char *)(&intf->mib) + (i * sizeof(u32)); + put_unaligned(val, (u32 *)p); + } +} + +static void bcmasp_get_ethtool_stats(struct net_device *dev, + struct ethtool_stats *stats, + u64 *data) +{ + struct bcmasp_intf *intf = netdev_priv(dev); + unsigned int i; + char *p; + + if (netif_running(dev)) + bcmasp_update_mib_counters(intf); + + for (i = 0; i < BCMASP_STATS_LEN; i++) { + p = (char *)(&intf->mib) + (i * sizeof(u32)); + data[i] = *(u32 *)p; + } +} + static void bcmasp_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) { @@ -340,4 +497,7 @@ const struct ethtool_ops bcmasp_ethtool_ops = { .get_eth_mac_stats = bcmasp_get_eth_mac_stats, .get_rmon_stats = bcmasp_get_rmon_stats, .get_eth_ctrl_stats = bcmasp_get_eth_ctrl_stats, + .get_strings = bcmasp_get_strings, + .get_ethtool_stats = bcmasp_get_ethtool_stats, + .get_sset_count = bcmasp_get_sset_count, }; diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index 051f882b2766..53e542881255 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -104,15 +104,19 @@ static void bcmasp_set_rx_mode(struct net_device *dev) netdev_for_each_mc_addr(ha, dev) { ret = bcmasp_set_en_mda_filter(intf, ha->addr, mask); - if (ret) + if (ret) { + intf->mib.mc_filters_full_cnt++; goto set_promisc; + } } } netdev_for_each_uc_addr(ha, dev) { ret = bcmasp_set_en_mda_filter(intf, ha->addr, mask); - if (ret) + if (ret) { + intf->mib.uc_filters_full_cnt++; goto set_promisc; + } } spin_unlock_bh(&intf->parent->mda_lock); @@ -120,6 +124,7 @@ static void bcmasp_set_rx_mode(struct net_device *dev) set_promisc: bcmasp_set_promisc(intf, 1); + intf->mib.promisc_filters_cnt++; /* disable all filters used by this port */ bcmasp_disable_all_filters(intf); @@ -155,6 +160,7 @@ static struct sk_buff *bcmasp_csum_offload(struct net_device *dev, struct sk_buff *skb, bool *csum_hw) { + struct bcmasp_intf *intf = netdev_priv(dev); u32 header = 0, header2 = 0, epkt = 0; struct bcmasp_pkt_offload *offload; unsigned int header_cnt = 0; @@ -165,8 +171,10 @@ static struct sk_buff *bcmasp_csum_offload(struct net_device *dev, return skb; ret = skb_cow_head(skb, sizeof(*offload)); - if (ret < 0) + if (ret < 0) { + intf->mib.tx_realloc_offload_failed++; goto help; + } switch (skb->protocol) { case htons(ETH_P_IP): @@ -305,6 +313,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) } if (dma_mapping_error(kdev, mapping)) { + intf->mib.tx_dma_failed++; spb_index = intf->tx_spb_index; for (j = 0; j < i; j++) { bcmasp_clean_txcb(intf, spb_index); @@ -541,6 +550,8 @@ static int bcmasp_rx_poll(struct napi_struct *napi, int budget) u64_stats_update_begin(&stats->syncp); u64_stats_inc(&stats->rx_dropped); u64_stats_update_end(&stats->syncp); + intf->mib.alloc_rx_skb_failed++; + goto next; } @@ -1116,6 +1127,7 @@ static void bcmasp_tx_timeout(struct net_device *dev, unsigned int txqueue) struct bcmasp_intf *intf = netdev_priv(dev); netif_dbg(intf, tx_err, dev, "transmit timeout!\n"); + intf->mib.tx_timeout_cnt++; } static int bcmasp_get_phys_port_name(struct net_device *dev,