On Fri, Feb 17, 2023 at 04:32:08PM +0530, Rakesh Sankaranarayanan wrote:
> +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);
> +}
These should be reported as standard pause stats as well (ethtool -I --show-pause swpN).
Hi Vlad,
On Fri, 2023-02-17 at 19:08 +0200, Vladimir Oltean wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
>
> On Fri, Feb 17, 2023 at 04:32:08PM +0530, Rakesh Sankaranarayanan
> wrote:
> > +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);
> > +}
>
> These should be reported as standard pause stats as well (ethtool -I
> --show-pause swpN).
Yes, these are reported as standards stats through get_pause_stats call
back.
static void ksz_get_pause_stats(struct dsa_switch *ds, int port,
struct ethtool_pause_stats
*pause_stats)
{
struct ksz_device *dev = ds->priv;
struct ksz_port_mib *mib;
mib = &dev->ports[port].mib;
spin_lock(&mib->stats64_lock);
memcpy(pause_stats, &mib->pause_stats, sizeof(*pause_stats));
spin_unlock(&mib->stats64_lock);
}
@@ -206,6 +206,7 @@ static const struct ksz_dev_ops ksz8_dev_ops = {
.port_init_cnt = ksz8_port_init_cnt,
.fdb_dump = ksz8_fdb_dump,
.get_rmon_stats = ksz8_get_rmon_stats,
+ .get_eth_ctrl_stats = ksz8_get_eth_ctrl_stats,
.mdb_add = ksz8_mdb_add,
.mdb_del = ksz8_mdb_del,
.vlan_filtering = ksz8_port_vlan_filtering,
@@ -244,6 +245,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,
@@ -281,6 +283,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,
@@ -1744,6 +1747,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)
{
@@ -3201,6 +3213,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,
.get_ts_info = ksz_get_ts_info,
@@ -364,6 +364,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);
@@ -139,6 +139,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)
@@ -178,3 +199,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);
+}
@@ -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