Message ID | 20201211105322.7818-2-o.rempel@pengutronix.de (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | net: dsa: add stats64 support | expand |
On Fri, Dec 11, 2020 at 11:53:21AM +0100, Oleksij Rempel wrote: > Allow DSA drivers to export stats64 > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> > Reviewed-by: Vladimir Oltean <olteanv@gmail.com> > --- > include/net/dsa.h | 3 +++ > net/dsa/slave.c | 14 +++++++++++++- > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/include/net/dsa.h b/include/net/dsa.h > index 4e60d2610f20..457b89143875 100644 > --- a/include/net/dsa.h > +++ b/include/net/dsa.h > @@ -655,6 +655,9 @@ struct dsa_switch_ops { > int (*port_change_mtu)(struct dsa_switch *ds, int port, > int new_mtu); > int (*port_max_mtu)(struct dsa_switch *ds, int port); > + > + void (*get_stats64)(struct dsa_switch *ds, int port, > + struct rtnl_link_stats64 *s); Nitpick: I would have probably put it under the "ethtool hardware statistics." category, at the same time renaming it into "Port statistics counters." > }; > > #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ > diff --git a/net/dsa/slave.c b/net/dsa/slave.c > index ff2266d2b998..6e1a4dc18a97 100644 > --- a/net/dsa/slave.c > +++ b/net/dsa/slave.c > @@ -1602,6 +1602,18 @@ static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev) > return dp->ds->devlink ? &dp->devlink_port : NULL; > } > > +static void dsa_slave_get_stats64(struct net_device *dev, > + struct rtnl_link_stats64 *s) > +{ > + struct dsa_port *dp = dsa_slave_to_port(dev); > + struct dsa_switch *ds = dp->ds; > + > + if (!ds->ops->get_stats64) > + return dev_get_tstats64(dev, s); > + > + return ds->ops->get_stats64(ds, dp->index, s); > +} > + > static const struct net_device_ops dsa_slave_netdev_ops = { > .ndo_open = dsa_slave_open, > .ndo_stop = dsa_slave_close, > @@ -1621,7 +1633,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = { > #endif > .ndo_get_phys_port_name = dsa_slave_get_phys_port_name, > .ndo_setup_tc = dsa_slave_setup_tc, > - .ndo_get_stats64 = dev_get_tstats64, > + .ndo_get_stats64 = dsa_slave_get_stats64, > .ndo_get_port_parent_id = dsa_slave_get_port_parent_id, > .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid, > .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid, > -- > 2.29.2 >
On Fri, 11 Dec 2020 11:53:21 +0100 Oleksij Rempel wrote: > +static void dsa_slave_get_stats64(struct net_device *dev, > + struct rtnl_link_stats64 *s) > +{ > + struct dsa_port *dp = dsa_slave_to_port(dev); > + struct dsa_switch *ds = dp->ds; > + > + if (!ds->ops->get_stats64) > + return dev_get_tstats64(dev, s); > + > + return ds->ops->get_stats64(ds, dp->index, s); nit: please don't return void, "else" will do just fine here
diff --git a/include/net/dsa.h b/include/net/dsa.h index 4e60d2610f20..457b89143875 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -655,6 +655,9 @@ struct dsa_switch_ops { int (*port_change_mtu)(struct dsa_switch *ds, int port, int new_mtu); int (*port_max_mtu)(struct dsa_switch *ds, int port); + + void (*get_stats64)(struct dsa_switch *ds, int port, + struct rtnl_link_stats64 *s); }; #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ diff --git a/net/dsa/slave.c b/net/dsa/slave.c index ff2266d2b998..6e1a4dc18a97 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1602,6 +1602,18 @@ static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev) return dp->ds->devlink ? &dp->devlink_port : NULL; } +static void dsa_slave_get_stats64(struct net_device *dev, + struct rtnl_link_stats64 *s) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->get_stats64) + return dev_get_tstats64(dev, s); + + return ds->ops->get_stats64(ds, dp->index, s); +} + static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_open = dsa_slave_open, .ndo_stop = dsa_slave_close, @@ -1621,7 +1633,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = { #endif .ndo_get_phys_port_name = dsa_slave_get_phys_port_name, .ndo_setup_tc = dsa_slave_setup_tc, - .ndo_get_stats64 = dev_get_tstats64, + .ndo_get_stats64 = dsa_slave_get_stats64, .ndo_get_port_parent_id = dsa_slave_get_port_parent_id, .ndo_vlan_rx_add_vid = dsa_slave_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = dsa_slave_vlan_rx_kill_vid,