Skip to content

Commit 3e9005b

Browse files
xdarklightdavem330
authored andcommitted
net: dsa: lantiq_gswip: Don't use PHY auto polling
PHY auto polling on the GSWIP hardware can be used so link changes (speed, link up/down, etc.) can be detected automatically. Internally GSWIP reads the PHY's registers for this functionality. Based on this automatic detection GSWIP can also automatically re-configure it's port settings. Unfortunately this auto polling (and configuration) mechanism seems to cause various issues observed by different people on different devices: - FritzBox 7360v2: the two Gbit/s ports (connected to the two internal PHY11G instances) are working fine but the two Fast Ethernet ports (using an AR8030 RMII PHY) are completely dead (neither RX nor TX are received). It turns out that the AR8030 PHY sets the BMSR_ESTATEN bit as well as the ESTATUS_1000_TFULL and ESTATUS_1000_XFULL bits. This makes the PHY auto polling state machine (rightfully?) think that the established link speed (when the other side is Gbit/s capable) is 1Gbit/s. - None of the Ethernet ports on the Zyxel P-2812HNU-F1 (two are connected to the internal PHY11G GPHYs while the other three are external RGMII PHYs) are working. Neither RX nor TX traffic was observed. It is not clear which part of the PHY auto polling state- machine caused this. - FritzBox 7412 (only one LAN port which is connected to one of the internal GPHYs running in PHY22F / Fast Ethernet mode) was seeing random disconnects (link down events could be seen). Sometimes all traffic would stop after such disconnect. It is not clear which part of the PHY auto polling state-machine cauased this. - TP-Link TD-W9980 (two ports are connected to the internal GPHYs running in PHY11G / Gbit/s mode, the other two are external RGMII PHYs) was affected by similar issues as the FritzBox 7412 just without the "link down" events Switch to software based configuration instead of PHY auto polling (and letting the GSWIP hardware configure the ports automatically) for the following link parameters: - link up/down - link speed - full/half duplex - flow control (RX / TX pause) After a big round of manual testing by various people (who helped test this on OpenWrt) it turns out that this fixes all reported issues. Additionally it can be considered more future proof because any "quirk" which is implemented for a PHY on the driver side can now be used with the GSWIP hardware as well because Linux is in control of the link parameters. As a nice side-effect this also solves a problem where fixed-links were not supported previously because we were relying on the PHY auto polling mechanism, which cannot work for fixed-links as there's no PHY from where it can read the registers. Configuring the link settings on the GSWIP ports means that we now use the settings from device-tree also for ports with fixed-links. Fixes: 14fceff ("net: dsa: Add Lantiq / Intel DSA driver for vrx200") Fixes: 3e6fdeb ("net: dsa: lantiq_gswip: Let GSWIP automatically set the xMII clock") Cc: [email protected] Acked-by: Hauke Mehrtens <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Martin Blumenstingl <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6494d15 commit 3e9005b

File tree

1 file changed

+159
-26
lines changed

1 file changed

+159
-26
lines changed

drivers/net/dsa/lantiq_gswip.c

Lines changed: 159 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@
190190
#define GSWIP_PCE_DEFPVID(p) (0x486 + ((p) * 0xA))
191191

