From patchwork Fri Dec 1 12:58:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13475779 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="EJSILsgR" Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465CF10F3 for ; Fri, 1 Dec 2023 04:58:49 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c9b5b72983so27925531fa.2 for ; Fri, 01 Dec 2023 04:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701435527; x=1702040327; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=W20/R/2/lPxahq8QRbTSIQuYC5cfYA58c59XK3Afbak=; b=EJSILsgRJCPpsp69uhLI/ahqhBRGvrvjMVfjS3lbdCCl2qP6m0u9J55YkVKg4AQudl nCYDYMR9eDZujYKQdr8iVH/7RSV5FcdPe6uZDYvVuhJ45E63aO45F0L4gsDkmW2D0i0C FIZyBQkqDn/4LHdIlOdX8EG6tm90g7AbxE13dAYVJprZ6aYiDD4rIMBd8gI/ldbC+bRL Px2hu1mL5vDTD3n734m6/E2/D+lwfIDY0IwbsDLRkTrRZ3HOXab4p6efg/8v1NZiFcCc TTF/GX/xHgKLhl8v6GbwG191Sm7S31NwpPu847q/BZN37pcMp2896Mp2polw9pIuXDHI c1fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435527; x=1702040327; h=content-transfer-encoding:organization:mime-version: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=W20/R/2/lPxahq8QRbTSIQuYC5cfYA58c59XK3Afbak=; b=TH0BrlR3wA6pXcOhf6gAVF4C8Wtf7BzZsASopl0UA1kJmkPAdvMMlFtkw2m2YJM08o V8K+QuafmDkk9BlrPupJpYV2fE/ZMrrQWB2vRKCwroUzikTZWch5YpsWCYUL/4i2dZdF nql6jZ86e60LliLIUdpfqcPwuGFPvfFEeR8UJIRY9RfujAInBi6symdzoDAT6/nnGPGg slgi9/Hjt3VrXlxTeg27lwxxyrWI9Ey0LbOmdcmkr3H9HYzRftE8Cg938M/uY4QOaT/3 wit/vzl4bNJID777KRTI1ZafwYf9/5f7PUgtA7XkHoblNGJUIsHCFDXWZfsuKBzjccsN KkMA== X-Gm-Message-State: AOJu0YzHlyAwLY+a7TVbrOMVnvuL56nlG2nadancdDY1KzEJG8W4UfPS hMlOep0c3RXcyrtHd16qBJnRIA== X-Google-Smtp-Source: AGHT+IEJSH9H45M/LqcBB65V8y60blxmvxT+cn2BuOj+blZ8mU4i28smSH4eYN0SG21SPRTKI+WZ4w== X-Received: by 2002:a2e:b0e4:0:b0:2c9:d863:2c3c with SMTP id h4-20020a2eb0e4000000b002c9d8632c3cmr763302ljl.101.1701435527381; Fri, 01 Dec 2023 04:58:47 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id z13-20020a05651c11cd00b002c02b36d381sm417036ljo.88.2023.12.01.04.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:58:46 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 1/4] net: dsa: mv88e6xxx: Create API to read a single stat counter Date: Fri, 1 Dec 2023 13:58:09 +0100 Message-Id: <20231201125812.1052078-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201125812.1052078-1-tobias@waldekranz.com> References: <20231201125812.1052078-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org This change contains no functional change. We simply push the hardware specific stats logic to a function reading a single counter, rather than the whole set. This is a preparatory change for the upcoming standard ethtool statistics support (i.e. "eth-mac", "eth-ctrl" etc.). Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 160 ++++++++++++++++++------------- drivers/net/dsa/mv88e6xxx/chip.h | 27 +++--- 2 files changed, 105 insertions(+), 82 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 42b1acaca33a..ffd81174bda3 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1000,7 +1000,7 @@ static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { }; static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip, - struct mv88e6xxx_hw_stat *s, + const struct mv88e6xxx_hw_stat *s, int port, u16 bank1_select, u16 histogram) { @@ -1183,59 +1183,82 @@ static int mv88e6xxx_get_sset_count(struct dsa_switch *ds, int port, int sset) return count; } -static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, - uint64_t *data, int types, - u16 bank1_select, u16 histogram) +static int mv88e6095_stats_get_stat(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data) { - struct mv88e6xxx_hw_stat *stat; - int i, j; + if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_PORT))) + return 0; - for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { - stat = &mv88e6xxx_hw_stats[i]; - if (stat->type & types) { - mv88e6xxx_reg_lock(chip); - data[j] = _mv88e6xxx_get_ethtool_stat(chip, stat, port, - bank1_select, - histogram); - mv88e6xxx_reg_unlock(chip); + *data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, 0, + MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + return 1; +} - j++; - } - } - return j; +static int mv88e6250_stats_get_stat(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data) +{ + if (!(stat->type & STATS_TYPE_BANK0)) + return 0; + + *data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, 0, + MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + return 1; } -static int mv88e6095_stats_get_stats(struct mv88e6xxx_chip *chip, int port, - uint64_t *data) +static int mv88e6320_stats_get_stat(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data) { - return mv88e6xxx_stats_get_stats(chip, port, data, - STATS_TYPE_BANK0 | STATS_TYPE_PORT, - 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_BANK1))) + return 0; + + *data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, + MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9, + MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + return 1; } -static int mv88e6250_stats_get_stats(struct mv88e6xxx_chip *chip, int port, - uint64_t *data) +static int mv88e6390_stats_get_stat(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data) { - return mv88e6xxx_stats_get_stats(chip, port, data, STATS_TYPE_BANK0, - 0, MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + if (!(stat->type & (STATS_TYPE_BANK0 | STATS_TYPE_BANK1))) + return 0; + + *data = _mv88e6xxx_get_ethtool_stat(chip, stat, port, + MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10, + 0); + return 1; } -static int mv88e6320_stats_get_stats(struct mv88e6xxx_chip *chip, int port, - uint64_t *data) +static int mv88e6xxx_stats_get_stat(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data) { - return mv88e6xxx_stats_get_stats(chip, port, data, - STATS_TYPE_BANK0 | STATS_TYPE_BANK1, - MV88E6XXX_G1_STATS_OP_BANK_1_BIT_9, - MV88E6XXX_G1_STATS_OP_HIST_RX_TX); + int ret = 0; + + if (chip->info->ops->stats_get_stat) { + mv88e6xxx_reg_lock(chip); + ret = chip->info->ops->stats_get_stat(chip, port, stat, data); + mv88e6xxx_reg_unlock(chip); + } + + return ret; } -static int mv88e6390_stats_get_stats(struct mv88e6xxx_chip *chip, int port, +static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, uint64_t *data) { - return mv88e6xxx_stats_get_stats(chip, port, data, - STATS_TYPE_BANK0 | STATS_TYPE_BANK1, - MV88E6XXX_G1_STATS_OP_BANK_1_BIT_10, - 0); + struct mv88e6xxx_hw_stat *stat; + int i, j; + + for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { + stat = &mv88e6xxx_hw_stats[i]; + j += mv88e6xxx_stats_get_stat(chip, port, stat, &data[j]); + } + return j; } static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port, @@ -1251,10 +1274,9 @@ static void mv88e6xxx_atu_vtu_get_stats(struct mv88e6xxx_chip *chip, int port, static void mv88e6xxx_get_stats(struct mv88e6xxx_chip *chip, int port, uint64_t *data) { - int count = 0; + int count; - if (chip->info->ops->stats_get_stats) - count = chip->info->ops->stats_get_stats(chip, port, data); + count = mv88e6xxx_stats_get_stats(chip, port, data); mv88e6xxx_reg_lock(chip); if (chip->info->ops->serdes_get_stats) { @@ -3973,7 +3995,7 @@ static const struct mv88e6xxx_ops mv88e6085_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4011,7 +4033,7 @@ static const struct mv88e6xxx_ops mv88e6095_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .mgmt_rsvd2cpu = mv88e6185_g2_mgmt_rsvd2cpu, .ppu_enable = mv88e6185_g1_ppu_enable, .ppu_disable = mv88e6185_g1_ppu_disable, @@ -4052,7 +4074,7 @@ static const struct mv88e6xxx_ops mv88e6097_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4094,7 +4116,7 @@ static const struct mv88e6xxx_ops mv88e6123_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4137,7 +4159,7 @@ static const struct mv88e6xxx_ops mv88e6131_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4186,7 +4208,7 @@ static const struct mv88e6xxx_ops mv88e6141_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4241,7 +4263,7 @@ static const struct mv88e6xxx_ops mv88e6161_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4279,7 +4301,7 @@ static const struct mv88e6xxx_ops mv88e6165_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4327,7 +4349,7 @@ static const struct mv88e6xxx_ops mv88e6171_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4376,7 +4398,7 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4427,7 +4449,7 @@ static const struct mv88e6xxx_ops mv88e6175_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4476,7 +4498,7 @@ static const struct mv88e6xxx_ops mv88e6176_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4521,7 +4543,7 @@ static const struct mv88e6xxx_ops mv88e6185_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4570,7 +4592,7 @@ static const struct mv88e6xxx_ops mv88e6190_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4628,7 +4650,7 @@ static const struct mv88e6xxx_ops mv88e6190x_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4684,7 +4706,7 @@ static const struct mv88e6xxx_ops mv88e6191_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4743,7 +4765,7 @@ static const struct mv88e6xxx_ops mv88e6240_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -4796,7 +4818,7 @@ static const struct mv88e6xxx_ops mv88e6250_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6250_stats_get_sset_count, .stats_get_strings = mv88e6250_stats_get_strings, - .stats_get_stats = mv88e6250_stats_get_stats, + .stats_get_stat = mv88e6250_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6250_watchdog_ops, @@ -4843,7 +4865,7 @@ static const struct mv88e6xxx_ops mv88e6290_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4902,7 +4924,7 @@ static const struct mv88e6xxx_ops mv88e6320_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6320_stats_get_stats, + .stats_get_stat = mv88e6320_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4949,7 +4971,7 @@ static const struct mv88e6xxx_ops mv88e6321_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6320_stats_get_stats, + .stats_get_stat = mv88e6320_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -4998,7 +5020,7 @@ static const struct mv88e6xxx_ops mv88e6341_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -5056,7 +5078,7 @@ static const struct mv88e6xxx_ops mv88e6350_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -5102,7 +5124,7 @@ static const struct mv88e6xxx_ops mv88e6351_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -5153,7 +5175,7 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings, - .stats_get_stats = mv88e6095_stats_get_stats, + .stats_get_stat = mv88e6095_stats_get_stat, .set_cpu_port = mv88e6095_g1_set_cpu_port, .set_egress_port = mv88e6095_g1_set_egress_port, .watchdog_ops = &mv88e6097_watchdog_ops, @@ -5215,7 +5237,7 @@ static const struct mv88e6xxx_ops mv88e6390_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -5277,7 +5299,7 @@ static const struct mv88e6xxx_ops mv88e6390x_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, .set_cpu_port = mv88e6390_g1_set_cpu_port, .set_egress_port = mv88e6390_g1_set_egress_port, .watchdog_ops = &mv88e6390_watchdog_ops, @@ -5339,7 +5361,7 @@ static const struct mv88e6xxx_ops mv88e6393x_ops = { .stats_set_histogram = mv88e6390_g1_stats_set_histogram, .stats_get_sset_count = mv88e6320_stats_get_sset_count, .stats_get_strings = mv88e6320_stats_get_strings, - .stats_get_stats = mv88e6390_stats_get_stats, + .stats_get_stat = mv88e6390_stats_get_stat, /* .set_cpu_port is missing because this family does not support a global * CPU port, only per port CPU port which is set via * .port_set_upstream_port method. diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 44383a03ef2f..b0dfbcae0be9 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -318,6 +318,17 @@ struct mv88e6xxx_mst { struct mv88e6xxx_stu_entry stu; }; +#define STATS_TYPE_PORT BIT(0) +#define STATS_TYPE_BANK0 BIT(1) +#define STATS_TYPE_BANK1 BIT(2) + +struct mv88e6xxx_hw_stat { + char string[ETH_GSTRING_LEN]; + size_t size; + int reg; + int type; +}; + struct mv88e6xxx_chip { const struct mv88e6xxx_info *info; @@ -574,8 +585,9 @@ struct mv88e6xxx_ops { /* Return the number of strings describing statistics */ int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip); int (*stats_get_strings)(struct mv88e6xxx_chip *chip, uint8_t *data); - int (*stats_get_stats)(struct mv88e6xxx_chip *chip, int port, - uint64_t *data); + int (*stats_get_stat)(struct mv88e6xxx_chip *chip, int port, + const struct mv88e6xxx_hw_stat *stat, + uint64_t *data); int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port); int (*set_egress_port)(struct mv88e6xxx_chip *chip, enum mv88e6xxx_egress_direction direction, @@ -727,17 +739,6 @@ struct mv88e6xxx_pcs_ops { }; -#define STATS_TYPE_PORT BIT(0) -#define STATS_TYPE_BANK0 BIT(1) -#define STATS_TYPE_BANK1 BIT(2) - -struct mv88e6xxx_hw_stat { - char string[ETH_GSTRING_LEN]; - size_t size; - int reg; - int type; -}; - static inline bool mv88e6xxx_has_stu(struct mv88e6xxx_chip *chip) { return chip->info->max_sid > 0 && From patchwork Fri Dec 1 12:58:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13475780 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="ZAf64Aul" Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B23110F8 for ; Fri, 1 Dec 2023 04:58:50 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c9d4740e1cso18781641fa.1 for ; Fri, 01 Dec 2023 04:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701435529; x=1702040329; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=7ZtIZgqTj3rEA0I/YUjrAOcWoVwlj56B9868AHGBdis=; b=ZAf64Aul1JBmzMpEMbsfm+TT1K17gCdCc4Zr5ltAHuqvuFM60SezveqeA5Qbfivynh whnQvG9Zh9MFvVhnczJnGDgMaJ/giCsSaCPv2KmHRGfTRtpMwAEebcNXN/be4pI+avWW z5HRgNkECJVxR6XblyjDUAeCrHn4GUbj+aLYtwdFpCrXaEbrluVNna7nBmbF5I0iZ25e tYURHIU168HmsXduOxF7d5rjeo+t9rhuyMV4JiwQ8WJTEUdp97bSyX5CYyHMg8F3dO++ 2DdD4H9Dt86S8y5WNWgfhWXitOzfqKeansmumvB80a1yuiqlRb2Z7A12MwTeU7KcLDrZ QF7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435529; x=1702040329; h=content-transfer-encoding:organization:mime-version: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=7ZtIZgqTj3rEA0I/YUjrAOcWoVwlj56B9868AHGBdis=; b=pkC9ce9E3wo6S5lBmQkQQj4TSCx1czW/U3We0FFf+PEpUihxfBxcI4gpvCvvgYvhk9 5ahJwuxIXRbFjNEj+tyEJdKLs63qW/EQyzgSfLP+FkYjRj+ejdwEhduusHDbZvfxnFRF yxdvsdb6LxK4moJBp210vC6wOoJ/8hoox2+9CNC5KgiwRCrbwvCFMMa7fAnFFT3EQLNY NAbzN5bdtsnNzirtGdRLwxtbUJCcZ6MfFqXVI59lBSbJg8LD68AxN0RYGZKs+KuDpFe6 DSDuvlWtvGJNOhevLhiKTvACHeYBU3Q9VT2JB6vXCourJ3HCXz7bmf1OBbi692vh4nbq c9Kw== X-Gm-Message-State: AOJu0YxpFeEFv3QeNNE+gZoF3YKrDI/z6ykj+4y6hwJHLeKR4A30W5vG TC+kii0bqC4ae4BF+FygtWFKAg== X-Google-Smtp-Source: AGHT+IEgBiwidzG8ByH2iwN5dAfPS6+RGMljZD4DEHlk72N6ChBSJLk9ES5gBKM28pb3uJhtErHqwA== X-Received: by 2002:a05:651c:221d:b0:2c9:dae6:4452 with SMTP id y29-20020a05651c221d00b002c9dae64452mr374594ljq.212.1701435528948; Fri, 01 Dec 2023 04:58:48 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id z13-20020a05651c11cd00b002c02b36d381sm417036ljo.88.2023.12.01.04.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:58:47 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 2/4] net: dsa: mv88e6xxx: Give each hw stat an ID Date: Fri, 1 Dec 2023 13:58:10 +0100 Message-Id: <20231201125812.1052078-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201125812.1052078-1-tobias@waldekranz.com> References: <20231201125812.1052078-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org With the upcoming standard counter group support, we are no longer reading out the whole set of counters, but rather mapping a subset to the requested group. Therefore, create an enum with an ID for each stat, such that mv88e6xxx_hw_stats[] can be subscripted with a human-readable ID corresponding to the counter's name. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 140 +++++++++++++++++-------------- 1 file changed, 77 insertions(+), 63 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index ffd81174bda3..71c60f229a2f 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -937,66 +937,80 @@ static int mv88e6xxx_stats_snapshot(struct mv88e6xxx_chip *chip, int port) return chip->info->ops->stats_snapshot(chip, port); } -static struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { - { "in_good_octets", 8, 0x00, STATS_TYPE_BANK0, }, - { "in_bad_octets", 4, 0x02, STATS_TYPE_BANK0, }, - { "in_unicast", 4, 0x04, STATS_TYPE_BANK0, }, - { "in_broadcasts", 4, 0x06, STATS_TYPE_BANK0, }, - { "in_multicasts", 4, 0x07, STATS_TYPE_BANK0, }, - { "in_pause", 4, 0x16, STATS_TYPE_BANK0, }, - { "in_undersize", 4, 0x18, STATS_TYPE_BANK0, }, - { "in_fragments", 4, 0x19, STATS_TYPE_BANK0, }, - { "in_oversize", 4, 0x1a, STATS_TYPE_BANK0, }, - { "in_jabber", 4, 0x1b, STATS_TYPE_BANK0, }, - { "in_rx_error", 4, 0x1c, STATS_TYPE_BANK0, }, - { "in_fcs_error", 4, 0x1d, STATS_TYPE_BANK0, }, - { "out_octets", 8, 0x0e, STATS_TYPE_BANK0, }, - { "out_unicast", 4, 0x10, STATS_TYPE_BANK0, }, - { "out_broadcasts", 4, 0x13, STATS_TYPE_BANK0, }, - { "out_multicasts", 4, 0x12, STATS_TYPE_BANK0, }, - { "out_pause", 4, 0x15, STATS_TYPE_BANK0, }, - { "excessive", 4, 0x11, STATS_TYPE_BANK0, }, - { "collisions", 4, 0x1e, STATS_TYPE_BANK0, }, - { "deferred", 4, 0x05, STATS_TYPE_BANK0, }, - { "single", 4, 0x14, STATS_TYPE_BANK0, }, - { "multiple", 4, 0x17, STATS_TYPE_BANK0, }, - { "out_fcs_error", 4, 0x03, STATS_TYPE_BANK0, }, - { "late", 4, 0x1f, STATS_TYPE_BANK0, }, - { "hist_64bytes", 4, 0x08, STATS_TYPE_BANK0, }, - { "hist_65_127bytes", 4, 0x09, STATS_TYPE_BANK0, }, - { "hist_128_255bytes", 4, 0x0a, STATS_TYPE_BANK0, }, - { "hist_256_511bytes", 4, 0x0b, STATS_TYPE_BANK0, }, - { "hist_512_1023bytes", 4, 0x0c, STATS_TYPE_BANK0, }, - { "hist_1024_max_bytes", 4, 0x0d, STATS_TYPE_BANK0, }, - { "sw_in_discards", 4, 0x10, STATS_TYPE_PORT, }, - { "sw_in_filtered", 2, 0x12, STATS_TYPE_PORT, }, - { "sw_out_filtered", 2, 0x13, STATS_TYPE_PORT, }, - { "in_discards", 4, 0x00, STATS_TYPE_BANK1, }, - { "in_filtered", 4, 0x01, STATS_TYPE_BANK1, }, - { "in_accepted", 4, 0x02, STATS_TYPE_BANK1, }, - { "in_bad_accepted", 4, 0x03, STATS_TYPE_BANK1, }, - { "in_good_avb_class_a", 4, 0x04, STATS_TYPE_BANK1, }, - { "in_good_avb_class_b", 4, 0x05, STATS_TYPE_BANK1, }, - { "in_bad_avb_class_a", 4, 0x06, STATS_TYPE_BANK1, }, - { "in_bad_avb_class_b", 4, 0x07, STATS_TYPE_BANK1, }, - { "tcam_counter_0", 4, 0x08, STATS_TYPE_BANK1, }, - { "tcam_counter_1", 4, 0x09, STATS_TYPE_BANK1, }, - { "tcam_counter_2", 4, 0x0a, STATS_TYPE_BANK1, }, - { "tcam_counter_3", 4, 0x0b, STATS_TYPE_BANK1, }, - { "in_da_unknown", 4, 0x0e, STATS_TYPE_BANK1, }, - { "in_management", 4, 0x0f, STATS_TYPE_BANK1, }, - { "out_queue_0", 4, 0x10, STATS_TYPE_BANK1, }, - { "out_queue_1", 4, 0x11, STATS_TYPE_BANK1, }, - { "out_queue_2", 4, 0x12, STATS_TYPE_BANK1, }, - { "out_queue_3", 4, 0x13, STATS_TYPE_BANK1, }, - { "out_queue_4", 4, 0x14, STATS_TYPE_BANK1, }, - { "out_queue_5", 4, 0x15, STATS_TYPE_BANK1, }, - { "out_queue_6", 4, 0x16, STATS_TYPE_BANK1, }, - { "out_queue_7", 4, 0x17, STATS_TYPE_BANK1, }, - { "out_cut_through", 4, 0x18, STATS_TYPE_BANK1, }, - { "out_octets_a", 4, 0x1a, STATS_TYPE_BANK1, }, - { "out_octets_b", 4, 0x1b, STATS_TYPE_BANK1, }, - { "out_management", 4, 0x1f, STATS_TYPE_BANK1, }, +#define MV88E6XXX_HW_STAT_MAPPER(_fn) \ + _fn(in_good_octets, 8, 0x00, STATS_TYPE_BANK0) \ + _fn(in_bad_octets, 4, 0x02, STATS_TYPE_BANK0) \ + _fn(in_unicast, 4, 0x04, STATS_TYPE_BANK0) \ + _fn(in_broadcasts, 4, 0x06, STATS_TYPE_BANK0) \ + _fn(in_multicasts, 4, 0x07, STATS_TYPE_BANK0) \ + _fn(in_pause, 4, 0x16, STATS_TYPE_BANK0) \ + _fn(in_undersize, 4, 0x18, STATS_TYPE_BANK0) \ + _fn(in_fragments, 4, 0x19, STATS_TYPE_BANK0) \ + _fn(in_oversize, 4, 0x1a, STATS_TYPE_BANK0) \ + _fn(in_jabber, 4, 0x1b, STATS_TYPE_BANK0) \ + _fn(in_rx_error, 4, 0x1c, STATS_TYPE_BANK0) \ + _fn(in_fcs_error, 4, 0x1d, STATS_TYPE_BANK0) \ + _fn(out_octets, 8, 0x0e, STATS_TYPE_BANK0) \ + _fn(out_unicast, 4, 0x10, STATS_TYPE_BANK0) \ + _fn(out_broadcasts, 4, 0x13, STATS_TYPE_BANK0) \ + _fn(out_multicasts, 4, 0x12, STATS_TYPE_BANK0) \ + _fn(out_pause, 4, 0x15, STATS_TYPE_BANK0) \ + _fn(excessive, 4, 0x11, STATS_TYPE_BANK0) \ + _fn(collisions, 4, 0x1e, STATS_TYPE_BANK0) \ + _fn(deferred, 4, 0x05, STATS_TYPE_BANK0) \ + _fn(single, 4, 0x14, STATS_TYPE_BANK0) \ + _fn(multiple, 4, 0x17, STATS_TYPE_BANK0) \ + _fn(out_fcs_error, 4, 0x03, STATS_TYPE_BANK0) \ + _fn(late, 4, 0x1f, STATS_TYPE_BANK0) \ + _fn(hist_64bytes, 4, 0x08, STATS_TYPE_BANK0) \ + _fn(hist_65_127bytes, 4, 0x09, STATS_TYPE_BANK0) \ + _fn(hist_128_255bytes, 4, 0x0a, STATS_TYPE_BANK0) \ + _fn(hist_256_511bytes, 4, 0x0b, STATS_TYPE_BANK0) \ + _fn(hist_512_1023bytes, 4, 0x0c, STATS_TYPE_BANK0) \ + _fn(hist_1024_max_bytes, 4, 0x0d, STATS_TYPE_BANK0) \ + _fn(sw_in_discards, 4, 0x10, STATS_TYPE_PORT) \ + _fn(sw_in_filtered, 2, 0x12, STATS_TYPE_PORT) \ + _fn(sw_out_filtered, 2, 0x13, STATS_TYPE_PORT) \ + _fn(in_discards, 4, 0x00, STATS_TYPE_BANK1) \ + _fn(in_filtered, 4, 0x01, STATS_TYPE_BANK1) \ + _fn(in_accepted, 4, 0x02, STATS_TYPE_BANK1) \ + _fn(in_bad_accepted, 4, 0x03, STATS_TYPE_BANK1) \ + _fn(in_good_avb_class_a, 4, 0x04, STATS_TYPE_BANK1) \ + _fn(in_good_avb_class_b, 4, 0x05, STATS_TYPE_BANK1) \ + _fn(in_bad_avb_class_a, 4, 0x06, STATS_TYPE_BANK1) \ + _fn(in_bad_avb_class_b, 4, 0x07, STATS_TYPE_BANK1) \ + _fn(tcam_counter_0, 4, 0x08, STATS_TYPE_BANK1) \ + _fn(tcam_counter_1, 4, 0x09, STATS_TYPE_BANK1) \ + _fn(tcam_counter_2, 4, 0x0a, STATS_TYPE_BANK1) \ + _fn(tcam_counter_3, 4, 0x0b, STATS_TYPE_BANK1) \ + _fn(in_da_unknown, 4, 0x0e, STATS_TYPE_BANK1) \ + _fn(in_management, 4, 0x0f, STATS_TYPE_BANK1) \ + _fn(out_queue_0, 4, 0x10, STATS_TYPE_BANK1) \ + _fn(out_queue_1, 4, 0x11, STATS_TYPE_BANK1) \ + _fn(out_queue_2, 4, 0x12, STATS_TYPE_BANK1) \ + _fn(out_queue_3, 4, 0x13, STATS_TYPE_BANK1) \ + _fn(out_queue_4, 4, 0x14, STATS_TYPE_BANK1) \ + _fn(out_queue_5, 4, 0x15, STATS_TYPE_BANK1) \ + _fn(out_queue_6, 4, 0x16, STATS_TYPE_BANK1) \ + _fn(out_queue_7, 4, 0x17, STATS_TYPE_BANK1) \ + _fn(out_cut_through, 4, 0x18, STATS_TYPE_BANK1) \ + _fn(out_octets_a, 4, 0x1a, STATS_TYPE_BANK1) \ + _fn(out_octets_b, 4, 0x1b, STATS_TYPE_BANK1) \ + _fn(out_management, 4, 0x1f, STATS_TYPE_BANK1) \ + /* */ + +#define MV88E6XXX_HW_STAT_ENTRY(_string, _size, _reg, _type) \ + { #_string, _size, _reg, _type }, +static const struct mv88e6xxx_hw_stat mv88e6xxx_hw_stats[] = { + MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENTRY) +}; + +#define MV88E6XXX_HW_STAT_ENUM(_string, _size, _reg, _type) \ + MV88E6XXX_HW_STAT_ID_ ## _string, +enum mv88e6xxx_hw_stat_id { + MV88E6XXX_HW_STAT_MAPPER(MV88E6XXX_HW_STAT_ENUM) + + MV88E6XXX_HW_STAT_ID_MAX }; static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip, @@ -1043,7 +1057,7 @@ static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip, static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip, uint8_t *data, int types) { - struct mv88e6xxx_hw_stat *stat; + const struct mv88e6xxx_hw_stat *stat; int i, j; for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { @@ -1124,7 +1138,7 @@ static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, static int mv88e6xxx_stats_get_sset_count(struct mv88e6xxx_chip *chip, int types) { - struct mv88e6xxx_hw_stat *stat; + const struct mv88e6xxx_hw_stat *stat; int i, j; for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { @@ -1251,7 +1265,7 @@ static int mv88e6xxx_stats_get_stat(struct mv88e6xxx_chip *chip, int port, static int mv88e6xxx_stats_get_stats(struct mv88e6xxx_chip *chip, int port, uint64_t *data) { - struct mv88e6xxx_hw_stat *stat; + const struct mv88e6xxx_hw_stat *stat; int i, j; for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { From patchwork Fri Dec 1 12:58:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13475782 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="VfWS8zZL" Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F41401B3 for ; Fri, 1 Dec 2023 04:58:51 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c9b88cf626so28048101fa.3 for ; Fri, 01 Dec 2023 04:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701435530; x=1702040330; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=emgmCjmERPAQVOPYdRIVng8dq1nSX2gRlTojtJgnELA=; b=VfWS8zZLXU2snFmSxcE5y6e2z5KpjsEcOMEyKl9YbDiArh5eVbaGA4inCnuQd9jCxU 7qpmaJx4uRTwL7oGCPKzS+nyC5d1j8rHjekUFKwwONVf55Ey5SDQpU6Sa/J7d/FCF3mF n4Zkv2gD3Ov3plBY9ZOjmzY27vsqAWVqEvI5bSZ9DRoJFVyr63b5fM7gksCNeoBx537E Sv0/G3cLdZfcq78dulXGYJ6gXglm+jAeV9cSZngQduab0kr11KJv2Fn3IR0c5ATM6xbM uEFo02MMfkr0IRmLKsSyj4lF7z+oM+q60TF/xJqwLWRZQr6uJ7IbXZjLExlsGOhog64k N5gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435530; x=1702040330; h=content-transfer-encoding:organization:mime-version: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=emgmCjmERPAQVOPYdRIVng8dq1nSX2gRlTojtJgnELA=; b=EWAZFO29fMEWkSz2zrEts2VAzWz3Vf+v8kYhhb6k4DOnB0KFlzhQpt1/739YfqGXwU yaWGDtXKyeRRi5BqF74fifJAP8pPlb6Rj0X7cM0lsADmEcBOgW6P4wXPAsQYU7C1OH/Y Rknm2VAHy7jGmLHW6hrb3YyJa6EAbL9TZzrcqOuM675TPmhSWUOzIlUyztzep9C0Vy3w fzj2jLWVKduF706gsi7tWKjQFHLemba7WMSNYsCfDD0zwpo4TiD8NZE7t4g+Qekp3eH1 8ODyH6UHAy6S/jCvhdG9s0/Ozq7z7mNNjLPIE5bfsSTTkVeJU+G8gTFP96eQhl6Yg0Im 35jQ== X-Gm-Message-State: AOJu0Yz3qJ/R8A8h/LpgtRt4AGr2mHmBa3J/B5nJ4vWqQvCg/b7RoUeb 6t9CahS5kDaI0fPIc6c32T5tTw== X-Google-Smtp-Source: AGHT+IEPtlwCMSmQKnEYHe/wVXAiCwqDKPcDP6UVRIuDjprAJXl31Q1iPp+78BAMoWH0JySe3/YSEg== X-Received: by 2002:a2e:8708:0:b0:2c9:d872:e7a6 with SMTP id m8-20020a2e8708000000b002c9d872e7a6mr900767lji.93.1701435530239; Fri, 01 Dec 2023 04:58:50 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id z13-20020a05651c11cd00b002c02b36d381sm417036ljo.88.2023.12.01.04.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:58:49 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 3/4] net: dsa: mv88e6xxx: Add "eth-mac" counter group support Date: Fri, 1 Dec 2023 13:58:11 +0100 Message-Id: <20231201125812.1052078-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201125812.1052078-1-tobias@waldekranz.com> References: <20231201125812.1052078-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Report the applicable subset of an mv88e6xxx port's counters using ethtool's standardized "eth-mac" counter group. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 71c60f229a2f..51e3744cb89b 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1320,6 +1320,57 @@ static void mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds, int port, } +static void mv88e6xxx_get_eth_mac_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_mac_stats *mac_stats) +{ +#define MV88E6XXX_ETH_MAC_STAT_MAPPING(_id, _member) \ + [MV88E6XXX_HW_STAT_ID_ ## _id] = \ + offsetof(struct ethtool_eth_mac_stats, stats._member) \ + + static const size_t stat_map[MV88E6XXX_HW_STAT_ID_MAX] = { + MV88E6XXX_ETH_MAC_STAT_MAPPING(out_unicast, FramesTransmittedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(single, SingleCollisionFrames), + MV88E6XXX_ETH_MAC_STAT_MAPPING(multiple, MultipleCollisionFrames), + MV88E6XXX_ETH_MAC_STAT_MAPPING(in_unicast, FramesReceivedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(in_fcs_error, FrameCheckSequenceErrors), + MV88E6XXX_ETH_MAC_STAT_MAPPING(out_octets, OctetsTransmittedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(deferred, FramesWithDeferredXmissions), + MV88E6XXX_ETH_MAC_STAT_MAPPING(late, LateCollisions), + MV88E6XXX_ETH_MAC_STAT_MAPPING(in_good_octets, OctetsReceivedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(out_multicasts, MulticastFramesXmittedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(out_broadcasts, BroadcastFramesXmittedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(excessive, FramesWithExcessiveDeferral), + MV88E6XXX_ETH_MAC_STAT_MAPPING(in_multicasts, MulticastFramesReceivedOK), + MV88E6XXX_ETH_MAC_STAT_MAPPING(in_broadcasts, BroadcastFramesReceivedOK), + }; + struct mv88e6xxx_chip *chip = ds->priv; + const struct mv88e6xxx_hw_stat *stat; + enum mv88e6xxx_hw_stat_id id; + u64 *member; + int ret; + + mv88e6xxx_reg_lock(chip); + ret = mv88e6xxx_stats_snapshot(chip, port); + mv88e6xxx_reg_unlock(chip); + + if (ret < 0) + return; + + stat = mv88e6xxx_hw_stats; + for (id = 0; id < MV88E6XXX_HW_STAT_ID_MAX; id++, stat++) { + if (!stat_map[id]) + continue; + + member = (u64 *)(((char *)mac_stats) + stat_map[id]); + mv88e6xxx_stats_get_stat(chip, port, stat, member); + } + + mac_stats->stats.FramesTransmittedOK += mac_stats->stats.MulticastFramesXmittedOK; + mac_stats->stats.FramesTransmittedOK += mac_stats->stats.BroadcastFramesXmittedOK; + mac_stats->stats.FramesReceivedOK += mac_stats->stats.MulticastFramesReceivedOK; + mac_stats->stats.FramesReceivedOK += mac_stats->stats.BroadcastFramesReceivedOK; +} + static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) { struct mv88e6xxx_chip *chip = ds->priv; @@ -6839,6 +6890,7 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .phylink_mac_link_up = mv88e6xxx_mac_link_up, .get_strings = mv88e6xxx_get_strings, .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, + .get_eth_mac_stats = mv88e6xxx_get_eth_mac_stats, .get_sset_count = mv88e6xxx_get_sset_count, .port_max_mtu = mv88e6xxx_get_max_mtu, .port_change_mtu = mv88e6xxx_change_mtu, From patchwork Fri Dec 1 12:58:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13475781 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="qPthpX49" Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1CD10E2 for ; Fri, 1 Dec 2023 04:58:53 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c9c18e7990so27533591fa.2 for ; Fri, 01 Dec 2023 04:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1701435531; x=1702040331; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=3nO97Jrg0PQ6UehyNGDlcD8xXoZojQSDiJExXNN24ho=; b=qPthpX499RLrR+TgG5aTmzMdje6jv14zRnQoCbIYF+64mYqkEBumYCMPEG33tBFR23 maJBYhFRyPeken14QVB/RjDiMUwYeBow5o0wEr7lirYM8I2xvofjWHrAsTtsDp5ibem8 hIPfn4HOIx41F6p5VmyxEbm5keMeJxeL0OawucJOg8AL+GbL3jLSaV/XhkOBPiSzizwF 1d4/V9qYaW6L7NNmsN/DJQKw/mU3PGwiPWgVeGyt0m+7sXOa69vcezG8edY4a+ci+xel BP8gJC+vXY1A42lXPukTO7J/+DHhBYRu3Z9tKBUenyHk+91Fp8jqyOBOHtOdUFjJQ/V4 mvFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701435531; x=1702040331; h=content-transfer-encoding:organization:mime-version: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=3nO97Jrg0PQ6UehyNGDlcD8xXoZojQSDiJExXNN24ho=; b=tWeEfIEm2K8qqlt907yfrbfUQ4aiIyKmlOwJ4RINZ/MOKHNAm65BkOyNaEkk9etB+w 3s6D069PXDrC7+xrAihQHcBOM7wj/N5gmzZGJqjGP8HU7Cy5bEOTlbbaQEU7+sRUdziF qjlQaji8Xlj5gwOzL+mPdWPQqxJHMbC880gnF7t+MpqF6O3RQoON9LmBjoxERec6jCM7 rRxw/I0Lahmim7rUN9c5MKqklCMPJ2VB0h3vLJtn/qOsJk998KY0Jvs1gKFemEi9Yi+N DNgqfQVbT/ZypYG+q2kMVAebhSTA0qpkordF0wx+vGn6qzk2dY1ErDcTc4JX/LPMatCE bP1w== X-Gm-Message-State: AOJu0Yyp35atBX61uDYLkQzkOkrrMkVkVZLQlBG+XYlIw6HG2Ru+4163 Z2JdJiW+cQCik8yYNZIehWf7lQ== X-Google-Smtp-Source: AGHT+IHOAAz+6anfXzaug6CijYDcDKmUqZQ351SgIm+13Rmi6q/HQdKOA8zYwtvRQoBj2vrjFx/vyA== X-Received: by 2002:a2e:90cf:0:b0:2c9:d872:abc7 with SMTP id o15-20020a2e90cf000000b002c9d872abc7mr837566ljg.69.1701435531481; Fri, 01 Dec 2023 04:58:51 -0800 (PST) Received: from wkz-x13.addiva.ad (a124.broadband3.quicknet.se. [46.17.184.124]) by smtp.gmail.com with ESMTPSA id z13-20020a05651c11cd00b002c02b36d381sm417036ljo.88.2023.12.01.04.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 04:58:50 -0800 (PST) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, olteanv@gmail.com, netdev@vger.kernel.org Subject: [PATCH net-next 4/4] net: dsa: mv88e6xxx: Add "rmon" counter group support Date: Fri, 1 Dec 2023 13:58:12 +0100 Message-Id: <20231201125812.1052078-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201125812.1052078-1-tobias@waldekranz.com> References: <20231201125812.1052078-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: kuba@kernel.org Report the applicable subset of an mv88e6xxx port's counters using ethtool's standardized "rmon" counter group. Signed-off-by: Tobias Waldekranz --- drivers/net/dsa/mv88e6xxx/chip.c | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 51e3744cb89b..bcb47ccf3ec1 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1371,6 +1371,60 @@ static void mv88e6xxx_get_eth_mac_stats(struct dsa_switch *ds, int port, mac_stats->stats.FramesReceivedOK += mac_stats->stats.BroadcastFramesReceivedOK; } +static void mv88e6xxx_get_rmon_stats(struct dsa_switch *ds, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges) +{ +#define MV88E6XXX_RMON_STAT_MAPPING(_id, _member) \ + [MV88E6XXX_HW_STAT_ID_ ## _id] = \ + offsetof(struct ethtool_rmon_stats, stats._member) \ + + static const size_t stat_map[MV88E6XXX_HW_STAT_ID_MAX] = { + MV88E6XXX_RMON_STAT_MAPPING(in_undersize, undersize_pkts), + MV88E6XXX_RMON_STAT_MAPPING(in_oversize, oversize_pkts), + MV88E6XXX_RMON_STAT_MAPPING(in_fragments, fragments), + MV88E6XXX_RMON_STAT_MAPPING(in_jabber, jabbers), + MV88E6XXX_RMON_STAT_MAPPING(hist_64bytes, hist[0]), + MV88E6XXX_RMON_STAT_MAPPING(hist_65_127bytes, hist[1]), + MV88E6XXX_RMON_STAT_MAPPING(hist_128_255bytes, hist[2]), + MV88E6XXX_RMON_STAT_MAPPING(hist_256_511bytes, hist[3]), + MV88E6XXX_RMON_STAT_MAPPING(hist_512_1023bytes, hist[4]), + MV88E6XXX_RMON_STAT_MAPPING(hist_1024_max_bytes, hist[5]), + }; + static const struct ethtool_rmon_hist_range rmon_ranges[] = { + { 64, 64 }, + { 65, 127 }, + { 128, 255 }, + { 256, 511 }, + { 512, 1023 }, + { 1024, 65535 }, + {} + }; + struct mv88e6xxx_chip *chip = ds->priv; + const struct mv88e6xxx_hw_stat *stat; + enum mv88e6xxx_hw_stat_id id; + u64 *member; + int ret; + + mv88e6xxx_reg_lock(chip); + ret = mv88e6xxx_stats_snapshot(chip, port); + mv88e6xxx_reg_unlock(chip); + + if (ret < 0) + return; + + stat = mv88e6xxx_hw_stats; + for (id = 0; id < MV88E6XXX_HW_STAT_ID_MAX; id++, stat++) { + if (!stat_map[id]) + continue; + + member = (u64 *)(((char *)rmon_stats) + stat_map[id]); + mv88e6xxx_stats_get_stat(chip, port, stat, member); + } + + *ranges = rmon_ranges; +} + static int mv88e6xxx_get_regs_len(struct dsa_switch *ds, int port) { struct mv88e6xxx_chip *chip = ds->priv; @@ -6891,6 +6945,7 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .get_strings = mv88e6xxx_get_strings, .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, .get_eth_mac_stats = mv88e6xxx_get_eth_mac_stats, + .get_rmon_stats = mv88e6xxx_get_rmon_stats, .get_sset_count = mv88e6xxx_get_sset_count, .port_max_mtu = mv88e6xxx_get_max_mtu, .port_change_mtu = mv88e6xxx_change_mtu,