net: dsa: bcm_sf2: Restore CFP rules during system resume
authorFlorian Fainelli <f.fainelli@gmail.com>
Tue, 6 Nov 2018 20:58:39 +0000 (12:58 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 6 Nov 2018 23:05:22 +0000 (15:05 -0800)
The hardware can lose its context during system suspend, and depending
on the switch generation (7445 vs. 7278), while the rules are still
there, they will have their valid bit cleared (because that's the
fastest way for the HW to reset things). Just make sure we re-apply them
coming back from resume. The 7445 switch is an older version of the core
that has some quirky RAM technology requiring a delete then re-inser to
guarantee the RAM entries are properly latched.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/bcm_sf2.c
drivers/net/dsa/bcm_sf2.h
drivers/net/dsa/bcm_sf2_cfp.c

index 89722dbfafb81a96bad1686f4d0c5dc2fc7970eb..d8b93043b7899cbc50710e06e248d2e624214104 100644 (file)
@@ -710,6 +710,10 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds)
                return ret;
        }
 
+       ret = bcm_sf2_cfp_resume(ds);
+       if (ret)
+               return ret;
+
        if (priv->hw_params.num_gphy == 1)
                bcm_sf2_gphy_enable_set(ds, true);
 
index 03444982c25e2379381a9638b1376b369a096686..faaef320ec48ed32043c4fd07f1599b8e08beb7b 100644 (file)
@@ -215,5 +215,6 @@ int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
                      struct ethtool_rxnfc *nfc);
 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);
 
 #endif /* __BCM_SF2_H */
index 396bfa43c2e185dbaec1210d4c47b69321a9747b..5034e4f56fd5ab8114e581ccd8c4a1e8da415e96 100644 (file)
@@ -1443,3 +1443,39 @@ void bcm_sf2_cfp_exit(struct dsa_switch *ds)
        list_for_each_entry_safe_reverse(rule, n, &priv->cfp.rules_list, next)
                bcm_sf2_cfp_rule_del(priv, rule->port, rule->fs.location);
 }
+
+int bcm_sf2_cfp_resume(struct dsa_switch *ds)
+{
+       struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
+       struct cfp_rule *rule;
+       int ret = 0;
+       u32 reg;
+
+       if (list_empty(&priv->cfp.rules_list))
+               return ret;
+
+       reg = core_readl(priv, CORE_CFP_CTL_REG);
+       reg &= ~CFP_EN_MAP_MASK;
+       core_writel(priv, reg, CORE_CFP_CTL_REG);
+
+       ret = bcm_sf2_cfp_rst(priv);
+       if (ret)
+               return ret;
+
+       list_for_each_entry(rule, &priv->cfp.rules_list, next) {
+               ret = bcm_sf2_cfp_rule_remove(priv, rule->port,
+                                             rule->fs.location);
+               if (ret) {
+                       dev_err(ds->dev, "failed to remove rule\n");
+                       return ret;
+               }
+
+               ret = bcm_sf2_cfp_rule_insert(ds, rule->port, &rule->fs);
+               if (ret) {
+                       dev_err(ds->dev, "failed to restore rule\n");
+                       return ret;
+               }
+       };
+
+       return ret;
+}