All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/9] net: dsa: misc improvements
@ 2016-06-04  0:05 Florian Fainelli
  2016-06-04  0:05 ` [PATCH net-next 1/9] net: dsa: Prepare to support legacy DT binding Florian Fainelli
                   ` (13 more replies)
  0 siblings, 14 replies; 39+ messages in thread
From: Florian Fainelli @ 2016-06-04  0:05 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, vivien.didelot, john, Florian Fainelli

Hi all,

This patch series builds on top of Andrew's "New DSA bind, switches as devices"
patch set and does the following:

- add support for the old DSA binding with the new dsa_register_switch() API
  which is needed by some platforms where the Device Tree is pretty much frozen

- add a few helper functions/goodies for net/dsa/dsa2.c to be as close as possible
  from net/dsa/dsa.c in terms of what drivers can expect, in particular the slave
  MDIO bus and the enabled_port_mask and phy_mii_mask

- fix the CPU port ethtools ops to work in a multiple tree setup since we can
  no longer assume a single tree is supported

- finally conver the bcm_sf2 driver to be a true platform device driver and
  slightly rework its internal vs. external MDIO bus indirect read/writes to
  be cleaner

Florian Fainelli (9):
  net: dsa: Prepare to support legacy DT binding
  net: dsa: Add support for parsing the old binding
  net: dsa: Provide unique DSA slave MII bus names
  net: dsa: Initialize ds->enabled_port_mask and ds->phys_mii_mask
  net: dsa: Export suspend/resume functions
  net: dsa: Add initialization helper for CPU port ethtool_ops
  net: dsa: Initialize CPU port ethtool ops per tree
  net: dsa: bcm_sf2: Make it a real platform device driver
  net: dsa: bcm_sf2: Register our slave MDIO bus

 drivers/net/dsa/bcm_sf2.c | 390 +++++++++++++++++++++++++++++-----------------
 drivers/net/dsa/bcm_sf2.h |   6 +
 include/net/dsa.h         |  14 ++
 net/dsa/dsa.c             |  35 ++++-
 net/dsa/dsa2.c            | 199 ++++++++++++++++++++---
 net/dsa/dsa_priv.h        |   3 +
 net/dsa/slave.c           |  25 ++-
 7 files changed, 491 insertions(+), 181 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 39+ messages in thread
* [PATCH net-next] net: dsa: Provide CPU port statistics to master netdev
@ 2016-04-27 18:45 Florian Fainelli
  2016-04-27 19:03 ` Andrew Lunn
  2016-04-28 21:16 ` David Miller
  0 siblings, 2 replies; 39+ messages in thread
From: Florian Fainelli @ 2016-04-27 18:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, vivien.didelot, Florian Fainelli

This patch overloads the DSA master netdev, aka CPU Ethernet MAC to also
include switch-side statistics, which is useful for debugging purposes,
when the switch is not properly connected to the Ethernet MAC (duplex
mismatch, (RG)MII electrical issues etc.).

We accomplish this by retaining the original copy of the master netdev's
ethtool_ops, and just overload the 3 operations we care about:
get_sset_count, get_strings and get_ethtool_stats so as to intercept
these calls and call into the original master_netdev ethtool_ops, plus
our own.

We take this approach as opposed to providing a set of DSA helper
functions that would retrive the CPU port's statistics, because the
entire purpose of DSA is to allow unmodified Ethernet MAC drivers to be
used as CPU conduit interfaces, therefore, statistics overlay in such
drivers would simply not scale.

The new ethtool -S <iface> output would therefore look like this now:
<iface> statistics
p<2 digits cpu port number>_<switch MIB counter names>

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
Changes from RFC:

- prepend the CPU port as a prefix to make it clear what the stats are
  about, master netdev interface stats are unchanged

 include/net/dsa.h |  5 ++++
 net/dsa/slave.c   | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 2d280aba97e2..8e86af87c84f 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -111,6 +111,11 @@ struct dsa_switch_tree {
 	enum dsa_tag_protocol	tag_protocol;
 
 	/*
+	 * Original copy of the master netdev ethtool_ops
+	 */
+	struct ethtool_ops	master_ethtool_ops;
+
+	/*
 	 * The switch and port to which the CPU is attached.
 	 */
 	s8			cpu_switch;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 3b6750f5e68b..5ea8a40c8d33 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -666,6 +666,78 @@ static void dsa_slave_get_strings(struct net_device *dev,
 	}
 }
 
