2022-11-30 13:35:21

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 0/5] add ethtool categorized statistics

Patch series contain following changes:
- add categorized ethtool statistics for Microchip KSZ series
switches, support "eth-mac", "eth-phy", "eth-ctrl", "rmon"
parameters with ethtool statistics command. mib parameter index
are same for all KSZ family switches except KSZ8830. So, functions
can be re-used across all KSZ Families (except KSZ8830) and LAN937x
series. Create separate functions for KSZ8830 with their mib
parameters.
- Remove num_alus member from ksz_chip_data structure since it is
unused.

Changes tested on LAN937x Series and KSZ9477.

Rakesh Sankaranarayanan (5):
net: dsa: microchip: add rmon grouping for ethtool statistics
net: dsa: microchip: add eth ctrl grouping for ethtool statistics
net: dsa: microchip: add eth mac grouping for ethtool statistics
net: dsa: microchip: add eth phy grouping for ethtool statistics
net: dsa: microchip: remove num_alus variable

drivers/net/dsa/microchip/Makefile | 1 +
drivers/net/dsa/microchip/ksz_common.c | 70 +++--
drivers/net/dsa/microchip/ksz_common.h | 10 +-
drivers/net/dsa/microchip/ksz_ethtool.c | 344 ++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 31 +++
5 files changed, 439 insertions(+), 17 deletions(-)
create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.c
create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.h

--
2.34.1


2022-11-30 13:35:28

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 4/5] net: dsa: microchip: add eth phy grouping for ethtool statistics

Add support for ethtool standard device statistics grouping. Support
ethernet phy statistics grouping using eth-phy groups parameter in
ethtool command.

Signed-off-by: Rakesh Sankaranarayanan <[email protected]>
---
drivers/net/dsa/microchip/ksz_common.c | 13 +++++++++
drivers/net/dsa/microchip/ksz_common.h | 2 ++
drivers/net/dsa/microchip/ksz_ethtool.c | 36 +++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 5 ++++
4 files changed, 56 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index ceb3c4f120bd..0f3925d0c668 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -161,6 +161,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.get_rmon_stats = ksz8_get_rmon_stats,
.get_eth_ctrl_stats = ksz8_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz8_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz8_get_eth_phy_stats,
.fdb_dump = ksz8_fdb_dump,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
@@ -201,6 +202,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz9477_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz9477_get_eth_phy_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -240,6 +242,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz9477_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz9477_get_eth_phy_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -1647,6 +1650,15 @@ static void ksz_get_eth_mac_stats(struct dsa_switch *ds, int port,
dev->dev_ops->get_eth_mac_stats(dev, port, mac_stats);
}

+static void ksz_get_eth_phy_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_device *dev = ds->priv;
+
+ if (dev->dev_ops->get_eth_phy_stats)
+ dev->dev_ops->get_eth_phy_stats(dev, port, phy_stats);
+}
+
static void ksz_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *buf)
{
@@ -2900,6 +2912,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.get_rmon_stats = ksz_get_rmon_stats,
.get_eth_ctrl_stats = ksz_get_eth_ctrl_stats,
.get_eth_mac_stats = ksz_get_eth_mac_stats,
+ .get_eth_phy_stats = ksz_get_eth_phy_stats,
.port_change_mtu = ksz_change_mtu,
.port_max_mtu = ksz_max_mtu,
};
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 5b77f98483a9..c253d761b62b 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -346,6 +346,8 @@ struct ksz_dev_ops {
struct ethtool_eth_ctrl_stats *ctrl_stats);
void (*get_eth_mac_stats)(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+ void (*get_eth_phy_stats)(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);
};

struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
index 96529fea8e84..5061c503437a 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.c
+++ b/drivers/net/dsa/microchip/ksz_ethtool.c
@@ -203,6 +203,24 @@ void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
mutex_unlock(&mib->cnt_mutex);
}

+void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz8_rx_symbol_err];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_symbol_err, NULL, cnt);
+
+ phy_stats->SymbolErrorDuringCarrier = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges)
@@ -306,3 +324,21 @@ void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,

mutex_unlock(&mib->cnt_mutex);
}
+
+void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz9477_rx_symbol_err];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_symbol_err, NULL, cnt);
+
+ phy_stats->SymbolErrorDuringCarrier = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/microchip/ksz_ethtool.h
index 2dcfe8922b4e..042a0b38a899 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.h
+++ b/drivers/net/dsa/microchip/ksz_ethtool.h
@@ -15,6 +15,8 @@ void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);

void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
@@ -23,4 +25,7 @@ void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,
struct ethtool_eth_mac_stats *mac_stats);
+void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_phy_stats *phy_stats);
+
#endif
--
2.34.1

2022-11-30 14:02:03

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 3/5] net: dsa: microchip: add eth mac grouping for ethtool statistics

Add support for ethtool standard device statistics grouping.
Support ethernet mac statistics grouping using eth-mac groups
parameter in ethtool command.