192192
#define GSWIP_MAC_FLEN 0x8C5
193+
#define GSWIP_MAC_CTRL_0p(p) (0x903 + ((p) * 0xC))
194+
#define GSWIP_MAC_CTRL_0_PADEN BIT(8)
195+
#define GSWIP_MAC_CTRL_0_FCS_EN BIT(7)
196+
#define GSWIP_MAC_CTRL_0_FCON_MASK 0x0070
197+
#define GSWIP_MAC_CTRL_0_FCON_AUTO 0x0000
198+
#define GSWIP_MAC_CTRL_0_FCON_RX 0x0010
199+
#define GSWIP_MAC_CTRL_0_FCON_TX 0x0020
200+
#define GSWIP_MAC_CTRL_0_FCON_RXTX 0x0030
201+
#define GSWIP_MAC_CTRL_0_FCON_NONE 0x0040
202+
#define GSWIP_MAC_CTRL_0_FDUP_MASK 0x000C
203+
#define GSWIP_MAC_CTRL_0_FDUP_AUTO 0x0000
204+
#define GSWIP_MAC_CTRL_0_FDUP_EN 0x0004
205+
#define GSWIP_MAC_CTRL_0_FDUP_DIS 0x000C
206+
#define GSWIP_MAC_CTRL_0_GMII_MASK 0x0003
207+
#define GSWIP_MAC_CTRL_0_GMII_AUTO 0x0000
208+
#define GSWIP_MAC_CTRL_0_GMII_MII 0x0001
209+
#define GSWIP_MAC_CTRL_0_GMII_RGMII 0x0002
193210
#define GSWIP_MAC_CTRL_2p(p) (0x905 + ((p) * 0xC))
194211
#define GSWIP_MAC_CTRL_2_MLEN BIT(3) /* Maximum Untagged Frame Lnegth */
195212

@@ -653,16 +670,13 @@ static int gswip_port_enable(struct dsa_switch *ds, int port,
653670
GSWIP_SDMA_PCTRLp(port));
654671

655672
if (!dsa_is_cpu_port(ds, port)) {
656-
u32 macconf = GSWIP_MDIO_PHY_LINK_AUTO |
657-
GSWIP_MDIO_PHY_SPEED_AUTO |
658-
GSWIP_MDIO_PHY_FDUP_AUTO |
659-
GSWIP_MDIO_PHY_FCONTX_AUTO |
660-
GSWIP_MDIO_PHY_FCONRX_AUTO |
661-
(phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK);
662-
663-
gswip_mdio_w(priv, macconf, GSWIP_MDIO_PHYp(port));
664-
/* Activate MDIO auto polling */
665-
gswip_mdio_mask(priv, 0, BIT(port), GSWIP_MDIO_MDC_CFG0);
673+
u32 mdio_phy = 0;
674+
675+
if (phydev)
676+
mdio_phy = phydev->mdio.addr & GSWIP_MDIO_PHY_ADDR_MASK;
677+
678+
gswip_mdio_mask(priv, GSWIP_MDIO_PHY_ADDR_MASK, mdio_phy,
679+
GSWIP_MDIO_PHYp(port));
666680
}
667681

668682
return 0;
@@ -675,14 +689,6 @@ static void gswip_port_disable(struct dsa_switch *ds, int port)
675689
if (!dsa_is_user_port(ds, port))
676690
return;
677691

678-
if (!dsa_is_cpu_port(ds, port)) {
679-
gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_DOWN,
680-
GSWIP_MDIO_PHY_LINK_MASK,
681-
GSWIP_MDIO_PHYp(port));
682-
/* Deactivate MDIO auto polling */
683-
gswip_mdio_mask(priv, BIT(port), 0, GSWIP_MDIO_MDC_CFG0);
684-
}
685-
686692
gswip_switch_mask(priv, GSWIP_FDMA_PCTRL_EN, 0,
687693
GSWIP_FDMA_PCTRLp(port));
688694
gswip_switch_mask(priv, GSWIP_SDMA_PCTRL_EN, 0,
@@ -794,20 +800,31 @@ static int gswip_setup(struct dsa_switch *ds)
794800
gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP2);
795801
gswip_switch_w(priv, BIT(cpu_port), GSWIP_PCE_PMAP3);
796802

