net: dsa: bcm_sf2: Add support for CFP statistics
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
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
@@ -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
@@ -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
PATCH 2/4 net: dsa: bcm_sf2: Prepare for adding CFP statistics
In reply to Florian FainelliIn 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
@@ -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
PATCH 3/4 net: dsa: bcm_sf2: Add support for CFP statistics
In reply to Florian FainelliReturn 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
@@ -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
@@ -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
@@ -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
PATCH 4/4 net: dsa: bcm_sf2: Allow looping back CFP rules
In reply to Florian FainelliWhen 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
@@ -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
David Miller
maintainerFrom: 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.