netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics
@ 2019-02-06 20:45 Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 1/4] net: dsa: bcm_sf2: Remove stats mutex Florian Fainelli
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-02-06 20:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, cphealy, vivien.didelot, Florian Fainelli

Hi all,

The Broadcom SF2 switch has a Compact Field Processor (CFP) which not
only can perform matching + action, but also counts the number of times
a rule has been hit. This is invaluable while debugging when/if rules
are not matched.

Florian Fainelli (4):
  net: dsa: bcm_sf2: Remove stats mutex
  net: dsa: bcm_sf2: Prepare for adding CFP statistics
  net: dsa: bcm_sf2: Add support for CFP statistics
  net: dsa: bcm_sf2: Allow looping back CFP rules

 drivers/net/dsa/bcm_sf2.c      | 39 ++++++++++++--
 drivers/net/dsa/bcm_sf2.h      |  8 +--
 drivers/net/dsa/bcm_sf2_cfp.c  | 99 ++++++++++++++++++++++++++++++++--
 drivers/net/dsa/bcm_sf2_regs.h |  4 ++
 4 files changed, 140 insertions(+), 10 deletions(-)

-- 
2.17.1


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

* [PATCH net-next 1/4] net: dsa: bcm_sf2: Remove stats mutex
  2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
@ 2019-02-06 20:45 ` Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 2/4] net: dsa: bcm_sf2: Prepare for adding CFP statistics Florian Fainelli
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-02-06 20:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, cphealy, vivien.didelot, Florian Fainelli

We no longer need a dedicated statistics mutex since we leverage
b53_common for statistics now.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/bcm_sf2.c | 1 -
 drivers/net/dsa/bcm_sf2.h | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 361fbde76654..a97b18595be9 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1062,7 +1062,6 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
 	dev_set_drvdata(&pdev->dev, priv);
 
 	spin_lock_init(&priv->indir_lock);
-	mutex_init(&priv->stats_mutex);
 	mutex_init(&priv->cfp.lock);
 	INIT_LIST_HEAD(&priv->cfp.rules_list);
 
diff --git a/drivers/net/dsa/bcm_sf2.h b/drivers/net/dsa/bcm_sf2.h
index faaef320ec48..83e1d8001447 100644
--- a/drivers/net/dsa/bcm_sf2.h
+++ b/drivers/net/dsa/bcm_sf2.h
@@ -87,9 +87,6 @@ struct bcm_sf2_priv {
 	/* Backing b53_device */
 	struct b53_device		*dev;
 
-	/* Mutex protecting access to the MIB counters */
-	struct mutex			stats_mutex;
-
 	struct bcm_sf2_hw_params	hw_params;
 
 	struct bcm_sf2_port_status	port_sts[DSA_MAX_PORTS];
-- 
2.17.1


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

* [PATCH net-next 2/4] net: dsa: bcm_sf2: Prepare for adding CFP statistics
  2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 1/4] net: dsa: bcm_sf2: Remove stats mutex Florian Fainelli
@ 2019-02-06 20:45 ` Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 3/4] net: dsa: bcm_sf2: Add support for " Florian Fainelli
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-02-06 20:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, cphealy, vivien.didelot, Florian Fainelli

In preparation for adding CFP statistics, we will need to overlay the
standard B53 statistics, so create specific bcm_sf2_sw_* functions to
call into their b53_common.c counterpart.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/bcm_sf2.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index a97b18595be9..ce5f4260ea1a 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -894,12 +894,30 @@ static const struct b53_io_ops bcm_sf2_io_ops = {
 	.write64 = bcm_sf2_core_write64,
 };
 