797-
/* disable PHY auto polling */
803+
/* Deactivate MDIO PHY auto polling. Some PHYs as the AR8030 have an
804+
* interoperability problem with this auto polling mechanism because
805+
* their status registers think that the link is in a different state
806+
* than it actually is. For the AR8030 it has the BMSR_ESTATEN bit set
807+
* as well as ESTATUS_1000_TFULL and ESTATUS_1000_XFULL. This makes the
808+
* auto polling state machine consider the link being negotiated with
809+
* 1Gbit/s. Since the PHY itself is a Fast Ethernet RMII PHY this leads
810+
* to the switch port being completely dead (RX and TX are both not
811+
* working).
812+
* Also with various other PHY / port combinations (PHY11G GPHY, PHY22F
813+
* GPHY, external RGMII PEF7071/7072) any traffic would stop. Sometimes
814+
* it would work fine for a few minutes to hours and then stop, on
815+
* other device it would no traffic could be sent or received at all.
816+
* Testing shows that when PHY auto polling is disabled these problems
817+
* go away.
818+
*/
798819
gswip_mdio_w(priv, 0x0, GSWIP_MDIO_MDC_CFG0);
820+
799821
/* Configure the MDIO Clock 2.5 MHz */
800822
gswip_mdio_mask(priv, 0xff, 0x09, GSWIP_MDIO_MDC_CFG1);
801823

802-
for (i = 0; i < priv->hw_info->max_ports; i++) {
803-
/* Disable the xMII link */
824+
/* Disable the xMII link */
825+
for (i = 0; i < priv->hw_info->max_ports; i++)
804826
gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, i);
805827

806-
/* Automatically select the xMII interface clock */
807-
gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_RATE_MASK,
808-
GSWIP_MII_CFG_RATE_AUTO, i);
809-
}
810-
811828
/* enable special tag insertion on cpu port */
812829
gswip_switch_mask(priv, 0, GSWIP_FDMA_PCTRL_STEN,
813830
GSWIP_FDMA_PCTRLp(cpu_port));
@@ -1455,6 +1472,112 @@ static void gswip_phylink_validate(struct dsa_switch *ds, int port,
14551472
return;
14561473
}
14571474