Signed-off-by: Rakesh Sankaranarayanan <[email protected]>
---
drivers/net/dsa/microchip/ksz_common.c | 13 ++++
drivers/net/dsa/microchip/ksz_common.h | 2 +
drivers/net/dsa/microchip/ksz_ethtool.c | 88 +++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 4 ++
4 files changed, 107 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 9b13a38d553d..ceb3c4f120bd 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -160,6 +160,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.port_init_cnt = ksz8_port_init_cnt,
.get_rmon_stats = ksz8_get_rmon_stats,
.get_eth_ctrl_stats = ksz8_get_eth_ctrl_stats,
+ .get_eth_mac_stats = ksz8_get_eth_mac_stats,
.fdb_dump = ksz8_fdb_dump,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
@@ -199,6 +200,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
.port_init_cnt = ksz9477_port_init_cnt,
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
+ .get_eth_mac_stats = ksz9477_get_eth_mac_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -237,6 +239,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.port_init_cnt = ksz9477_port_init_cnt,
.get_rmon_stats = ksz9477_get_rmon_stats,
.get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
+ .get_eth_mac_stats = ksz9477_get_eth_mac_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -1635,6 +1638,15 @@ static void ksz_get_eth_ctrl_stats(struct dsa_switch *ds, int port,
dev->dev_ops->get_eth_ctrl_stats(dev, port, ctrl_stats);
}

+static void ksz_get_eth_mac_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_mac_stats *mac_stats)
+{
+ struct ksz_device *dev = ds->priv;
+
+ if (dev->dev_ops->get_eth_mac_stats)
+ dev->dev_ops->get_eth_mac_stats(dev, port, mac_stats);
+}
+
static void ksz_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *buf)
{
@@ -2887,6 +2899,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.get_pause_stats = ksz_get_pause_stats,
.get_rmon_stats = ksz_get_rmon_stats,
.get_eth_ctrl_stats = ksz_get_eth_ctrl_stats,
+ .get_eth_mac_stats = ksz_get_eth_mac_stats,
.port_change_mtu = ksz_change_mtu,
.port_max_mtu = ksz_max_mtu,
};
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 07627ff1a749..5b77f98483a9 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -344,6 +344,8 @@ struct ksz_dev_ops {
const struct ethtool_rmon_hist_range **ranges);
void (*get_eth_ctrl_stats)(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
+ void (*get_eth_mac_stats)(struct ksz_device *dev, int port,
+ struct ethtool_eth_mac_stats *mac_stats);
};

struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
index 4c9ca21e1806..96529fea8e84 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.c
+++ b/drivers/net/dsa/microchip/ksz_ethtool.c
@@ -159,6 +159,50 @@ void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
mutex_unlock(&mib->cnt_mutex);
}

+void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_mac_stats *mac_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *ctr;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+ ctr = mib->counters;
+
+ while (mib->cnt_ptr < dev->info->mib_cnt) {
+ dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr,
+ NULL, &mib->counters[mib->cnt_ptr]);
+ ++mib->cnt_ptr;
+ }
+
+ mac_stats->FramesTransmittedOK = ctr[ksz8_tx_mcast] +
+ ctr[ksz8_tx_bcast] +
+ ctr[ksz8_tx_ucast] +
+ ctr[ksz8_tx_pause];
+ mac_stats->SingleCollisionFrames = ctr[ksz8_tx_single_col];
+ mac_stats->MultipleCollisionFrames = ctr[ksz8_tx_mult_col];
+ mac_stats->FramesReceivedOK = ctr[ksz8_rx_mcast] +
+ ctr[ksz8_rx_bcast] +
+ ctr[ksz8_rx_ucast] +
+ ctr[ksz8_rx_pause];
+ mac_stats->FrameCheckSequenceErrors = ctr[ksz8_rx_crc_err];
+ mac_stats->AlignmentErrors = ctr[ksz8_rx_align_err];
+ mac_stats->OctetsTransmittedOK = ctr[ksz8_tx_total_col];
+ mac_stats->FramesWithDeferredXmissions = ctr[ksz8_tx_deferred];
+ mac_stats->LateCollisions = ctr[ksz8_tx_late_col];
+ mac_stats->FramesAbortedDueToXSColls = ctr[ksz8_tx_exc_col];
+ mac_stats->MulticastFramesXmittedOK = ctr[ksz8_tx_mcast];
+ mac_stats->BroadcastFramesXmittedOK = ctr[ksz8_tx_bcast];
+ mac_stats->MulticastFramesReceivedOK = ctr[ksz8_rx_mcast];
+ mac_stats->BroadcastFramesReceivedOK = ctr[ksz8_rx_bcast];
+ mac_stats->InRangeLengthErrors = ctr[ksz8_rx_oversize];
+
+ mib->cnt_ptr = 0;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges)
@@ -218,3 +262,47 @@ void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,

