net: dsa: b53: Move EEE functions to b53
authorFlorian Fainelli <f.fainelli@gmail.com>
Tue, 19 Sep 2017 17:46:50 +0000 (10:46 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 19 Sep 2017 23:08:53 +0000 (16:08 -0700)
Move the bcm_sf2 EEE-related functions to the b53 driver because this is shared
code amongst Gigabit capable switch, only 5325 and 5365 are too old to support
that.

Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/b53/b53_common.c
drivers/net/dsa/b53/b53_priv.h
drivers/net/dsa/bcm_sf2.c
drivers/net/dsa/bcm_sf2.h
drivers/net/dsa/bcm_sf2_regs.h

index aa2187c71ea5aebbc0cf1a63ef2769caf3d4d276..491e4ffa8a0e99d8950a812ae673bb99d29dbe99 100644 (file)
@@ -1531,6 +1531,69 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
 }
 EXPORT_SYMBOL(b53_mirror_del);
 
+void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
+{
+       struct b53_device *dev = ds->priv;
+       u16 reg;
+
+       b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
+       if (enable)
+               reg |= BIT(port);
+       else
+               reg &= ~BIT(port);
+       b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
+}
+EXPORT_SYMBOL(b53_eee_enable_set);
+
+
+/* Returns 0 if EEE was not enabled, or 1 otherwise
+ */
+int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
+{
+       int ret;
+
+       ret = phy_init_eee(phy, 0);
+       if (ret)
+               return 0;
+
+       b53_eee_enable_set(ds, port, true);
+
+       return 1;
+}
+EXPORT_SYMBOL(b53_eee_init);
+
+int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
+{
+       struct b53_device *dev = ds->priv;
+       struct ethtool_eee *p = &dev->ports[port].eee;
+       u16 reg;
+
+       if (is5325(dev) || is5365(dev))
+               return -EOPNOTSUPP;
+
+       b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
+       e->eee_enabled = p->eee_enabled;
+       e->eee_active = !!(reg & BIT(port));
+
+       return 0;
+}
+EXPORT_SYMBOL(b53_get_mac_eee);
+
+int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
+{
+       struct b53_device *dev = ds->priv;
+       struct ethtool_eee *p = &dev->ports[port].eee;
+
+       if (is5325(dev) || is5365(dev))
+               return -EOPNOTSUPP;
+
+       p->eee_enabled = e->eee_enabled;
+       b53_eee_enable_set(ds, port, e->eee_enabled);
+
+       return 0;
+}
+EXPORT_SYMBOL(b53_set_mac_eee);
+
 static const struct dsa_switch_ops b53_switch_ops = {
        .get_tag_protocol       = b53_get_tag_protocol,
        .setup                  = b53_setup,
index 77102f685da030d69cc053ecafe704a13a444e3d..aabe80eab25dc175c8877df01b78ee1c108bc4bc 100644 (file)
@@ -70,6 +70,7 @@ enum {
 
 struct b53_port {
        u16             vlan_ctl_mask;
+       struct ethtool_eee eee;
 };
 
 struct b53_vlan {
@@ -310,5 +311,9 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
 void b53_mirror_del(struct dsa_switch *ds, int port,
                    struct dsa_mall_mirror_tc_entry *mirror);
 void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
+void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);
+int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
+int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
+int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
 
 #endif
index 49cb51223f7004ba2c92b49cd2813507ae608ee3..4e8ef4c07eab8c271b8ff9fdd4e1d2d5274d5045 100644 (file)
@@ -107,19 +107,6 @@ static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port)
        core_writel(priv, reg, offset);
 }
 
-static void bcm_sf2_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
-{
-       struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       u32 reg;
-
-       reg = core_readl(priv, CORE_EEE_EN_CTRL);
-       if (enable)
-               reg |= 1 << port;
-       else
-               reg &= ~(1 << port);
-       core_writel(priv, reg, CORE_EEE_EN_CTRL);
-}
-
 static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable)
 {
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
@@ -256,8 +243,8 @@ static int bcm_sf2_port_setup(struct dsa_switch *ds, int port,
        bcm_sf2_imp_vlan_setup(ds, cpu_port);
 
        /* If EEE was enabled, restore it */
-       if (priv->port_sts[port].eee.eee_enabled)
-               bcm_sf2_eee_enable_set(ds, port, true);
+       if (priv->dev->ports[port].eee.eee_enabled)
+               b53_eee_enable_set(ds, port, true);
 
        return 0;
 }
@@ -292,47 +279,6 @@ static void bcm_sf2_port_disable(struct dsa_switch *ds, int port,
        core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL);
 }
 