+static void dsa_cpu_port_get_ethtool_stats(struct net_device *dev,
+					   struct ethtool_stats *stats,
+					   uint64_t *data)
+{
+	struct dsa_switch_tree *dst = dev->dsa_ptr;
+	struct dsa_switch *ds = dst->ds[0];
+	s8 cpu_port = dst->cpu_port;
+	int count = 0;
+
+	if (dst->master_ethtool_ops.get_sset_count) {
+		count = dst->master_ethtool_ops.get_sset_count(dev,
+							       ETH_SS_STATS);
+		dst->master_ethtool_ops.get_ethtool_stats(dev, stats, data);
+	}
+
+	if (ds->drv->get_ethtool_stats)
+		ds->drv->get_ethtool_stats(ds, cpu_port, data + count);
+}
+
+static int dsa_cpu_port_get_sset_count(struct net_device *dev, int sset)
+{
+	struct dsa_switch_tree *dst = dev->dsa_ptr;
+	struct dsa_switch *ds = dst->ds[0];
+	int count = 0;
+
+	if (dst->master_ethtool_ops.get_sset_count)
+		count += dst->master_ethtool_ops.get_sset_count(dev, sset);
+
+	if (sset == ETH_SS_STATS && ds->drv->get_sset_count)
+		count += ds->drv->get_sset_count(ds);
+
+	return count;
+}
+
+static void dsa_cpu_port_get_strings(struct net_device *dev,
+				     uint32_t stringset, uint8_t *data)
+{
+	struct dsa_switch_tree *dst = dev->dsa_ptr;
+	struct dsa_switch *ds = dst->ds[0];
+	s8 cpu_port = dst->cpu_port;
+	int len = ETH_GSTRING_LEN;
+	int mcount = 0, count;
+	unsigned int i;
+	uint8_t pfx[4];
+	uint8_t *ndata;
+
+	snprintf(pfx, sizeof(pfx), "p%.2d", cpu_port);
+	/* We do not want to be NULL-terminated, since this is a prefix */
+	pfx[sizeof(pfx) - 1] = '_';
+
+	if (dst->master_ethtool_ops.get_sset_count) {
+		mcount = dst->master_ethtool_ops.get_sset_count(dev,
+								ETH_SS_STATS);
+		dst->master_ethtool_ops.get_strings(dev, stringset, data);
+	}
+
+	if (stringset == ETH_SS_STATS && ds->drv->get_strings) {
+		ndata = data + mcount * len;
+		/* This function copies ETH_GSTRINGS_LEN bytes, we will mangle
+		 * the output after to prepend our CPU port prefix we
+		 * constructed earlier
+		 */
+		ds->drv->get_strings(ds, cpu_port, ndata);
+		count = ds->drv->get_sset_count(ds);
+		for (i = 0; i < count; i++) {
+			memmove(ndata + (i * len + sizeof(pfx)),
+				ndata + i * len, len - sizeof(pfx));
+			memcpy(ndata + i * len, pfx, sizeof(pfx));
+		}
+	}
+}
+
 static void dsa_slave_get_ethtool_stats(struct net_device *dev,
 					struct ethtool_stats *stats,
 					uint64_t *data)
@@ -821,6 +893,8 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = {
 	.get_eee		= dsa_slave_get_eee,
 };
 