mutex_unlock(&mib->cnt_mutex);
}
+
+void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_mac_stats *mac_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *ctr;
+
+ mib = &dev->ports[port].mib;
+ ctr = mib->counters;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ while (mib->cnt_ptr < dev->info->mib_cnt) {
+ dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr,
+ NULL, &mib->counters[mib->cnt_ptr]);
+ ++mib->cnt_ptr;
+ }
+
+ mac_stats->FramesTransmittedOK = ctr[ksz9477_tx_mcast] +
+ ctr[ksz9477_tx_bcast] +
+ ctr[ksz9477_tx_ucast] +
+ ctr[ksz9477_tx_pause];
+ mac_stats->SingleCollisionFrames = ctr[ksz9477_tx_single_col];
+ mac_stats->MultipleCollisionFrames = ctr[ksz9477_tx_mult_col];
+ mac_stats->FramesReceivedOK = ctr[ksz9477_rx_mcast] +
+ ctr[ksz9477_rx_bcast] +
+ ctr[ksz9477_rx_ucast] +
+ ctr[ksz9477_rx_pause];
+ mac_stats->FrameCheckSequenceErrors = ctr[ksz9477_rx_crc_err];
+ mac_stats->AlignmentErrors = ctr[ksz9477_rx_align_err];
+ mac_stats->OctetsTransmittedOK = ctr[ksz9477_tx_total_col];
+ mac_stats->FramesWithDeferredXmissions = ctr[ksz9477_tx_deferred];
+ mac_stats->LateCollisions = ctr[ksz9477_tx_late_col];
+ mac_stats->FramesAbortedDueToXSColls = ctr[ksz9477_tx_exc_col];
+ mac_stats->MulticastFramesXmittedOK = ctr[ksz9477_tx_mcast];
+ mac_stats->BroadcastFramesXmittedOK = ctr[ksz9477_tx_bcast];
+ mac_stats->MulticastFramesReceivedOK = ctr[ksz9477_rx_mcast];
+ mac_stats->BroadcastFramesReceivedOK = ctr[ksz9477_rx_bcast];
+ mac_stats->InRangeLengthErrors = ctr[ksz9477_rx_oversize];
+
+ mib->cnt_ptr = 0;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/microchip/ksz_ethtool.h
index 18dc155d60b9..2dcfe8922b4e 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.h
+++ b/drivers/net/dsa/microchip/ksz_ethtool.h
@@ -13,10 +13,14 @@ void ksz8_get_rmon_stats(struct ksz_device *dev, int port,
const struct ethtool_rmon_hist_range **ranges);
void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
+void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_mac_stats *mac_stats);

void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges);
void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,
struct ethtool_eth_ctrl_stats *ctrl_stats);
+void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_mac_stats *mac_stats);
#endif
--
2.34.1

2022-11-30 14:04:57

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 5/5] net: dsa: microchip: remove num_alus variable

Remove num_alus variable from ksz_chip_data structure since
it is unused now.

Signed-off-by: Rakesh Sankaranarayanan <[email protected]>
---
drivers/net/dsa/microchip/ksz_common.c | 16 ----------------
drivers/net/dsa/microchip/ksz_common.h | 1 -
2 files changed, 17 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 0f3925d0c668..3e616f1e71b9 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1048,7 +1048,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ8563_CHIP_ID,
.dev_name = "KSZ8563",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x07, /* can be configured as cpu port */
.port_cnt = 3, /* total port count */
@@ -1075,7 +1074,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ8795_CHIP_ID,
.dev_name = "KSZ8795",
.num_vlans = 4096,
- .num_alus = 0,
.num_statics = 8,
.cpu_ports = 0x10, /* can be configured as cpu port */
.port_cnt = 5, /* total cpu and user ports */
@@ -1113,7 +1111,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ8794_CHIP_ID,
.dev_name = "KSZ8794",
.num_vlans = 4096,
- .num_alus = 0,
.num_statics = 8,
.cpu_ports = 0x10, /* can be configured as cpu port */
.port_cnt = 5, /* total cpu and user ports */
@@ -1137,7 +1134,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ8765_CHIP_ID,
.dev_name = "KSZ8765",
.num_vlans = 4096,
- .num_alus = 0,
.num_statics = 8,
.cpu_ports = 0x10, /* can be configured as cpu port */
.port_cnt = 5, /* total cpu and user ports */
@@ -1161,7 +1157,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ8830_CHIP_ID,
.dev_name = "KSZ8863/KSZ8873",
.num_vlans = 16,
- .num_alus = 0,
.num_statics = 8,
.cpu_ports = 0x4, /* can be configured as cpu port */
.port_cnt = 3,
@@ -1181,7 +1176,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9477_CHIP_ID,
.dev_name = "KSZ9477",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x7F, /* can be configured as cpu port */
.port_cnt = 7, /* total physical port count */
@@ -1213,7 +1207,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9896_CHIP_ID,
.dev_name = "KSZ9896",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x3F, /* can be configured as cpu port */
.port_cnt = 6, /* total physical port count */
@@ -1245,7 +1238,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9897_CHIP_ID,
.dev_name = "KSZ9897",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x7F, /* can be configured as cpu port */
.port_cnt = 7, /* total physical port count */
@@ -1275,7 +1267,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9893_CHIP_ID,
.dev_name = "KSZ9893",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x07, /* can be configured as cpu port */
.port_cnt = 3, /* total port count */
@@ -1300,7 +1291,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9563_CHIP_ID,
.dev_name = "KSZ9563",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x07, /* can be configured as cpu port */
.port_cnt = 3, /* total port count */
@@ -1325,7 +1315,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = KSZ9567_CHIP_ID,
.dev_name = "KSZ9567",
.num_vlans = 4096,
- .num_alus = 4096,
.num_statics = 16,
.cpu_ports = 0x7F, /* can be configured as cpu port */
.port_cnt = 7, /* total physical port count */
@@ -1355,7 +1344,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = LAN9370_CHIP_ID,
.dev_name = "LAN9370",
.num_vlans = 4096,
- .num_alus = 1024,
.num_statics = 256,
.cpu_ports = 0x10, /* can be configured as cpu port */
.port_cnt = 5, /* total physical port count */
@@ -1379,7 +1367,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = LAN9371_CHIP_ID,
.dev_name = "LAN9371",
.num_vlans = 4096,
- .num_alus = 1024,
.num_statics = 256,
.cpu_ports = 0x30, /* can be configured as cpu port */
.port_cnt = 6, /* total physical port count */
@@ -1403,7 +1390,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = LAN9372_CHIP_ID,
.dev_name = "LAN9372",
.num_vlans = 4096,
- .num_alus = 1024,
.num_statics = 256,
.cpu_ports = 0x30, /* can be configured as cpu port */
.port_cnt = 8, /* total physical port count */
@@ -1431,7 +1417,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = LAN9373_CHIP_ID,
.dev_name = "LAN9373",
.num_vlans = 4096,
- .num_alus = 1024,
.num_statics = 256,
.cpu_ports = 0x38, /* can be configured as cpu port */
.port_cnt = 5, /* total physical port count */
@@ -1459,7 +1444,6 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.chip_id = LAN9374_CHIP_ID,
.dev_name = "LAN9374",
.num_vlans = 4096,
- .num_alus = 1024,
.num_statics = 256,
.cpu_ports = 0x30, /* can be configured as cpu port */
.port_cnt = 8, /* total physical port count */
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index c253d761b62b..359148fb9097 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -41,7 +41,6 @@ struct ksz_chip_data {
u32 chip_id;
const char *dev_name;
int num_vlans;
- int num_alus;
int num_statics;
int cpu_ports;
int port_cnt;
--
2.34.1

2022-11-30 14:06:35

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 1/5] net: dsa: microchip: add rmon grouping for ethtool statistics

