Skip to contentSkip to conversation

net: dsa: bcm_sf2: Add support for CFP statistics

PATCH In review Florian Fainelli 2 participants 6 messages Feb 6, 2019 – Feb 9, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover net: dsa: bcm_sf2: Add support for CFP statistics

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(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 net: dsa: bcm_sf2: Remove stats mutex

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

---
 drivers/net/dsa/bcm_sf2.c | 1 -
 drivers/net/dsa/bcm_sf2.h | 3 ---
 2 files changed, 4 deletions(-)
drivers/net/dsa/bcm_sf2.c +0 -1
index 361fbde76654..a97b18595be9 100644
@@ -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);
 
drivers/net/dsa/bcm_sf2.h +0 -3
index faaef320ec48..83e1d8001447 100644
@@ -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];
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/4 net: dsa: bcm_sf2: Prepare for adding CFP statistics

In reply to 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.

---
 drivers/net/dsa/bcm_sf2.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/dsa/bcm_sf2.c +21 -3
index a97b18595be9..ce5f4260ea1a 100644
@@ -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,
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/4 net: dsa: bcm_sf2: Add support for CFP statistics

In reply to 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).

---
 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(-)
drivers/net/dsa/bcm_sf2.c +15 -1
index ce5f4260ea1a..5193da67dcdc 100644
@@ -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 = {
drivers/net/dsa/bcm_sf2.h +5 -0
index 83e1d8001447..eb3655bea467 100644
@@ -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 */
drivers/net/dsa/bcm_sf2_cfp.c +88 -0

91 lines not on this page · raw message

drivers/net/dsa/bcm_sf2_regs.h +4 -0
index 0a1e530d52b7..67f056206f37 100644
@@ -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
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/4 net: dsa: bcm_sf2: Allow looping back CFP rules

In reply to 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.

---
 drivers/net/dsa/bcm_sf2_cfp.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/dsa/bcm_sf2_cfp.c +8 -3
index 8747d18297fa..0b9ca4bdf47e 100644
@@ -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;
Signature · 1 line
2.17.1
maintainer
#5 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Wed, 6 Feb 2019 12:45:56 -0800

Quoted 4 lines

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.