+static struct ethtool_ops dsa_cpu_port_ethtool_ops;
+
 static const struct net_device_ops dsa_slave_netdev_ops = {
 	.ndo_open	 	= dsa_slave_open,
 	.ndo_stop		= dsa_slave_close,
@@ -1038,6 +1112,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
 		     int port, char *name)
 {
 	struct net_device *master = ds->dst->master_netdev;
+	struct dsa_switch_tree *dst = ds->dst;
 	struct net_device *slave_dev;
 	struct dsa_slave_priv *p;
 	int ret;
@@ -1049,6 +1124,19 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
 
 	slave_dev->features = master->vlan_features;
 	slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
+	if (master->ethtool_ops != &dsa_cpu_port_ethtool_ops) {
+		memcpy(&dst->master_ethtool_ops, master->ethtool_ops,
+		       sizeof(struct ethtool_ops));
+		memcpy(&dsa_cpu_port_ethtool_ops, &dst->master_ethtool_ops,
+		       sizeof(struct ethtool_ops));
+		dsa_cpu_port_ethtool_ops.get_sset_count =
+					dsa_cpu_port_get_sset_count;
+		dsa_cpu_port_ethtool_ops.get_ethtool_stats =
+					dsa_cpu_port_get_ethtool_stats;
+		dsa_cpu_port_ethtool_ops.get_strings =
+					dsa_cpu_port_get_strings;
+		master->ethtool_ops = &dsa_cpu_port_ethtool_ops;
+	}
 	eth_hw_addr_inherit(slave_dev, master);
 	slave_dev->priv_flags |= IFF_NO_QUEUE;
 	slave_dev->netdev_ops = &dsa_slave_netdev_ops;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2016-06-06 20:13 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-04  0:05 [PATCH net-next 0/9] net: dsa: misc improvements Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 1/9] net: dsa: Prepare to support legacy DT binding Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next] net: dsa: Provide CPU port statistics to master netdev Florian Fainelli
2016-06-04  0:06   ` Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next] net: dsa: bcm_sf2: Implement FDB operations Florian Fainelli
2016-06-04  0:06   ` Florian Fainelli
2016-06-06 13:30   ` Vivien Didelot
2016-06-04  0:05 ` [PATCH net-next 2/9] net: dsa: Add support for parsing the old binding Florian Fainelli
2016-06-04 19:44   ` Andrew Lunn
2016-06-04 20:00   ` Andrew Lunn
2016-06-05 22:42     ` Florian Fainelli
2016-06-06  3:19       ` Andrew Lunn
2016-06-06 20:13         ` Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 3/9] net: dsa: Provide unique DSA slave MII bus names Florian Fainelli
2016-06-04 20:00   ` Andrew Lunn
2016-06-06 13:36   ` Vivien Didelot
2016-06-04  0:05 ` [PATCH net-next 4/9] net: dsa: Initialize ds->enabled_port_mask and ds->phys_mii_mask Florian Fainelli
2016-06-04 20:29   ` Andrew Lunn
2016-06-05 22:38     ` Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 5/9] net: dsa: Export suspend/resume functions Florian Fainelli
2016-06-04 20:30   ` Andrew Lunn
2016-06-06 13:40   ` Vivien Didelot
2016-06-04  0:05 ` [PATCH net-next 6/9] net: dsa: Add initialization helper for CPU port ethtool_ops Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 6/7] net: dsa: bcm_sf2: Make it a real platform device driver Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 7/9] net: dsa: Initialize CPU port ethtool ops per tree Florian Fainelli
2016-06-04 20:38   ` Andrew Lunn
2016-06-05 22:29     ` Florian Fainelli
2016-06-06  2:40       ` Andrew Lunn
2016-06-04  0:05 ` [PATCH net-next 7/7] net: dsa: bcm_sf2: Register our slave MDIO bus Florian Fainelli
2016-06-04 20:49   ` Andrew Lunn
2016-06-04  0:05 ` [PATCH net-next 8/9] net: dsa: bcm_sf2: Make it a real platform device driver Florian Fainelli
2016-06-04 20:55   ` Andrew Lunn
2016-06-05 22:30     ` Florian Fainelli
2016-06-04  0:05 ` [PATCH net-next 9/9] net: dsa: bcm_sf2: Register our slave MDIO bus Florian Fainelli
2016-06-04  0:10 ` [PATCH net-next 0/9] net: dsa: misc improvements Florian Fainelli
  -- strict thread matches above, loose matches on Subject: below --
2016-04-27 18:45 [PATCH net-next] net: dsa: Provide CPU port statistics to master netdev Florian Fainelli
2016-04-27 19:03 ` Andrew Lunn
2016-04-27 21:43   ` Florian Fainelli
2016-04-28 21:16 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.