Add support for ethtool standard device statistics grouping. Support rmon
statistics grouping using rmon groups parameter in ethtool command. rmon
provides packet size based range grouping. Common mib parameters are used
across all KSZ series swtches for packet size statistics, except for
KSZ8830. KSZ series have mib counters for packets with size:
- less than 64 Bytes,
- 65 to 127 Bytes,
- 128 to 255 Bytes,
- 256 to 511 Bytes,
- 512 to 1023 Bytes,
- 1024 to 1522 Bytes,
- 1523 to 2000 Bytes and
- More than 2001 Bytes
KSZ8830 have mib counters upto 1024-1522 range only. Since no other change,
common range used across all KSZ series, but used upto only upto 1024-1522
for KSZ8830.

Signed-off-by: Rakesh Sankaranarayanan <[email protected]>
---
drivers/net/dsa/microchip/Makefile | 1 +
drivers/net/dsa/microchip/ksz_common.c | 15 ++
drivers/net/dsa/microchip/ksz_common.h | 3 +
drivers/net/dsa/microchip/ksz_ethtool.c | 178 ++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 18 +++
5 files changed, 215 insertions(+)
create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.c
create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.h

diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip/Makefile
index 28873559efc2..413a706a47fb 100644
--- a/drivers/net/dsa/microchip/Makefile
+++ b/drivers/net/dsa/microchip/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON) += ksz_switch.o
ksz_switch-objs := ksz_common.o
+ksz_switch-objs += ksz_ethtool.o
ksz_switch-objs += ksz9477.o
ksz_switch-objs += ksz8795.o
ksz_switch-objs += lan937x_main.o
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 8c8db315317d..7a9d7ef818a7 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -24,6 +24,7 @@
#include <net/switchdev.h>

#include "ksz_common.h"
+#include "ksz_ethtool.h"
#include "ksz8.h"
#include "ksz9477.h"
#include "lan937x.h"
@@ -157,6 +158,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.r_mib_pkt = ksz8_r_mib_pkt,
.freeze_mib = ksz8_freeze_mib,
.port_init_cnt = ksz8_port_init_cnt,
+ .get_rmon_stats = ksz8_get_rmon_stats,
.fdb_dump = ksz8_fdb_dump,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
@@ -194,6 +196,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
.r_mib_stat64 = ksz_r_mib_stats64,
.freeze_mib = ksz9477_freeze_mib,
.port_init_cnt = ksz9477_port_init_cnt,
+ .get_rmon_stats = ksz9477_get_rmon_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -230,6 +233,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.r_mib_stat64 = ksz_r_mib_stats64,
.freeze_mib = ksz9477_freeze_mib,
.port_init_cnt = ksz9477_port_init_cnt,
+ .get_rmon_stats = ksz9477_get_rmon_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -1609,6 +1613,16 @@ static void ksz_get_pause_stats(struct dsa_switch *ds, int port,
spin_unlock(&mib->stats64_lock);
}

+static void ksz_get_rmon_stats(struct dsa_switch *ds, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ struct ksz_device *dev = ds->priv;
+
+ if (dev->dev_ops->get_rmon_stats)
+ dev->dev_ops->get_rmon_stats(dev, port, rmon_stats, ranges);
+}
+
static void ksz_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *buf)
{
@@ -2859,6 +2873,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.port_mirror_del = ksz_port_mirror_del,
.get_stats64 = ksz_get_stats64,
.get_pause_stats = ksz_get_pause_stats,
+ .get_rmon_stats = ksz_get_rmon_stats,
.port_change_mtu = ksz_change_mtu,
.port_max_mtu = ksz_max_mtu,
};
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index c6726cbd5465..ad6d196d2927 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -339,6 +339,9 @@ struct ksz_dev_ops {
int (*reset)(struct ksz_device *dev);
int (*init)(struct ksz_device *dev);
void (*exit)(struct ksz_device *dev);
+ void (*get_rmon_stats)(struct ksz_device *dev, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges);
};

struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
new file mode 100644
index 000000000000..7e1f1b4d1e98
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_ethtool.c
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Microchip KSZ series ethtool statistics
+ *
+ * Copyright (C) 2022 Microchip Technology Inc.
+ */
+
+#include "ksz_common.h"
+#include "ksz_ethtool.h"
+
+enum ksz8_mib_entry {
+ ksz8_rx,
+ ksz8_rx_hi,
+ ksz8_rx_undersize,
+ ksz8_rx_fragments,
+ ksz8_rx_oversize,
+ ksz8_rx_jabbers,
+ ksz8_rx_symbol_err,
+ ksz8_rx_crc_err,
+ ksz8_rx_align_err,
+ ksz8_rx_mac_ctrl,
+ ksz8_rx_pause,
+ ksz8_rx_bcast,
+ ksz8_rx_mcast,
+ ksz8_rx_ucast,
+ ksz8_rx_64_or_less,
+ ksz8_rx_65_127,
+ ksz8_rx_128_255,
+ ksz8_rx_256_511,
+ ksz8_rx_512_1023,
+ ksz8_rx_1024_1522,
+ ksz8_tx,
+ ksz8_tx_hi,
+ ksz8_tx_late_col,
+ ksz8_tx_pause,
+ ksz8_tx_bcast,
+ ksz8_tx_mcast,
+ ksz8_tx_ucast,
+ ksz8_tx_deferred,
+ ksz8_tx_total_col,
+ ksz8_tx_exc_col,
+ ksz8_tx_single_col,
+ ksz8_tx_mult_col,
+ ksz8_rx_discards = 0x100,
+ ksz8_tx_discards,
+};
+
+enum ksz9477_mib_entry {
+ ksz9477_rx_hi,
+ ksz9477_rx_undersize,
+ ksz9477_rx_fragments,
+ ksz9477_rx_oversize,
+ ksz9477_rx_jabbers,
+ ksz9477_rx_symbol_err,
+ ksz9477_rx_crc_err,
+ ksz9477_rx_align_err,
+ ksz9477_rx_mac_ctrl,
+ ksz9477_rx_pause,
+ ksz9477_rx_bcast,
+ ksz9477_rx_mcast,
+ ksz9477_rx_ucast,
+ ksz9477_rx_64_or_less,
+ ksz9477_rx_65_127,
+ ksz9477_rx_128_255,
+ ksz9477_rx_256_511,
+ ksz9477_rx_512_1023,
+ ksz9477_rx_1024_1522,
+ ksz9477_rx_1523_2000,
+ ksz9477_rx_2001,
+ ksz9477_tx_hi,
+ ksz9477_tx_late_col,
+ ksz9477_tx_pause,
+ ksz9477_tx_bcast,
+ ksz9477_tx_mcast,
+ ksz9477_tx_ucast,
+ ksz9477_tx_deferred,
+ ksz9477_tx_total_col,
+ ksz9477_tx_exc_col,
+ ksz9477_tx_single_col,
+ ksz9477_tx_mult_col,
+ ksz9477_rx_total = 0x80,
+ ksz9477_tx_total,
+ ksz9477_rx_discards,
+ ksz9477_tx_discards,
+};
+
+static const struct ethtool_rmon_hist_range ksz_rmon_ranges[] = {
+ { 0, 64 },
+ { 65, 127 },
+ { 128, 255 },
+ { 256, 511 },
+ { 512, 1023 },
+ { 1024, 1522 },
+ { 1523, 2000 },
+ { 2001, 9000 },
+ {}
+};
+
+#define KSZ8_HIST_LEN 6
+#define KSZ9477_HIST_LEN 8
+
+void ksz8_get_rmon_stats(struct ksz_device *dev, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+ u8 i;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz8_rx_undersize];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_undersize, NULL, cnt);
+ rmon_stats->undersize_pkts = *cnt;
+
+ cnt = &mib->counters[ksz8_rx_oversize];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_oversize, NULL, cnt);
+ rmon_stats->oversize_pkts = *cnt;
+
+ cnt = &mib->counters[ksz8_rx_fragments];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_fragments, NULL, cnt);
+ rmon_stats->fragments = *cnt;
+
+ cnt = &mib->counters[ksz8_rx_jabbers];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_jabbers, NULL, cnt);
+ rmon_stats->jabbers = *cnt;
+
+ for (i = 0; i < KSZ8_HIST_LEN; i++) {
+ cnt = &mib->counters[ksz8_rx_64_or_less + i];
+ dev->dev_ops->r_mib_pkt(dev, port, (ksz8_rx_64_or_less + i), NULL, cnt);
+ rmon_stats->hist[i] = *cnt;
+ }
+
+ mutex_unlock(&mib->cnt_mutex);
+
+ *ranges = ksz_rmon_ranges;
+}
+
+void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+ u8 i;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz9477_rx_undersize];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_undersize, NULL, cnt);
+ rmon_stats->undersize_pkts = *cnt;
+
+ cnt = &mib->counters[ksz9477_rx_oversize];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_oversize, NULL, cnt);
+ rmon_stats->oversize_pkts = *cnt;
+
+ cnt = &mib->counters[ksz9477_rx_fragments];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_fragments, NULL, cnt);
+ rmon_stats->fragments = *cnt;
+
+ cnt = &mib->counters[ksz9477_rx_jabbers];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_jabbers, NULL, cnt);
+ rmon_stats->jabbers = *cnt;
+
+ for (i = 0; i < KSZ9477_HIST_LEN; i++) {
+ cnt = &mib->counters[ksz9477_rx_64_or_less + i];
+ dev->dev_ops->r_mib_pkt(dev, port, (ksz9477_rx_64_or_less + i), NULL, cnt);
+ rmon_stats->hist[i] = *cnt;
+ }
+
+ mutex_unlock(&mib->cnt_mutex);
+
+ *ranges = ksz_rmon_ranges;
+}
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/microchip/ksz_ethtool.h
new file mode 100644
index 000000000000..6927e2f143f8
--- /dev/null
+++ b/drivers/net/dsa/microchip/ksz_ethtool.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Microchip KSZ series ethtool statistics
+ *
+ * Copyright (C) 2022 Microchip Technology Inc.
+ */
+
+#ifndef __KSZ_ETHTOOL_H
+#define __KSZ_ETHTOOL_H
+
+void ksz8_get_rmon_stats(struct ksz_device *dev, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges);
+
+void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
+ struct ethtool_rmon_stats *rmon_stats,
+ const struct ethtool_rmon_hist_range **ranges);
+#endif
--
2.34.1

