net: dsa: sja1105: Add support for the SGMII port
Vladimir Oltean
maintainerPATCH 1/1 net: dsa: sja1105: Add support for the SGMII port
From: Vladimir Oltean <[email protected]>
SJA1105 switches R and S have one SerDes port with an 802.3z quasi-compatible PCS, hardwired on port 4. The other ports are still MII/RMII/RGMII. The PCS performs rate adaptation to lower link speeds; the MAC on this port is hardwired at gigabit. Only full duplex is supported.
The SGMII port can be configured as part of the static config tables, as well as through a dedicated SPI address region for its pseudo-clause-22 registers. However it looks like the static configuration is not able to change some out-of-reset values (like the value of MII_BMCR), so at the end of the day, having code for it is utterly pointless. We are just going to use the pseudo-C22 interface.
Because the PCS gets reset when the switch resets, we have to add even more restoration logic to sja1105_static_config_reload, otherwise the SGMII port breaks after operations such as enabling PTP timestamping which require a switch reset.
From PHYLINK perspective, the switch supports *only* SGMII (it doesn't support 1000Base-X). It also doesn't expose access to the raw config word for in-band AN in registers MII_ADV/MII_LPA.
It is able to work in the following modes:
- Forced speed
- SGMII in-band AN slave (speed received from PHY)
- SGMII in-band AN master (acting as a PHY)
The latter mode is not supported by this patch. It is even unclear to me how that would be described.
--- drivers/net/dsa/sja1105/sja1105.h | 2 + drivers/net/dsa/sja1105/sja1105_clocking.c | 4 + drivers/net/dsa/sja1105/sja1105_main.c | 217 ++++++++++++++++++++- drivers/net/dsa/sja1105/sja1105_sgmii.h | 56 ++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 1 + 5 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_sgmii.h
drivers/net/dsa/sja1105/sja1105.h +2 -0
@@ -36,6 +36,7 @@ struct sja1105_regs {u64 port_control;u64 rgu;u64 config; +u64 sgmii;u64 rmii_pll1;u64 ptp_control;u64 ptpclkval;
@@ -159,6 +160,7 @@ typedef enum {XMII_MODE_MII =0 ,XMII_MODE_RMII =1 ,XMII_MODE_RGMII =2 , +XMII_MODE_SGMII =3 , } sja1105_phy_interface_t; typedef enum {
drivers/net/dsa/sja1105/sja1105_clocking.c +4 -0
@@ -660,6 +660,10 @@ int sja1105_clocking_setup_port(struct sja1105_private *priv, int port)case XMII_MODE_RGMII : rc =sja1105_rgmii_clocking_setup (priv, port, role);break ; +case XMII_MODE_SGMII : +/* Nothing to do in the CGU for SGMII */ + rc =0 ; +break ;default :dev_err (dev,"Invalid interface mode specified: %d\n" , phy_mode);
drivers/net/dsa/sja1105/sja1105_main.c +213 -4
310 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_sgmii.h new file +56 -0
56 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_spi.c +1 -0
@@ -474,6 +474,7 @@ static struct sja1105_regs sja1105pqrs_regs = {/* UM10944.pdf, Table 86, ACU Register overview */ .pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808}, .pad_mii_id = {0x100810, 0x100811, 0x100812, 0x100813, 0x100814}, + .sgmii = 0x1F0000, .rmii_pll1 = 0x10000A, .cgu_idiv = {0x10000B, 0x10000C, 0x10000D, 0x10000E, 0x10000F}, .mac = {0x200, 0x202, 0x204, 0x206, 0x208},
Signature · 1 line
2.17.1
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_mac_config(struct dsa_switch *ds, int port, · line 891
Quoted 13 lines · Vladimir Oltean
drivers/net/dsa/sja1105/sja1105_main.c +5
-1@@ -774,10 +881,14 @@ static void sja1105_mac_config(struct dsa_switch *ds, int port,return ; } -if (link_an_mode ==MLO_AN_INBAND ) { +if (link_an_mode ==MLO_AN_INBAND && !is_sgmii) {dev_err (ds->dev,"In-band AN not supported!\n" );return ; } + +if (is_sgmii) +sja1105_sgmii_config (priv, port, link_an_mode ==MLO_AN_INBAND , + state->speed);
Please avoid new usages of state->speed in mac_config() - I'm trying to eliminate them now that the mac_link_up() patches are in. If you need to set the PCS for the link speed, please hook that into mac_link_up() instead.
Quoted 20 lines
drivers/net/dsa/sja1105/sja1105_main.c +5
-1} static void sja1105_mac_link_down(struct dsa_switch *ds, int port,@@ -833,7 +944,8 @@ static void sja1105_phylink_validate(struct dsa_switch *ds, int port, phylink_set(mask, 10baseT_Full); phylink_set(mask, 100baseT_Full); phylink_set(mask, 100baseT1_Full); -if (mii->xmii_mode[port] ==XMII_MODE_RGMII ) +if (mii->xmii_mode[port] ==XMII_MODE_RGMII || + mii->xmii_mode[port] ==XMII_MODE_SGMII ) phylink_set(mask, 1000baseT_Full);bitmap_and (supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);@@ -841,6 +953,82 @@ static void sja1105_phylink_validate(struct dsa_switch *ds, int port, __ETHTOOL_LINK_MODE_MASK_NBITS); } +static int sja1105_mac_pcs_get_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_phylink_validate(struct dsa_switch *ds, int port, · line 968
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +10
-0+struct sja1105_private *priv = ds->priv; +int bmcr; + + bmcr =sja1105_sgmii_read (priv,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + state->an_enabled = !!(bmcr &BMCR_ANENABLE ); + +if (state->an_enabled) {
mac_pcs_get_state() is only called when in in-band AN mode, so this is not useful. If it's called with AN disabled, that's a bug.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up
Vladimir Oltean
maintainerQuoted 6 lines · Russell King - ARM Linux admin
Quoted 4 lines · Vladimir Oltean
(quoted diff) +0
-0@@ -774,10 +881,14 @@ static void sja1105_mac_config(struct dsa_switch *ds, int port, return; }
Quoted 15 lines
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_mac_config(struct dsa_switch *ds, int port, · line 891
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_main.c +5
-1-if (link_an_mode ==MLO_AN_INBAND ) { +if (link_an_mode ==MLO_AN_INBAND && !is_sgmii) {dev_err (ds->dev,"In-band AN not supported!\n" );return ; } + +if (is_sgmii) +sja1105_sgmii_config (priv, port, link_an_mode ==MLO_AN_INBAND , + state->speed);Please avoid new usages of
state->speedinmac_config()- I'm trying to eliminate them now that themac_link_up()patches are in. If you need to set the PCS for the link speed, please hook that intomac_link_up()instead.
Well, duh. I forward-ported this from a 5.4 kernel and I simply forgot to do this extra change. I'll still have to turn it around when I backport it again, but whatever.
Quoted 17 lines
Quoted 17 lines
drivers/net/dsa/sja1105/sja1105_main.c +2
-1} static void sja1105_mac_link_down(struct dsa_switch *ds, int port,@@ -833,7 +944,8 @@ static void sja1105_phylink_validate(struct dsa_switch *ds, int port, phylink_set(mask, 10baseT_Full); phylink_set(mask, 100baseT_Full); phylink_set(mask, 100baseT1_Full); -if (mii->xmii_mode[port] ==XMII_MODE_RGMII ) +if (mii->xmii_mode[port] ==XMII_MODE_RGMII || + mii->xmii_mode[port] ==XMII_MODE_SGMII ) phylink_set(mask, 1000baseT_Full);bitmap_and (supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS);@@ -841,6 +953,82 @@ static void sja1105_phylink_validate(struct dsa_switch *ds, int port, __ETHTOOL_LINK_MODE_MASK_NBITS); }
Quoted 17 lines
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_phylink_validate(struct dsa_switch *ds, int port, · line 968
Quoted 13 lines
drivers/net/dsa/sja1105/sja1105_main.c +13
-0+static int sja1105_mac_pcs_get_state (struct dsa_switch *ds,int port, +struct phylink_link_state *state) +{ +struct sja1105_private *priv = ds->priv; +int bmcr; + + bmcr =sja1105_sgmii_read (priv,MII_BMCR ); +if (bmcr <0 ) +return bmcr; + + state->an_enabled = !!(bmcr &BMCR_ANENABLE ); + +if (state->an_enabled) {
mac_pcs_get_state()is only called when in in-band AN mode, so this is not useful. If it's called with AN disabled, that's a bug.
Correct. In fact I only 'tested' in-band AN via register dumps. On my board it is physically impossible to really make use of mac_pcs_get_state because port 4 is a PHY-less interface (the CPU port), and if there were any in-band AN to take place at all, this switch port would have to be the AN master, and there isn't logic for that at the moment.
Because there isn't more than 1 SGMII port in this 5-port switch, I suspect that AN disabled is going to be the case for pretty much every other board out there.
Since I did spend the time to figure out how it should work, I thought it might have been useful to have some code, even if just blind-tested, for whomever needed it. But after your comment, I'm not willing to figure out now how to split the PCS config function to be called from the AN as well as non-AN code paths. So I'll just drop any sort of AN code in v2.
Quoted 3 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up
Thanks,
-Vladimir