net: dsa: sja1105: Add support for the SGMII port
Vladimir Oltean
maintainerPATCH v2 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 two modes (any sort of in-band AN) are not supported by this patch. For AN slave I did not have a board with the SGMII port connected to a PHY, and for AN master it is unclear to me how that would even be described.
---
Changes in v2:
- Moved PCS forced speed to .phylink_mac_link_up
- Removed not-fully-thought-out code for in-band AN slave
drivers/net/dsa/sja1105/sja1105.h | 2 + drivers/net/dsa/sja1105/sja1105_clocking.c | 4 + drivers/net/dsa/sja1105/sja1105_main.c | 126 ++++++++++++++++++++- drivers/net/dsa/sja1105/sja1105_sgmii.h | 56 +++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 1 + 5 files changed, 186 insertions(+), 3 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 +123 -3
198 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
Quoted 7 lines · Vladimir Oltean
drivers/net/dsa/sja1105/sja1105_main.c +7
-0+static void sja1105_sgmii_config (struct sja1105_private *priv,int port, +int speed) +{ +int pcs_speed; + +/* DIGITAL_CONTROL_1: Enable vendor-specific MMD1, allow the PHY to +* stop the clock during LPI mode, make the MAC reconfigure
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_parse_dt(struct sja1105_private *priv, · line 726
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +10
-0+* autonomously after PCS autoneg is done, flush the internal FIFOs. +*/ +sja1105_sgmii_write (priv,0x8000 ,SJA1105_DC1_EN_VSMMD1 | +SJA1105_DC1_CLOCK_STOP_EN | +SJA1105_DC1_MAC_AUTO_SW | +SJA1105_DC1_INIT ); +/* DIGITAL_CONTROL_2: No polarity inversion for TX and RX lanes */ +sja1105_sgmii_write (priv,0x80e1 ,SJA1105_DC2_TX_POL_INV_DISABLE ); +/* AUTONEG_CONTROL: Use SGMII autoneg */ +sja1105_sgmii_write (priv,0x8001 ,SJA1105_AC_AUTONEG_MODE_SGMII );
The above should be configured at mac_config() time.
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_main.c +6
-0+ +switch (speed) { +case SPEED_1000 : + pcs_speed =BMCR_SPEED1000 ; +break ; +case SPEED_100 :
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_parse_dt(struct sja1105_private *priv, · line 742
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +10
-0+ pcs_speed =BMCR_SPEED100 ; +break ; +case SPEED_10 : + pcs_speed =BMCR_SPEED10 ; +break ; +default : +dev_err (priv->ds->dev,"Invalid speed %d\n" , speed); +return ; + } +sja1105_sgmii_write (priv,MII_BMCR , pcs_speed |BMCR_FULLDPLX );
And this should be (as it now is) at mac_link_up().
If you want in-band AN (slave) to work, and that is documented as working by enabling the AN bit in MII_BMCR, then I would suggest setting that bit in the part called from mac_config() only if phylink_autoneg_inband(mode) returns true, and avoiding the above in mac_link_up() if phylink_autoneg_inband(mode) is also true. Yes, I realise you can't actually test that, but up to you whether or not to add that.
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