2022-11-30 14:14:54

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: [RFC Patch net-next 2/5] net: dsa: microchip: add eth ctrl grouping for ethtool statistics

Add support for ethtool standard device statistics grouping. Support
ethernet mac ctrl statistics grouping using eth-ctrl groups parameter
in ethtool command.

Signed-off-by: Rakesh Sankaranarayanan <[email protected]>
---
drivers/net/dsa/microchip/ksz_common.c | 13 ++++++++
drivers/net/dsa/microchip/ksz_common.h | 2 ++
drivers/net/dsa/microchip/ksz_ethtool.c | 42 +++++++++++++++++++++++++
drivers/net/dsa/microchip/ksz_ethtool.h | 4 +++
4 files changed, 61 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 7a9d7ef818a7..9b13a38d553d 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -159,6 +159,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.freeze_mib = ksz8_freeze_mib,
.port_init_cnt = ksz8_port_init_cnt,
.get_rmon_stats = ksz8_get_rmon_stats,
+ .get_eth_ctrl_stats = ksz8_get_eth_ctrl_stats,
.fdb_dump = ksz8_fdb_dump,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
@@ -197,6 +198,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = {
.freeze_mib = ksz9477_freeze_mib,
.port_init_cnt = ksz9477_port_init_cnt,
.get_rmon_stats = ksz9477_get_rmon_stats,
+ .get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -234,6 +236,7 @@ static const struct ksz_dev_ops lan937x_dev_ops = {
.freeze_mib = ksz9477_freeze_mib,
.port_init_cnt = ksz9477_port_init_cnt,
.get_rmon_stats = ksz9477_get_rmon_stats,
+ .get_eth_ctrl_stats = ksz9477_get_eth_ctrl_stats,
.vlan_filtering = ksz9477_port_vlan_filtering,
.vlan_add = ksz9477_port_vlan_add,
.vlan_del = ksz9477_port_vlan_del,
@@ -1623,6 +1626,15 @@ static void ksz_get_rmon_stats(struct dsa_switch *ds, int port,
dev->dev_ops->get_rmon_stats(dev, port, rmon_stats, ranges);
}

+static void ksz_get_eth_ctrl_stats(struct dsa_switch *ds, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats)
+{
+ struct ksz_device *dev = ds->priv;
+
+ if (dev->dev_ops->get_eth_ctrl_stats)
+ dev->dev_ops->get_eth_ctrl_stats(dev, port, ctrl_stats);
+}
+
static void ksz_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *buf)
{
@@ -2874,6 +2886,7 @@ static const struct dsa_switch_ops ksz_switch_ops = {
.get_stats64 = ksz_get_stats64,
.get_pause_stats = ksz_get_pause_stats,
.get_rmon_stats = ksz_get_rmon_stats,
+ .get_eth_ctrl_stats = ksz_get_eth_ctrl_stats,
.port_change_mtu = ksz_change_mtu,
.port_max_mtu = ksz_max_mtu,
};
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index ad6d196d2927..07627ff1a749 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -342,6 +342,8 @@ struct ksz_dev_ops {
void (*get_rmon_stats)(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges);
+ void (*get_eth_ctrl_stats)(struct ksz_device *dev, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats);
};

struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
index 7e1f1b4d1e98..4c9ca21e1806 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.c
+++ b/drivers/net/dsa/microchip/ksz_ethtool.c
@@ -138,6 +138,27 @@ void ksz8_get_rmon_stats(struct ksz_device *dev, int port,
*ranges = ksz_rmon_ranges;
}

+void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz8_tx_pause];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_tx_pause, NULL, cnt);
+ ctrl_stats->MACControlFramesTransmitted = *cnt;
+
+ cnt = &mib->counters[ksz8_rx_pause];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz8_rx_pause, NULL, cnt);
+ ctrl_stats->MACControlFramesReceived = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
+
void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges)
@@ -176,3 +197,24 @@ void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,

