Re: [PATCH net-next v3 5/5] net: dsa: b53: Add SerDes support

2018-09-05 Thread Andrew Lunn
On Wed, Sep 05, 2018 at 12:42:15PM -0700, Florian Fainelli wrote:
> Add support for the Northstar Plus SerDes which is accessed through a
> special page of the switch. Since this is something that most people
> probably will not want to use, make it a configurable option with a
> default on ARCH_BCM_NSP where it is the most useful currently.
> 
> The SerDes supports both SGMII and 1000baseX modes for both lanes, and
> 2500baseX for one of the lanes, and is internally looking like a
> seemingly standard MII PHY, except for the few bits that got repurposed.
> 
> Signed-off-by: Florian Fainelli 
 
Reviewed-by: Andrew Lunn 

Andrew


[PATCH net-next v3 5/5] net: dsa: b53: Add SerDes support

2018-09-05 Thread Florian Fainelli
Add support for the Northstar Plus SerDes which is accessed through a
special page of the switch. Since this is something that most people
probably will not want to use, make it a configurable option with a
default on ARCH_BCM_NSP where it is the most useful currently.

The SerDes supports both SGMII and 1000baseX modes for both lanes, and
2500baseX for one of the lanes, and is internally looking like a
seemingly standard MII PHY, except for the few bits that got repurposed.

Signed-off-by: Florian Fainelli 
---
 drivers/net/dsa/b53/Kconfig  |   7 +
 drivers/net/dsa/b53/Makefile |   1 +
 drivers/net/dsa/b53/b53_common.c |  26 
 drivers/net/dsa/b53/b53_priv.h   |  17 +++
 drivers/net/dsa/b53/b53_serdes.c | 217 +++
 drivers/net/dsa/b53/b53_serdes.h | 121 +
 drivers/net/dsa/b53/b53_srab.c   | 101 ++
 7 files changed, 490 insertions(+)
 create mode 100644 drivers/net/dsa/b53/b53_serdes.c
 create mode 100644 drivers/net/dsa/b53/b53_serdes.h

diff --git a/drivers/net/dsa/b53/Kconfig b/drivers/net/dsa/b53/Kconfig
index 37745f4bf4f6..e83ebfafd881 100644
--- a/drivers/net/dsa/b53/Kconfig
+++ b/drivers/net/dsa/b53/Kconfig
@@ -35,3 +35,10 @@ config B53_SRAB_DRIVER
help
  Select to enable support for memory-mapped Switch Register Access
  Bridge Registers (SRAB) like it is found on the BCM53010
+
+config B53_SERDES
+   tristate "B53 SerDes support"
+   depends on B53
+   default ARCH_BCM_NSP
+   help
+ Select to enable support for SerDes on e.g: Northstar Plus SoCs.
diff --git a/drivers/net/dsa/b53/Makefile b/drivers/net/dsa/b53/Makefile
index 4256fb42a4dd..b1be13023ae4 100644
--- a/drivers/net/dsa/b53/Makefile
+++ b/drivers/net/dsa/b53/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_B53_SPI_DRIVER)+= b53_spi.o
 obj-$(CONFIG_B53_MDIO_DRIVER)  += b53_mdio.o
 obj-$(CONFIG_B53_MMAP_DRIVER)  += b53_mmap.o
 obj-$(CONFIG_B53_SRAB_DRIVER)  += b53_srab.o
+obj-$(CONFIG_B53_SERDES)   += b53_serdes.o
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 3d5e822bb17c..ea4256cd628b 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -765,6 +765,8 @@ static int b53_reset_switch(struct b53_device *priv)
memset(priv->vlans, 0, sizeof(*priv->vlans) * priv->num_vlans);
memset(priv->ports, 0, sizeof(*priv->ports) * priv->num_ports);
 
+   priv->serdes_lane = B53_INVALID_LANE;
+
return b53_switch_reset(priv);
 }
 
@@ -1128,6 +1130,9 @@ void b53_phylink_validate(struct dsa_switch *ds, int port,
struct b53_device *dev = ds->priv;
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
 
+   if (dev->ops->serdes_phylink_validate)
+   dev->ops->serdes_phylink_validate(dev, port, mask, state);
+
/* Allow all the expected bits */
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
@@ -1164,8 +1169,13 @@ EXPORT_SYMBOL(b53_phylink_validate);
 int b53_phylink_mac_link_state(struct dsa_switch *ds, int port,
   struct phylink_link_state *state)
 {
+   struct b53_device *dev = ds->priv;
int ret = -EOPNOTSUPP;
 
+   if (phy_interface_mode_is_8023z(state->interface) &&
+   dev->ops->serdes_link_state)
+   ret = dev->ops->serdes_link_state(dev, port, state);
+
return ret;
 }
 EXPORT_SYMBOL(b53_phylink_mac_link_state);
@@ -1184,11 +1194,19 @@ void b53_phylink_mac_config(struct dsa_switch *ds, int 
port,
  state->duplex, state->pause);
return;
}
+
+   if (phy_interface_mode_is_8023z(state->interface) &&
+   dev->ops->serdes_config)
+   dev->ops->serdes_config(dev, port, mode, state);
 }
 EXPORT_SYMBOL(b53_phylink_mac_config);
 
 void b53_phylink_mac_an_restart(struct dsa_switch *ds, int port)
 {
+   struct b53_device *dev = ds->priv;
+
+   if (dev->ops->serdes_an_restart)
+   dev->ops->serdes_an_restart(dev, port);
 }
 EXPORT_SYMBOL(b53_phylink_mac_an_restart);
 
@@ -1205,6 +1223,10 @@ void b53_phylink_mac_link_down(struct dsa_switch *ds, 
int port,
b53_force_link(dev, port, false);
return;
}
+
+   if (phy_interface_mode_is_8023z(interface) &&
+   dev->ops->serdes_link_set)
+   dev->ops->serdes_link_set(dev, port, mode, interface, false);
 }
 EXPORT_SYMBOL(b53_phylink_mac_link_down);
 
@@ -1222,6 +1244,10 @@ void b53_phylink_mac_link_up(struct dsa_switch *ds, int 
port,
b53_force_link(dev, port, true);
return;
}
+
+   if (phy_interface_mode_is_8023z(interface) &&
+   dev->ops->serdes_link_set)
+   dev->ops->serdes_link_set(dev, port, mode, interface, true);
 }
 EXPORT_SYMBOL(b53_phylink_mac_link_up);
 
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index