Source-Changes-HG archive

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

[src/netbsd-8]: src/sys/dev/mii Pull up the following (requested by msaitoh i...



details:   https://anonhg.NetBSD.org/src/rev/c1c2351d1724
branches:  netbsd-8
changeset: 447583:c1c2351d1724
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Jan 17 17:23:02 2019 +0000

description:
Pull up the following (requested by msaitoh in ticket #1164):

        sys/dev/mii/miidevs                     1.128, 1.132 (patch)
        sys/dev/mii/makphy.c                    1.43-1.51
        sys/dev/mii/makphyreg.h                 1.7-1.9

- miidevs: Add E1000 with model id 0x0006, it exists according to
  OpenBSD rename E1000 model 0x0000 to E1000_0 for consistency.
- Match 88E1112, 88E1118, 88E1512, 88E3082 and G65G.
- Match 88E3016 and add some 88E3016 specific code. Fixes part of
  PR kern/49270 and PR kern/53301.
- Make sure page 0 is selected when we initialize the PHY. Fixes
  problems with the eephy(4) that attaches to nfe(4) on machines like
  the Sun Ultra 40. (we had condition for this, now the page 0 is
  selected for any PHY type)
- If autonegotiation is not enabled, we need a software reset for the
  settings to take effect in makphy_service().
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Control BMCR_PDOWN for IFM_NONE. Some chips still don't work as
  expected. It would be required to modify PSCR and/or other register.
- Set mii_media_active correctly on non-autonego mode.
- Remove obsolete comment.
- Whitespace fix.

diffstat:

 sys/dev/mii/makphy.c    |  240 ++++++++++++++++++++++++++++++++++-------------
 sys/dev/mii/makphyreg.h |   71 ++++++++++++--
 sys/dev/mii/miidevs     |    7 +-
 3 files changed, 235 insertions(+), 83 deletions(-)

diffs (truncated from 526 to 300 lines):

diff -r a11011e51261 -r c1c2351d1724 sys/dev/mii/makphy.c
--- a/sys/dev/mii/makphy.c      Tue Jan 15 18:41:22 2019 +0000
+++ b/sys/dev/mii/makphy.c      Thu Jan 17 17:23:02 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makphy.c,v 1.42 2016/11/08 08:48:35 msaitoh Exp $      */
+/*     $NetBSD: makphy.c,v 1.42.8.1 2019/01/17 17:23:02 martin Exp $   */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: makphy.c,v 1.42 2016/11/08 08:48:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: makphy.c,v 1.42.8.1 2019/01/17 17:23:02 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -92,44 +92,79 @@
 };
 
 static const struct mii_phydesc makphys[] = {
+       { MII_OUI_MARVELL,              MII_MODEL_MARVELL_E1000_0,
+         MII_STR_MARVELL_E1000_0 },
+
+       { MII_OUI_MARVELL,              MII_MODEL_MARVELL_E1000_3,
+         MII_STR_MARVELL_E1000_3 },
+
+       { MII_OUI_MARVELL,              MII_MODEL_MARVELL_E1000_5,
+         MII_STR_MARVELL_E1000_5 },
+
+       { MII_OUI_MARVELL,              MII_MODEL_MARVELL_E1000_6,
+         MII_STR_MARVELL_E1000_6 },
+
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1000_3,
          MII_STR_xxMARVELL_E1000_3 },
 
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1000_5,
          MII_STR_xxMARVELL_E1000_5 },
 
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1000S,
+         MII_STR_xxMARVELL_E1000S },
+
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1011,
          MII_STR_xxMARVELL_E1011 },
 
-       /* XXX: reported not to work on eg. HP XW9400 */
-       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1149,
-         MII_STR_xxMARVELL_E1149 },
-
-       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1149R,
-         MII_STR_xxMARVELL_E1149R },
-
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1111,
          MII_STR_xxMARVELL_E1111 },
 
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1112,
+         MII_STR_xxMARVELL_E1112 },
+
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1116,
          MII_STR_xxMARVELL_E1116 },
 