*ranges = ksz_rmon_ranges;
}
+
+void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats)
+{
+ struct ksz_port_mib *mib;
+ u64 *cnt;
+
+ mib = &dev->ports[port].mib;
+
+ mutex_lock(&mib->cnt_mutex);
+
+ cnt = &mib->counters[ksz9477_tx_pause];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_tx_pause, NULL, cnt);
+ ctrl_stats->MACControlFramesTransmitted = *cnt;
+
+ cnt = &mib->counters[ksz9477_rx_pause];
+ dev->dev_ops->r_mib_pkt(dev, port, ksz9477_rx_pause, NULL, cnt);
+ ctrl_stats->MACControlFramesReceived = *cnt;
+
+ mutex_unlock(&mib->cnt_mutex);
+}
diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/microchip/ksz_ethtool.h
index 6927e2f143f8..18dc155d60b9 100644
--- a/drivers/net/dsa/microchip/ksz_ethtool.h
+++ b/drivers/net/dsa/microchip/ksz_ethtool.h
@@ -11,8 +11,12 @@
void ksz8_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges);
+void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats);

void ksz9477_get_rmon_stats(struct ksz_device *dev, int port,
struct ethtool_rmon_stats *rmon_stats,
const struct ethtool_rmon_hist_range **ranges);
+void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port,
+ struct ethtool_eth_ctrl_stats *ctrl_stats);
#endif
--
2.34.1

2022-12-02 05:15:42

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [RFC Patch net-next 3/5] net: dsa: microchip: add eth mac grouping for ethtool statistics

On Wed, 30 Nov 2022 18:59:00 +0530 Rakesh Sankaranarayanan wrote:
> + mac_stats->FramesTransmittedOK = ctr[ksz9477_tx_mcast] +
> + ctr[ksz9477_tx_bcast] +
> + ctr[ksz9477_tx_ucast] +
> + ctr[ksz9477_tx_pause];

do control frames count towards FramesTransmittedOK?
Please check the standard I don't recall.

> + mac_stats->SingleCollisionFrames = ctr[ksz9477_tx_single_col];
> + mac_stats->MultipleCollisionFrames = ctr[ksz9477_tx_mult_col];
> + mac_stats->FramesReceivedOK = ctr[ksz9477_rx_mcast] +
> + ctr[ksz9477_rx_bcast] +
> + ctr[ksz9477_rx_ucast] +
> + ctr[ksz9477_rx_pause];
> + mac_stats->FrameCheckSequenceErrors = ctr[ksz9477_rx_crc_err];
> + mac_stats->AlignmentErrors = ctr[ksz9477_rx_align_err];
> + mac_stats->OctetsTransmittedOK = ctr[ksz9477_tx_total_col];

OctetsTransmittedOK = ksz9477_tx_total_col[lisons] ?

> + mac_stats->InRangeLengthErrors = ctr[ksz9477_rx_oversize];

You use the same counter for RMON oversize statistic, the two
definitely have different semantics, please check the standard
and the datasheet.

Remember that you don't have to fill in all the stats, if the HW does
not maintain a matching statistic - leave the field be. Kernel will
not report to user space unset fields.

2022-12-02 12:46:22

by Rakesh Sankaranarayanan

[permalink] [raw]
Subject: Re: [RFC Patch net-next 3/5] net: dsa: microchip: add eth mac grouping for ethtool statistics

Hi Jakub,

Thanks for the review comment.

On Thu, 2022-12-01 at 20:02 -0800, Jakub Kicinski wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
>
> On Wed, 30 Nov 2022 18:59:00 +0530 Rakesh Sankaranarayanan wrote:
> > +     mac_stats->FramesTransmittedOK = ctr[ksz9477_tx_mcast] +
> > +                                      ctr[ksz9477_tx_bcast] +
> > +                                      ctr[ksz9477_tx_ucast] +
> > +                                      ctr[ksz9477_tx_pause];
>
> do control frames count towards FramesTransmittedOK?
> Please check the standard I don't recall.
>
Yeah, I will check with the documentation.

> > +     mac_stats->SingleCollisionFrames =
> > ctr[ksz9477_tx_single_col];
> > +     mac_stats->MultipleCollisionFrames =
> > ctr[ksz9477_tx_mult_col];
> > +     mac_stats->FramesReceivedOK = ctr[ksz9477_rx_mcast] +
> > +                                   ctr[ksz9477_rx_bcast] +
> > +                                   ctr[ksz9477_rx_ucast] +
> > +                                   ctr[ksz9477_rx_pause];
> > +     mac_stats->FrameCheckSequenceErrors =
> > ctr[ksz9477_rx_crc_err];
> > +     mac_stats->AlignmentErrors = ctr[ksz9477_rx_align_err];
> > +     mac_stats->OctetsTransmittedOK = ctr[ksz9477_tx_total_col];
>
> OctetsTransmittedOK = ksz9477_tx_total_col[lisons] ?
>
Sorry about this. It should be ksz9477_tx_total. I will review all the
parameters again for avoiding such mistakes.

