Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Improve RGMII TX / RX delay handling, from OpenBSD.



details:   https://anonhg.NetBSD.org/src/rev/016740f0a902
branches:  trunk
changeset: 972410:016740f0a902
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon May 25 19:49:28 2020 +0000

description:
Improve RGMII TX / RX delay handling, from OpenBSD.

diffstat:

 sys/dev/acpi/genet_acpi.c |   6 ++++--
 sys/dev/fdt/genet_fdt.c   |   6 ++++--
 sys/dev/ic/bcmgenet.c     |  30 ++++++++++++++++++++++++++----
 sys/dev/ic/bcmgenetvar.h  |   3 ++-
 4 files changed, 36 insertions(+), 9 deletions(-)

diffs (152 lines):

diff -r 29fa730872a8 -r 016740f0a902 sys/dev/acpi/genet_acpi.c
--- a/sys/dev/acpi/genet_acpi.c Mon May 25 19:48:38 2020 +0000
+++ b/sys/dev/acpi/genet_acpi.c Mon May 25 19:49:28 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: genet_acpi.c,v 1.1 2020/02/22 02:28:06 jmcneill Exp $ */
+/* $NetBSD: genet_acpi.c,v 1.2 2020/05/25 19:49:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_net_mpsafe.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genet_acpi.c,v 1.1 2020/02/22 02:28:06 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genet_acpi.c,v 1.2 2020/05/25 19:49:28 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -131,6 +131,8 @@
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII_RXID;
        else if (strcmp(phy_mode, "rgmii-txid") == 0)
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII_TXID;
+       else if (strcmp(phy_mode, "rgmii-id") == 0)
+               sc->sc_phy_mode = GENET_PHY_MODE_RGMII_ID;
        else if (strcmp(phy_mode, "rgmii") == 0)
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII;
        else {
diff -r 29fa730872a8 -r 016740f0a902 sys/dev/fdt/genet_fdt.c
--- a/sys/dev/fdt/genet_fdt.c   Mon May 25 19:48:38 2020 +0000
+++ b/sys/dev/fdt/genet_fdt.c   Mon May 25 19:49:28 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: genet_fdt.c,v 1.1 2020/02/22 00:28:35 jmcneill Exp $ */
+/* $NetBSD: genet_fdt.c,v 1.2 2020/05/25 19:49:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -29,7 +29,7 @@
 #include "opt_net_mpsafe.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genet_fdt.c,v 1.1 2020/02/22 00:28:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genet_fdt.c,v 1.2 2020/05/25 19:49:28 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -108,6 +108,8 @@
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII_RXID;
        else if (strcmp(phy_mode, "rgmii-txid") == 0)
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII_TXID;
+       else if (strcmp(phy_mode, "rgmii-id") == 0)
+               sc->sc_phy_mode = GENET_PHY_MODE_RGMII_ID;
        else if (strcmp(phy_mode, "rgmii") == 0)
                sc->sc_phy_mode = GENET_PHY_MODE_RGMII;
        else {
diff -r 29fa730872a8 -r 016740f0a902 sys/dev/ic/bcmgenet.c
--- a/sys/dev/ic/bcmgenet.c     Mon May 25 19:48:38 2020 +0000
+++ b/sys/dev/ic/bcmgenet.c     Mon May 25 19:49:28 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.5 2020/03/29 13:20:04 jmcneill Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.6 2020/05/25 19:49:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.5 2020/03/29 13:20:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.6 2020/05/25 19:49:28 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -165,6 +165,8 @@
        val |= GENET_EXT_RGMII_OOB_RGMII_MODE_EN;
        if (sc->sc_phy_mode == GENET_PHY_MODE_RGMII)
                val |= GENET_EXT_RGMII_OOB_ID_MODE_DISABLE;
+       else
+               val &= ~GENET_EXT_RGMII_OOB_ID_MODE_DISABLE;
        WR4(sc, GENET_EXT_RGMII_OOB_CTRL, val);
 
        val = RD4(sc, GENET_UMAC_CMD);
@@ -507,9 +509,13 @@
                return 0;
 
        if (sc->sc_phy_mode == GENET_PHY_MODE_RGMII ||
-           sc->sc_phy_mode == GENET_PHY_MODE_RGMII_RXID)
+           sc->sc_phy_mode == GENET_PHY_MODE_RGMII_ID ||
+           sc->sc_phy_mode == GENET_PHY_MODE_RGMII_RXID ||
+           sc->sc_phy_mode == GENET_PHY_MODE_RGMII_TXID)
                WR4(sc, GENET_SYS_PORT_CTRL,
                    GENET_SYS_PORT_MODE_EXT_GPHY);
+       else
+               WR4(sc, GENET_SYS_PORT_CTRL, 0);
 
        /* Write hardware address */
        val = enaddr[3] | (enaddr[2] << 8) | (enaddr[1] << 16) |
@@ -908,6 +914,7 @@
        struct ifnet *ifp = &sc->sc_ec.ec_if;
        uint8_t eaddr[ETHER_ADDR_LEN];
        u_int maj, min;
+       int mii_flags = 0;
 
        const uint32_t rev = RD4(sc, GENET_SYS_REV_CTRL);
        min = __SHIFTOUT(rev, SYS_REV_MINOR);
@@ -922,6 +929,21 @@
                return ENXIO;
        }
 
+       switch (sc->sc_phy_mode) {
+       case GENET_PHY_MODE_RGMII_TXID:
+               mii_flags |= MIIF_TXID;
+               break;
+       case GENET_PHY_MODE_RGMII_RXID:
+               mii_flags |= MIIF_RXID;
+               break;
+       case GENET_PHY_MODE_RGMII_ID:
+               mii_flags |= MIIF_RXID | MIIF_TXID;
+               break;
+       case GENET_PHY_MODE_RGMII:
+       default:
+               break;
+       }
+
        aprint_naive("\n");
        aprint_normal(": GENETv%d.%d\n", maj, min);
 
@@ -968,7 +990,7 @@
        mii->mii_writereg = genet_mii_writereg;
        mii->mii_statchg = genet_mii_statchg;
        mii_attach(sc->sc_dev, mii, 0xffffffff, sc->sc_phy_id, MII_OFFSET_ANY,
-           0);
+           mii_flags);
 
        if (LIST_EMPTY(&mii->mii_phys)) {
                aprint_error_dev(sc->sc_dev, "no PHY found!\n");
diff -r 29fa730872a8 -r 016740f0a902 sys/dev/ic/bcmgenetvar.h
--- a/sys/dev/ic/bcmgenetvar.h  Mon May 25 19:48:38 2020 +0000
+++ b/sys/dev/ic/bcmgenetvar.h  Mon May 25 19:49:28 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenetvar.h,v 1.1 2020/02/22 00:28:35 jmcneill Exp $ */
+/* $NetBSD: bcmgenetvar.h,v 1.2 2020/05/25 19:49:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -37,6 +37,7 @@
 
 enum genet_phy_mode {
        GENET_PHY_MODE_RGMII,
+       GENET_PHY_MODE_RGMII_ID,
        GENET_PHY_MODE_RGMII_TXID,
        GENET_PHY_MODE_RGMII_RXID,
 };



Home | Main Index | Thread Index | Old Index