+static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port,
+				   u32 stringset, uint8_t *data)
+{
+	b53_get_strings(ds, port, stringset, data);
+}
+
+static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,
+					 uint64_t *data)
+{
+	b53_get_ethtool_stats(ds, port, data);
+}
+
+static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port,
+				     int sset)
+{
+	return b53_get_sset_count(ds, port, sset);
+}
+
 static const struct dsa_switch_ops bcm_sf2_ops = {
 	.get_tag_protocol	= b53_get_tag_protocol,
 	.setup			= bcm_sf2_sw_setup,
-	.get_strings		= b53_get_strings,
-	.get_ethtool_stats	= b53_get_ethtool_stats,
-	.get_sset_count		= b53_get_sset_count,
+	.get_strings		= bcm_sf2_sw_get_strings,
+	.get_ethtool_stats	= bcm_sf2_sw_get_ethtool_stats,
+	.get_sset_count		= bcm_sf2_sw_get_sset_count,
 	.get_ethtool_phy_stats	= b53_get_ethtool_phy_stats,
 	.get_phy_flags		= bcm_sf2_sw_get_phy_flags,
 	.phylink_validate	= bcm_sf2_sw_validate,
-- 
2.17.1


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

* [PATCH net-next 3/4] net: dsa: bcm_sf2: Add support for CFP statistics
  2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 1/4] net: dsa: bcm_sf2: Remove stats mutex Florian Fainelli
  2019-02-06 20:45 ` [PATCH net-next 2/4] net: dsa: bcm_sf2: Prepare for adding CFP statistics Florian Fainelli
@ 2019-02-06 20:45 ` Florian Fainelli
  2019-02-06 20:46 ` [PATCH net-next 4/4] net: dsa: bcm_sf2: Allow looping back CFP rules Florian Fainelli
  2019-02-09  6:11 ` [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-02-06 20:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, cphealy, vivien.didelot, Florian Fainelli

Return CFP policer statistics (Green, Yellow or Red) as part of the
standard ethtool statistics. This helps debug when CFP rules may not be
hit (0 counter).

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/bcm_sf2.c      | 16 ++++++-
 drivers/net/dsa/bcm_sf2.h      |  5 ++
 drivers/net/dsa/bcm_sf2_cfp.c  | 88 ++++++++++++++++++++++++++++++++++
 drivers/net/dsa/bcm_sf2_regs.h |  4 ++
 4 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index ce5f4260ea1a..5193da67dcdc 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -897,19 +897,33 @@ static const struct b53_io_ops bcm_sf2_io_ops = {
 static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port,
 				   u32 stringset, uint8_t *data)
 {
+	int cnt = b53_get_sset_count(ds, port, stringset);
+
 	b53_get_strings(ds, port, stringset, data);
+	bcm_sf2_cfp_get_strings(ds, port, stringset,
+				data + cnt * ETH_GSTRING_LEN);
 }
 
 static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,
 					 uint64_t *data)
 {
+	int cnt = b53_get_sset_count(ds, port, ETH_SS_STATS);
+
 	b53_get_ethtool_stats(ds, port, data);
+	bcm_sf2_cfp_get_ethtool_stats(ds, port, data + cnt);
 }
 
 static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port,
 				     int sset)
 {
-	return b53_get_sset_count(ds, port, sset);
+	int cnt = b53_get_sset_count(ds, port, sset);
+
+	if (cnt < 0)
+		return cnt;
+
+	cnt += bcm_sf2_cfp_get_sset_count(ds, port, sset);
+
+	return cnt;
 }
 
 static const struct dsa_switch_ops bcm_sf2_ops = {
diff --git a/drivers/net/dsa/bcm_sf2.h b/drivers/net/dsa/bcm_sf2.h
index 83e1d8001447..eb3655bea467 100644
--- a/drivers/net/dsa/bcm_sf2.h
+++ b/drivers/net/dsa/bcm_sf2.h
@@ -213,5 +213,10 @@ int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
 int bcm_sf2_cfp_rst(struct bcm_sf2_priv *priv);
 void bcm_sf2_cfp_exit(struct dsa_switch *ds);
 int bcm_sf2_cfp_resume(struct dsa_switch *ds);
+void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port,
+			     u32 stringset, uint8_t *data);
+void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
+				   uint64_t *data);
+int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset);
 
 #endif /* __BCM_SF2_H */
diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
index 6d8059dc77b7..8747d18297fa 100644
--- a/drivers/net/dsa/bcm_sf2_cfp.c
+++ b/drivers/net/dsa/bcm_sf2_cfp.c
@@ -1201,3 +1201,91 @@ int bcm_sf2_cfp_resume(struct dsa_switch *ds)
 
 	return ret;
 }
+
+static const struct bcm_sf2_cfp_stat {
+	unsigned int offset;
+	unsigned int ram_loc;
+	const char *name;
+} bcm_sf2_cfp_stats[] = {
+	{
+		.offset = CORE_STAT_GREEN_CNTR,
+		.ram_loc = GREEN_STAT_RAM,
+		.name = "Green"
+	},
+	{
+		.offset = CORE_STAT_YELLOW_CNTR,
+		.ram_loc = YELLOW_STAT_RAM,
+		.name = "Yellow"
+	},
+	{
+		.offset = CORE_STAT_RED_CNTR,
+		.ram_loc = RED_STAT_RAM,
+		.name = "Red"
+	},
+};
+
+void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port,
+			     u32 stringset, uint8_t *data)
+{
+	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
+	unsigned int s = ARRAY_SIZE(bcm_sf2_cfp_stats);
+	char buf[ETH_GSTRING_LEN];
+	unsigned int i, j, iter;
+
+	if (stringset != ETH_SS_STATS)
+		return;
+
+	for (i = 1; i < priv->num_cfp_rules; i++) {
+		for (j = 0; j < s; j++) {
+			snprintf(buf, sizeof(buf),
+				 "CFP%03d_%sCntr",
+				 i, bcm_sf2_cfp_stats[j].name);
+			iter = (i - 1) * s + j;
+			strlcpy(data + iter * ETH_GSTRING_LEN,
+				buf, ETH_GSTRING_LEN);
+		}
+	}
+}
+
+void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
+				   uint64_t *data)
+{
+	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
+	unsigned int s = ARRAY_SIZE(bcm_sf2_cfp_stats);
+	const struct bcm_sf2_cfp_stat *stat;
+	unsigned int i, j, iter;
+	struct cfp_rule *rule;
+	int ret;
+
+	mutex_lock(&priv->cfp.lock);
+	for (i = 1; i < priv->num_cfp_rules; i++) {
+		rule = bcm_sf2_cfp_rule_find(priv, port, i);
+		if (!rule)
+			continue;
+
+		for (j = 0; j < s; j++) {
+			stat = &bcm_sf2_cfp_stats[j];
+
+			bcm_sf2_cfp_rule_addr_set(priv, i);
+			ret = bcm_sf2_cfp_op(priv, stat->ram_loc | OP_SEL_READ);
+			if (ret)
+				continue;
+
+			iter = (i - 1) * s + j;
+			data[iter] = core_readl(priv, stat->offset);
+		}
+
+	}
+	mutex_unlock(&priv->cfp.lock);
+}
+
+int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset)
+{
+	struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
+
+	if (sset != ETH_SS_STATS)
+		return 0;
+
+	/* 3 counters per CFP rules */
+	return (priv->num_cfp_rules - 1) * ARRAY_SIZE(bcm_sf2_cfp_stats);
+}
diff --git a/drivers/net/dsa/bcm_sf2_regs.h b/drivers/net/dsa/bcm_sf2_regs.h
index 0a1e530d52b7..67f056206f37 100644
--- a/drivers/net/dsa/bcm_sf2_regs.h
+++ b/drivers/net/dsa/bcm_sf2_regs.h
@@ -400,6 +400,10 @@ enum bcm_sf2_reg_offs {
 #define CORE_RATE_METER6		0x281e0
 #define  CIR_REF_CNT_MASK		0x7ffff
 
+#define CORE_STAT_GREEN_CNTR		0x28200
+#define CORE_STAT_YELLOW_CNTR		0x28210
+#define CORE_STAT_RED_CNTR		0x28220
+
 #define CORE_CFP_CTL_REG		0x28400
 #define  CFP_EN_MAP_MASK		0x1ff
 
-- 
2.17.1


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

* [PATCH net-next 4/4] net: dsa: bcm_sf2: Allow looping back CFP rules
  2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
                   ` (2 preceding siblings ...)
  2019-02-06 20:45 ` [PATCH net-next 3/4] net: dsa: bcm_sf2: Add support for " Florian Fainelli
@ 2019-02-06 20:46 ` Florian Fainelli
  2019-02-09  6:11 ` [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-02-06 20:46 UTC (permalink / raw)
  To: netdev; +Cc: davem, cphealy, vivien.didelot, Florian Fainelli

When the source and destination port of a CFP rule match, we must set
the loopback bit enable to allow that, otherwise the frame is discarded.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/dsa/bcm_sf2_cfp.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c
index 8747d18297fa..0b9ca4bdf47e 100644
--- a/drivers/net/dsa/bcm_sf2_cfp.c
+++ b/drivers/net/dsa/bcm_sf2_cfp.c
@@ -213,6 +213,7 @@ static inline unsigned int bcm_sf2_cfp_rule_size(struct bcm_sf2_priv *priv)
 
 static int bcm_sf2_cfp_act_pol_set(struct bcm_sf2_priv *priv,
 				   unsigned int rule_index,
+				   int src_port,
 				   unsigned int port_num,
 				   unsigned int queue_num,
 				   bool fwd_map_change)
@@ -230,6 +231,10 @@ static int bcm_sf2_cfp_act_pol_set(struct bcm_sf2_priv *priv,
 	else
 		reg = 0;
 
+	/* Enable looping back to the original port */
+	if (src_port == port_num)
+		reg |= LOOP_BK_EN;
+
 	core_writel(priv, reg, CORE_ACT_POL_DATA0);
 
 	/* Set classification ID that needs to be put in Broadcom tag */
@@ -443,7 +448,7 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,
 	}
 
 	/* Insert into Action and policer RAMs now */
-	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index, port_num,
+	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index, port, port_num,
 				      queue_num, true);
 	if (ret)
 		goto out_err_flow_rule;
@@ -733,7 +738,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
 	}
 
 	/* Insert into Action and policer RAMs now */