1475+
static void gswip_port_set_link(struct gswip_priv *priv, int port, bool link)
1476+
{
1477+
u32 mdio_phy;
1478+
1479+
if (link)
1480+
mdio_phy = GSWIP_MDIO_PHY_LINK_UP;
1481+
else
1482+
mdio_phy = GSWIP_MDIO_PHY_LINK_DOWN;
1483+
1484+
gswip_mdio_mask(priv, GSWIP_MDIO_PHY_LINK_MASK, mdio_phy,
1485+
GSWIP_MDIO_PHYp(port));
1486+
}
1487+
1488+
static void gswip_port_set_speed(struct gswip_priv *priv, int port, int speed,
1489+
phy_interface_t interface)
1490+
{
1491+
u32 mdio_phy = 0, mii_cfg = 0, mac_ctrl_0 = 0;
1492+
1493+
switch (speed) {
1494+
case SPEED_10:
1495+
mdio_phy = GSWIP_MDIO_PHY_SPEED_M10;
1496+
1497+
if (interface == PHY_INTERFACE_MODE_RMII)
1498+
mii_cfg = GSWIP_MII_CFG_RATE_M50;
1499+
else
1500+
mii_cfg = GSWIP_MII_CFG_RATE_M2P5;
1501+
1502+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_MII;
1503+
break;
1504+
1505+
case SPEED_100:
1506+
mdio_phy = GSWIP_MDIO_PHY_SPEED_M100;
1507+
1508+
if (interface == PHY_INTERFACE_MODE_RMII)
1509+
mii_cfg = GSWIP_MII_CFG_RATE_M50;
1510+
else
1511+
mii_cfg = GSWIP_MII_CFG_RATE_M25;
1512+
1513+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_MII;
1514+
break;
1515+
1516+
case SPEED_1000:
1517+
mdio_phy = GSWIP_MDIO_PHY_SPEED_G1;
1518+
1519+
mii_cfg = GSWIP_MII_CFG_RATE_M125;
1520+
1521+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_GMII_RGMII;
1522+
break;
1523+
}
1524+
1525+
gswip_mdio_mask(priv, GSWIP_MDIO_PHY_SPEED_MASK, mdio_phy,
1526+
GSWIP_MDIO_PHYp(port));
1527+
gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_RATE_MASK, mii_cfg, port);
1528+
gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_GMII_MASK, mac_ctrl_0,
1529+
GSWIP_MAC_CTRL_0p(port));
1530+
}
1531+
1532+
static void gswip_port_set_duplex(struct gswip_priv *priv, int port, int duplex)
1533+
{
1534+
u32 mac_ctrl_0, mdio_phy;
1535+
1536+
if (duplex == DUPLEX_FULL) {
1537+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FDUP_EN;
1538+
mdio_phy = GSWIP_MDIO_PHY_FDUP_EN;
1539+
} else {
1540+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FDUP_DIS;
1541+
mdio_phy = GSWIP_MDIO_PHY_FDUP_DIS;
1542+
}
1543+
1544+
gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_FDUP_MASK, mac_ctrl_0,
1545+
GSWIP_MAC_CTRL_0p(port));
1546+
gswip_mdio_mask(priv, GSWIP_MDIO_PHY_FDUP_MASK, mdio_phy,
1547+
GSWIP_MDIO_PHYp(port));
1548+
}
1549+
1550+
static void gswip_port_set_pause(struct gswip_priv *priv, int port,
1551+
bool tx_pause, bool rx_pause)
1552+
{
1553+
u32 mac_ctrl_0, mdio_phy;
1554+
1555+
if (tx_pause && rx_pause) {
1556+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_RXTX;
1557+
mdio_phy = GSWIP_MDIO_PHY_FCONTX_EN |
1558+
GSWIP_MDIO_PHY_FCONRX_EN;
1559+
} else if (tx_pause) {
1560+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_TX;
1561+
mdio_phy = GSWIP_MDIO_PHY_FCONTX_EN |
1562+
GSWIP_MDIO_PHY_FCONRX_DIS;
1563+
} else if (rx_pause) {
1564+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_RX;
1565+
mdio_phy = GSWIP_MDIO_PHY_FCONTX_DIS |
1566+
GSWIP_MDIO_PHY_FCONRX_EN;
1567+
} else {
1568+
mac_ctrl_0 = GSWIP_MAC_CTRL_0_FCON_NONE;
1569+
mdio_phy = GSWIP_MDIO_PHY_FCONTX_DIS |
1570+
GSWIP_MDIO_PHY_FCONRX_DIS;
1571+
}
1572+
1573+
gswip_switch_mask(priv, GSWIP_MAC_CTRL_0_FCON_MASK,
1574+
mac_ctrl_0, GSWIP_MAC_CTRL_0p(port));
1575+
gswip_mdio_mask(priv,
1576+
GSWIP_MDIO_PHY_FCONTX_MASK |
1577+
GSWIP_MDIO_PHY_FCONRX_MASK,
1578+
mdio_phy, GSWIP_MDIO_PHYp(port));
1579+
}
1580+
14581581
static void gswip_phylink_mac_config(struct dsa_switch *ds, int port,
14591582
unsigned int mode,
14601583
const struct phylink_link_state *state)
@@ -1511,6 +1634,9 @@ static void gswip_phylink_mac_link_down(struct dsa_switch *ds, int port,
15111634
struct gswip_priv *priv = ds->priv;
15121635

15131636
gswip_mii_mask_cfg(priv, GSWIP_MII_CFG_EN, 0, port);
1637+
1638+
if (!dsa_is_cpu_port(ds, port))
1639+
gswip_port_set_link(priv, port, false);
15141640
}
15151641

15161642
static void gswip_phylink_mac_link_up(struct dsa_switch *ds, int port,
@@ -1522,6 +1648,13 @@ static void gswip_phylink_mac_link_up(struct dsa_switch *ds, int port,
15221648
{
15231649
struct gswip_priv *priv = ds->priv;
15241650

1651+
if (!dsa_is_cpu_port(ds, port)) {
1652+
gswip_port_set_link(priv, port, true);
1653+
gswip_port_set_speed(priv, port, speed, interface);
1654+
gswip_port_set_duplex(priv, port, duplex);
1655+
gswip_port_set_pause(priv, port, tx_pause, rx_pause);
1656+
}
1657+
15251658
gswip_mii_mask_cfg(priv, 0, GSWIP_MII_CFG_EN, port);
15261659
}
15271660

0 commit comments

Comments
 (0)