-       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1145,
-         MII_STR_xxMARVELL_E1145 },
-
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1116R,
          MII_STR_xxMARVELL_E1116R },
 
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1116R_29,
          MII_STR_xxMARVELL_E1116R_29 },
 
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1118,
+         MII_STR_xxMARVELL_E1118 },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1145,
+         MII_STR_xxMARVELL_E1145 },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1149,
+         MII_STR_xxMARVELL_E1149 },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1149R,
+         MII_STR_xxMARVELL_E1149R },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1512,
+         MII_STR_xxMARVELL_E1512 },
+
        { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E1543,
          MII_STR_xxMARVELL_E1543 },
 
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E3016,
+         MII_STR_xxMARVELL_E3016 },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_E3082,
+         MII_STR_xxMARVELL_E3082 },
+
+       { MII_OUI_xxMARVELL,            MII_MODEL_xxMARVELL_PHYG65G,
+         MII_STR_xxMARVELL_PHYG65G },
+
        { 0,                            0,
          NULL },
 };
 
+#define MAKARG_PDOWN   true    /* Power DOWN */
+#define MAKARG_PUP     false   /* Power UP */
+
 static int
 makphymatch(device_t parent, cfdata_t match, void *aux)
 {
@@ -164,26 +199,14 @@
        sc->mii_flags = ma->mii_flags;
        sc->mii_anegticks = MII_ANEGTICKS;
 
+       /* Make sure page 0 is selected. */
+       PHY_WRITE(sc, MAKPHY_EADR, 0);
+
        switch (sc->mii_mpd_model) {
        case MII_MODEL_xxMARVELL_E1011:
        case MII_MODEL_xxMARVELL_E1112:
-               if (PHY_READ(sc, MII_MAKPHY_ESSR) & ESSR_FIBER_LINK)
+               if (PHY_READ(sc, MAKPHY_ESSR) & ESSR_FIBER_LINK)
                        sc->mii_flags |= MIIF_HAVEFIBER;
-                break;
-       case MII_MODEL_xxMARVELL_E1149:
-       case MII_MODEL_xxMARVELL_E1149R:
-               /*
-                * Some 88E1149 PHY's page select is initialized to
-                * point to other bank instead of copper/fiber bank
-                * which in turn resulted in wrong registers were
-                * accessed during PHY operation. It is believed that
-                * page 0 should be used for copper PHY so reinitialize
-                * MII_MAKPHY_EADR to select default copper PHY. If parent
-                * device know the type of PHY(either copper or fiber),
-                * that information should be used to select default
-                * type of PHY.
-                */
-               PHY_WRITE(sc, MII_MAKPHY_EADR, 0);
                break;
        default:
                break;
@@ -207,20 +230,85 @@
 static void
 makphy_reset(struct mii_softc *sc)
 {
-       uint16_t pscr;
-
-       /* Assert CRS on transmit */
-       pscr = PHY_READ(sc, MII_MAKPHY_PSCR);
-       PHY_WRITE(sc, MII_MAKPHY_PSCR, pscr | PSCR_CRS_ON_TX);
+       uint16_t reg;
 
        mii_phy_reset(sc);
+
+       /*
+        * Initialize PHY Specific Control Register.
+        */
+       reg = PHY_READ(sc, MAKPHY_PSCR);
+
+       /* Assert CRS on transmit. */
+       switch (sc->mii_mpd_model) {
+       case MII_MODEL_MARVELL_E1000_0:
+       case MII_MODEL_MARVELL_E1000_3:
+       case MII_MODEL_MARVELL_E1000_5:
+       case MII_MODEL_MARVELL_E1000_6:
+       case MII_MODEL_xxMARVELL_E1000S:
+       case MII_MODEL_xxMARVELL_E1011:
+       case MII_MODEL_xxMARVELL_E1111:
+               reg |= PSCR_CRS_ON_TX;
+               break;
+       default: /* No PSCR_CRS_ON_TX bit */
+               break;
+       }
+
+       /* Enable scrambler if necessary. */
+       if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E3016)
+               reg &= ~E3016_PSCR_SCRAMBLE_DIS;
+
+       /*
+        * Store next page in the Link Partner Next Page register for
+        * compatibility with 802.3ab.
+        */
+       if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E3016)
+               reg |= E3016_PSCR_REG8NXTPG;
+
+       PHY_WRITE(sc, MAKPHY_PSCR, reg);
+
+       /* Configure LEDs if they were left unconfigured. */
+       if (sc->mii_mpd_model == MII_MODEL_xxMARVELL_E3016 &&
+           PHY_READ(sc, 0x16) == 0) {
+               reg = (0x0b << 8) | (0x05 << 4) | 0x04; /* XXX */
+               PHY_WRITE(sc, 0x16, reg);
+       }
+
+       mii_phy_reset(sc);
+}
+
+static void
+makphy_pdown(struct mii_softc *sc, bool pdown)
+{
+       int bmcr, new;
+       bool need_reset = false;
+
+       /*
+        * XXX
+        * PSCR (register 16) should be modified on some chips.
+        */
+
+       bmcr = PHY_READ(sc, MII_BMCR);
+       if (pdown)
+               new = bmcr | BMCR_PDOWN;
+       else
+               new = bmcr & ~BMCR_PDOWN;
+       if (bmcr != new)
+               need_reset = true;
+
+       if (need_reset)
+               new |= BMCR_RESET;
+       PHY_WRITE(sc, MII_BMCR, new);
 }
 
 static int
 makphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-       int reg;