-/* Returns 0 if EEE was not enabled, or 1 otherwise
- */
-static int bcm_sf2_eee_init(struct dsa_switch *ds, int port,
-                           struct phy_device *phy)
-{
-       int ret;
-
-       ret = phy_init_eee(phy, 0);
-       if (ret)
-               return 0;
-
-       bcm_sf2_eee_enable_set(ds, port, true);
-
-       return 1;
-}
-
-static int bcm_sf2_sw_get_mac_eee(struct dsa_switch *ds, int port,
-                                 struct ethtool_eee *e)
-{
-       struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       struct ethtool_eee *p = &priv->port_sts[port].eee;
-       u32 reg;
-
-       reg = core_readl(priv, CORE_EEE_LPI_INDICATE);
-       e->eee_enabled = p->eee_enabled;
-       e->eee_active = !!(reg & (1 << port));
-
-       return 0;
-}
-
-static int bcm_sf2_sw_set_mac_eee(struct dsa_switch *ds, int port,
-                                 struct ethtool_eee *e)
-{
-       struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       struct ethtool_eee *p = &priv->port_sts[port].eee;
-
-       p->eee_enabled = e->eee_enabled;
-       bcm_sf2_eee_enable_set(ds, port, e->eee_enabled);
-
-       return 0;
-}
 
 static int bcm_sf2_sw_indir_rw(struct bcm_sf2_priv *priv, int op, int addr,
                               int regnum, u16 val)
@@ -567,7 +513,7 @@ static void bcm_sf2_sw_adjust_link(struct dsa_switch *ds, int port,
                                   struct phy_device *phydev)
 {
        struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
-       struct ethtool_eee *p = &priv->port_sts[port].eee;
+       struct ethtool_eee *p = &priv->dev->ports[port].eee;
        u32 id_mode_dis = 0, port_mode;
        const char *str = NULL;
        u32 reg, offset;
@@ -649,7 +595,7 @@ force_link:
        core_writel(priv, reg, offset);
 
        if (!phydev->is_pseudo_fixed_link)
-               p->eee_enabled = bcm_sf2_eee_init(ds, port, phydev);
+               p->eee_enabled = b53_eee_init(ds, port, phydev);
 }
 
 static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port,
@@ -978,8 +924,8 @@ static const struct dsa_switch_ops bcm_sf2_ops = {
        .set_wol                = bcm_sf2_sw_set_wol,
        .port_enable            = bcm_sf2_port_setup,
        .port_disable           = bcm_sf2_port_disable,
-       .get_mac_eee            = bcm_sf2_sw_get_mac_eee,
-       .set_mac_eee            = bcm_sf2_sw_set_mac_eee,
+       .get_mac_eee            = b53_get_mac_eee,
+       .set_mac_eee            = b53_set_mac_eee,
        .port_bridge_join       = b53_br_join,
        .port_bridge_leave      = b53_br_leave,
        .port_stp_state_set     = b53_br_set_stp_state,
index 02c499f9c56b3bdd0cccb277ce0be9e13d318055..1922e027ff5971853e40cbdfa49e252068c0d185 100644 (file)
@@ -48,8 +48,6 @@ struct bcm_sf2_hw_params {
 
 struct bcm_sf2_port_status {
        unsigned int link;
-
-       struct ethtool_eee eee;
 };
 
 struct bcm_sf2_cfp_priv {
index 788361ad68a011a502bb16724cb95dd4b8eb29a6..d8b8074a47b97e26e073b1feb92d6a5b0e4489a0 100644 (file)
@@ -244,9 +244,6 @@ enum bcm_sf2_reg_offs {
 
 #define CORE_JOIN_ALL_VLAN_EN          0xd140
 
-#define CORE_EEE_EN_CTRL               0x24800
-#define CORE_EEE_LPI_INDICATE          0x24810
-
 #define CORE_CFP_ACC                   0x28000
 #define  OP_STR_DONE                   (1 << 0)
 #define  OP_SEL_SHIFT                  1