> > +     mac_stats->InRangeLengthErrors = ctr[ksz9477_rx_oversize];
>
> You use the same counter for RMON oversize statistic, the two
> definitely have different semantics, please check the standard
> and the datasheet.
>
> Remember that you don't have to fill in all the stats, if the HW does
> not maintain a matching statistic - leave the field be. Kernel will
> not report to user space unset fields.

Sure Jacub, I will review my code against documentation and submit the
updated revision.

Thanks,
Rakesh S

2022-12-07 13:26:17

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [RFC Patch net-next 3/5] net: dsa: microchip: add eth mac grouping for ethtool statistics

On Fri, Dec 02, 2022 at 11:53:33AM +0000, [email protected] wrote:
> Hi Jakub,
>
> Thanks for the review comment.
>
> On Thu, 2022-12-01 at 20:02 -0800, Jakub Kicinski wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you
> > know the content is safe
> >
> > On Wed, 30 Nov 2022 18:59:00 +0530 Rakesh Sankaranarayanan wrote:
> > > +???? mac_stats->FramesTransmittedOK = ctr[ksz9477_tx_mcast] +
> > > +????????????????????????????????????? ctr[ksz9477_tx_bcast] +
> > > +????????????????????????????????????? ctr[ksz9477_tx_ucast] +
> > > +????????????????????????????????????? ctr[ksz9477_tx_pause];
> >
> > do control frames count towards FramesTransmittedOK?
> > Please check the standard I don't recall.
> >
> Yeah, I will check with the documentation.

Oleksij said that the hardware counts pause frames for the byte
counters, so at least for consistency, they should be counted in frame
counters too.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

2022-12-07 13:26:40

by Vladimir Oltean

[permalink] [raw]
Subject: Re: [RFC Patch net-next 1/5] net: dsa: microchip: add rmon grouping for ethtool statistics

On Wed, Nov 30, 2022 at 06:58:58PM +0530, Rakesh Sankaranarayanan wrote:
> diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/microchip/ksz_ethtool.c
> new file mode 100644
> index 000000000000..7e1f1b4d1e98
> --- /dev/null
> +++ b/drivers/net/dsa/microchip/ksz_ethtool.c
> @@ -0,0 +1,178 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Microchip KSZ series ethtool statistics
> + *
> + * Copyright (C) 2022 Microchip Technology Inc.
> + */
> +
> +#include "ksz_common.h"
> +#include "ksz_ethtool.h"
> +
> +enum ksz8_mib_entry {
> + ksz8_rx,
> + ksz8_rx_hi,
> + ksz8_rx_undersize,
> + ksz8_rx_fragments,
> + ksz8_rx_oversize,
> + ksz8_rx_jabbers,
> + ksz8_rx_symbol_err,
> + ksz8_rx_crc_err,
> + ksz8_rx_align_err,
> + ksz8_rx_mac_ctrl,
> + ksz8_rx_pause,
> + ksz8_rx_bcast,
> + ksz8_rx_mcast,
> + ksz8_rx_ucast,
> + ksz8_rx_64_or_less,
> + ksz8_rx_65_127,
> + ksz8_rx_128_255,
> + ksz8_rx_256_511,
> + ksz8_rx_512_1023,
> + ksz8_rx_1024_1522,
> + ksz8_tx,
> + ksz8_tx_hi,
> + ksz8_tx_late_col,
> + ksz8_tx_pause,
> + ksz8_tx_bcast,
> + ksz8_tx_mcast,
> + ksz8_tx_ucast,
> + ksz8_tx_deferred,
> + ksz8_tx_total_col,
> + ksz8_tx_exc_col,
> + ksz8_tx_single_col,
> + ksz8_tx_mult_col,
> + ksz8_rx_discards = 0x100,
> + ksz8_tx_discards,
> +};
> +
> +enum ksz9477_mib_entry {
> + ksz9477_rx_hi,
> + ksz9477_rx_undersize,
> + ksz9477_rx_fragments,
> + ksz9477_rx_oversize,
> + ksz9477_rx_jabbers,
> + ksz9477_rx_symbol_err,
> + ksz9477_rx_crc_err,
> + ksz9477_rx_align_err,
> + ksz9477_rx_mac_ctrl,
> + ksz9477_rx_pause,
> + ksz9477_rx_bcast,
> + ksz9477_rx_mcast,
> + ksz9477_rx_ucast,
> + ksz9477_rx_64_or_less,
> + ksz9477_rx_65_127,
> + ksz9477_rx_128_255,
> + ksz9477_rx_256_511,
> + ksz9477_rx_512_1023,
> + ksz9477_rx_1024_1522,
> + ksz9477_rx_1523_2000,
> + ksz9477_rx_2001,
> + ksz9477_tx_hi,
> + ksz9477_tx_late_col,
> + ksz9477_tx_pause,
> + ksz9477_tx_bcast,
> + ksz9477_tx_mcast,
> + ksz9477_tx_ucast,
> + ksz9477_tx_deferred,
> + ksz9477_tx_total_col,
> + ksz9477_tx_exc_col,
> + ksz9477_tx_single_col,
> + ksz9477_tx_mult_col,
> + ksz9477_rx_total = 0x80,
> + ksz9477_tx_total,
> + ksz9477_rx_discards,
> + ksz9477_tx_discards,
> +};

We usually name constants using all capitals.

Can you do something to reuse the ksz_mib_names structures?