+       int bmcr;
+
+       if (!device_is_active(sc->mii_dev))
+               return (ENXIO);
 
        switch (cmd) {
        case MII_POLLSTAT:
@@ -237,8 +325,8 @@
                 * isolate ourselves.
                 */
                if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
-                       reg = PHY_READ(sc, MII_BMCR);
-                       PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
+                       bmcr = PHY_READ(sc, MII_BMCR);
+                       PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO);
                        return (0);
                }
 
@@ -248,15 +336,21 @@
                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
                        break;
 
+               /* Try to power up the PHY in case it's down */
+               if (IFM_SUBTYPE(ife->ifm_media) != IFM_NONE)
+                       makphy_pdown(sc, MAKARG_PUP);
+
                mii_phy_setmedia(sc);
-               if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
-                       /*
-                        * when not in auto mode, we need to restart nego
-                        * anyway, or a switch from a fixed mode to another
-                        * fixed mode may not be seen by the switch.
-                        */
-                       PHY_WRITE(sc, MII_BMCR,
-                           PHY_READ(sc, MII_BMCR) | BMCR_STARTNEG);
+
+               /*
+                * If autonegitation is not enabled, we need a
+                * software reset for the settings to take effect.
+                */
+               if (IFM_SUBTYPE(ife->ifm_media) == IFM_NONE)
+                       makphy_pdown(sc, MAKARG_PDOWN);
+               else if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
+                       bmcr = PHY_READ(sc, MII_BMCR);
+                       PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_RESET);
                }
                break;
 
@@ -288,65 +382,73 @@
 makphy_status(struct mii_softc *sc)
 {
        struct mii_data *mii = sc->mii_pdata;
-       struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-       int bmcr, pssr, gtsr;
+       int bmcr, gsr, pssr;
 
        mii->mii_media_status = IFM_AVALID;
        mii->mii_media_active = IFM_ETHER;
 
-       pssr = PHY_READ(sc, MII_MAKPHY_PSSR);
+       bmcr = PHY_READ(sc, MII_BMCR);
+       /* XXX FIXME: Use different page for Fiber on newer chips */
+       pssr = PHY_READ(sc, MAKPHY_PSSR);
 
        if (pssr & PSSR_LINK)
                mii->mii_media_status |= IFM_ACTIVE;
 
-       bmcr = PHY_READ(sc, MII_BMCR);
+       if (bmcr & BMCR_LOOP)
+               mii->mii_media_active |= IFM_LOOP;
+
        if (bmcr & BMCR_ISO) {
                mii->mii_media_active |= IFM_NONE;
                mii->mii_media_status = 0;
                return;
        }



Home | Main Index | Thread Index | Old Index