-	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index[0], port_num,
+	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index[0], port, port_num,
 				      queue_num, false);
 	if (ret)
 		goto out_err_flow_rule;
@@ -795,7 +800,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
 	/* Insert into Action and policer RAMs now, set chain ID to
 	 * the one we are chained to
 	 */
-	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index[1], port_num,
+	ret = bcm_sf2_cfp_act_pol_set(priv, rule_index[1], port, port_num,
 				      queue_num, true);
 	if (ret)
 		goto out_err_flow_rule;
-- 
2.17.1


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

* Re: [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics
  2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
                   ` (3 preceding siblings ...)
  2019-02-06 20:46 ` [PATCH net-next 4/4] net: dsa: bcm_sf2: Allow looping back CFP rules Florian Fainelli
@ 2019-02-09  6:11 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2019-02-09  6:11 UTC (permalink / raw)
  To: f.fainelli; +Cc: netdev, cphealy, vivien.didelot

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Wed,  6 Feb 2019 12:45:56 -0800

> The Broadcom SF2 switch has a Compact Field Processor (CFP) which not
> only can perform matching + action, but also counts the number of times
> a rule has been hit. This is invaluable while debugging when/if rules
> are not matched.

Series applied, thanks Florian.

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

end of thread, other threads:[~2019-02-09  6:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 20:45 [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics Florian Fainelli
2019-02-06 20:45 ` [PATCH net-next 1/4] net: dsa: bcm_sf2: Remove stats mutex Florian Fainelli
2019-02-06 20:45 ` [PATCH net-next 2/4] net: dsa: bcm_sf2: Prepare for adding CFP statistics Florian Fainelli
2019-02-06 20:45 ` [PATCH net-next 3/4] net: dsa: bcm_sf2: Add support for " Florian Fainelli
2019-02-06 20:46 ` [PATCH net-next 4/4] net: dsa: bcm_sf2: Allow looping back CFP rules Florian Fainelli
2019-02-09  6:11 ` [PATCH net-next 0/4] net: dsa: bcm_sf2: Add support for CFP statistics David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).