Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/sociox extend mii_statchg() to use ether_mediac...



details:   https://anonhg.NetBSD.org/src/rev/b4082d47e31d
branches:  trunk
changeset: 746299:b4082d47e31d
user:      nisimura <nisimura%NetBSD.org@localhost>
date:      Fri Mar 27 13:00:13 2020 +0000

description:
extend mii_statchg() to use ether_mediachange(). care about hash filter selection.

diffstat:

 sys/arch/arm/sociox/if_ave.c |  90 +++++++++++++++----------------------------
 sys/arch/arm/sociox/if_scx.c |  73 +++++++++++++----------------------
 2 files changed, 59 insertions(+), 104 deletions(-)

diffs (truncated from 329 to 300 lines):

diff -r 3e1c9c3e4647 -r b4082d47e31d sys/arch/arm/sociox/if_ave.c
--- a/sys/arch/arm/sociox/if_ave.c      Fri Mar 27 11:15:33 2020 +0000
+++ b/sys/arch/arm/sociox/if_ave.c      Fri Mar 27 13:00:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ave.c,v 1.15 2020/03/24 03:08:02 nisimura Exp $     */
+/*     $NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $     */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -36,15 +36,16 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.15 2020/03/24 03:08:02 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ave.c,v 1.16 2020/03/27 13:00:22 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/intr.h>
 #include <sys/device.h>
 #include <sys/callout.h>
+#include <sys/ioctl.h>
+#include <sys/malloc.h>
 #include <sys/mbuf.h>
-#include <sys/malloc.h>
 #include <sys/errno.h>
 #include <sys/rndsource.h>
 #include <sys/kernel.h>
@@ -249,7 +250,6 @@
 static int ave_ioctl(struct ifnet *, u_long, void *);
 static void ave_set_rcvfilt(struct ave_softc *);
 static void ave_write_filt(struct ave_softc *, int, const uint8_t *);
-static int ave_ifmedia_upd(struct ifnet *);
 static void ave_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 static void mii_statchg(struct ifnet *);
 static void lnkchg(struct ave_softc *);
@@ -384,19 +384,17 @@
        sc->sc_model = of_search_compatible(phandle, compat_data)->data;
 
        phy_mode = fdtbus_get_string(phandle, "phy-mode");
-       if (phy_mode == NULL) {
+       if (phy_mode == NULL)
                aprint_error(": missing 'phy-mode' property\n");
-               phy_mode = "rgmii";
-       }
 
        aprint_naive("\n");
        aprint_normal(": Gigabit Ethernet Controller\n");
-       aprint_normal_dev(self, "UniPhier %c%c%c%c AVE%d GbE (%d.%d) %s\n",
+       aprint_normal_dev(self, "UniPhier %c%c%c%c AVE%d GbE (%d.%d)\n",
            hwimp >> 24, hwimp >> 16, hwimp >> 8, hwimp,
-           sc->sc_model, hwver >> 8, hwver & 0xff, phy_mode);
+           sc->sc_model, hwver >> 8, hwver & 0xff);
        aprint_normal_dev(self, "interrupt on %s\n", intrstr);
 
-       sc->sc_100mii = (strcmp(phy_mode, "rgmii") != 0);
+       sc->sc_100mii = (phy_mode && strcmp(phy_mode, "rgmii") != 0);
        sc->sc_desops = (sc->sc_model == 64) ? &ave64ops : &ave32ops;
 
        CSR_WRITE(sc, AVEGR, GR_GRST | GR_PHYRST);
@@ -429,7 +427,7 @@
        sc->sc_phy_id = MII_PHY_ANY;
 
        sc->sc_ethercom.ec_mii = mii;
-       ifmedia_init(ifm, 0, ave_ifmedia_upd, ave_ifmedia_sts);
+       ifmedia_init(ifm, 0, ether_mediachange, ave_ifmedia_sts);
        mii_attach(sc->sc_dev, mii, 0xffffffff, sc->sc_phy_id,
            MII_OFFSET_ANY, MIIF_DOPAUSE);
        if (LIST_FIRST(&mii->mii_phys) == NULL) {
@@ -586,7 +584,7 @@
        /* accept multicast frame or run promisc mode */
        ave_set_rcvfilt(sc);
 
-       (void)ave_ifmedia_upd(ifp);
+       (void)ether_mediachange(ifp);
 
        csr = CSR_READ(sc, AVECFG);
        if (ifp->if_capenable & IFCAP_CSUM_IPv4_Tx) {
@@ -636,49 +634,6 @@
        ifp->if_timer = 0;
 }
 
-static int
-ave_ifmedia_upd(struct ifnet *ifp)
-{
-       struct ave_softc *sc = ifp->if_softc;
-       struct ifmedia *ifm = &sc->sc_mii.mii_media;
-       uint32_t txcr, rxcr, csr;
-
-       txcr = CSR_READ(sc, AVETXC);
-       rxcr = CSR_READ(sc, AVERXC);
-       CSR_WRITE(sc, AVERXC, rxcr &~ RXC_EN); /* stop Rx first */
-
-       if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_AUTO) {
-               ; /* restart AN */
-               ; /* enable AN */
-               ; /* advertise flow control pause */
-               ; /* adv. 1000FDX,100FDX,100HDX,10FDX,10HDX */
-       } else {
-#if 1 /* XXX not sure to belong here XXX */
-               txcr &= ~(TXC_SPD1000 | TXC_SPD100);
-               rxcr &= ~RXC_USEFDX;
-               if ((sc->sc_100mii == 0) /* RGMII model */
-                    && IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
-                       txcr |= TXC_SPD1000;
-               else if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
-                       txcr |= TXC_SPD100;
-               if (ifm->ifm_media & IFM_FDX)
-                       rxcr |= RXC_USEFDX;     
-
-               /* adjust LINKSEL when RMII/MII too */
-               if (sc->sc_100mii) {
-                       csr = CSR_READ(sc, AVELINKSEL) &~ LINKSEL_SPD100;
-                       if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
-                               csr |= LINKSEL_SPD100;
-                       CSR_WRITE(sc, AVELINKSEL, csr);
-               }
-#endif
-       }
-       sc->sc_rxc = rxcr;
-       CSR_WRITE(sc, AVETXC, txcr);
-       CSR_WRITE(sc, AVERXC, rxcr | RXC_EN);
-       return 0;
-}
-
 static void
 ave_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
@@ -696,7 +651,8 @@
 {
        struct ave_softc *sc = ifp->if_softc;
        struct mii_data *mii = &sc->sc_mii;
-       uint32_t txcr, rxcr;
+       struct ifmedia *ifm = &mii->mii_media;
+       uint32_t txcr, rxcr, lsel;
 
        /* Get flow control negotiation result. */
        if (IFM_SUBTYPE(mii->mii_media.ifm_cur->ifm_media) == IFM_AUTO &&
@@ -707,14 +663,30 @@
        rxcr = CSR_READ(sc, AVERXC);
        CSR_WRITE(sc, AVERXC, rxcr &~ RXC_EN); /* stop Rx first */
 
-       /* Adjust 802.3x PAUSE flow control. */
+       /* Adjust speed 1000/100/10. */
+       txcr &= ~(TXC_SPD1000 | TXC_SPD100);
+       if ((sc->sc_100mii == 0) /* RGMII model */
+            && IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
+               txcr |= TXC_SPD1000;
+       else if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
+               txcr |= TXC_SPD100;
+
+       /* Adjust LINKSEL when RMII/MII too. */
+       if (sc->sc_100mii) {
+               lsel = CSR_READ(sc, AVELINKSEL) &~ LINKSEL_SPD100;
+               if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX)
+                       lsel |= LINKSEL_SPD100;
+               CSR_WRITE(sc, AVELINKSEL, lsel);
+       }
+
+       /* Adjust duplexity and 802.3x PAUSE flow control. */
        txcr &= ~TXC_FCE;
-       rxcr &= ~RXC_FCE;
+       rxcr &= ~(RXC_FCE & RXC_USEFDX);
        if (mii->mii_media_active & IFM_FDX) {
                if (sc->sc_flowflags & IFM_ETH_TXPAUSE)
                        txcr |= TXC_FCE;
                if (sc->sc_flowflags & IFM_ETH_RXPAUSE)
-                       rxcr |= RXC_FCE;
+                       rxcr |= RXC_FCE | RXC_USEFDX;
        }
 
        sc->sc_rxc = rxcr;
diff -r 3e1c9c3e4647 -r b4082d47e31d sys/arch/arm/sociox/if_scx.c
--- a/sys/arch/arm/sociox/if_scx.c      Fri Mar 27 11:15:33 2020 +0000
+++ b/sys/arch/arm/sociox/if_scx.c      Fri Mar 27 13:00:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $     */
+/*     $NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $     */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.20 2020/03/27 09:19:33 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_scx.c,v 1.21 2020/03/27 13:00:13 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -224,8 +224,7 @@
 #define GMACEVCTL      0x0100          /* event counter control */
 #define GMACEVCNT(i)   ((i)*4+0x114)   /* event counter 0x114~284 */
 
-#define GMACMHT0       0x0500          /* 256bit multicast hash table 0 - 7 */
-#define GMACMHT(i)     ((i)*4+0x500)
+#define GMACMHT(i)     ((i)*4+0x500)   /* 256bit multicast hash table 0 - 7 */
 #define GMACVHT                0x0588          /* VLAN tag hash */
 
 /* 0x0700-0734 ??? */
@@ -452,7 +451,6 @@
 static void scx_watchdog(struct ifnet *);
 static int scx_ioctl(struct ifnet *, u_long, void *);
 static void scx_set_rcvfilt(struct scx_softc *);
-static int scx_ifmedia_upd(struct ifnet *);
 static void scx_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 static void mii_statchg(struct ifnet *);
 static void phy_tick(void *);
@@ -709,7 +707,7 @@
        mii->mii_statchg = mii_statchg;
 
        sc->sc_ethercom.ec_mii = mii;
-       ifmedia_init(ifm, 0, scx_ifmedia_upd, scx_ifmedia_sts);
+       ifmedia_init(ifm, 0, ether_mediachange, scx_ifmedia_sts);
        mii_attach(sc->sc_dev, mii, 0xffffffff, sc->sc_phy_id,
            MII_OFFSET_ANY, MIIF_DOPAUSE);
        if (LIST_FIRST(&mii->mii_phys) == NULL) {
@@ -881,7 +879,7 @@
        /* accept multicast frame or run promisc mode */
        scx_set_rcvfilt(sc);
 
-       (void)scx_ifmedia_upd(ifp);
+       (void)ether_mediachange(ifp);
 
        /* build sane Tx */
        memset(sc->sc_txdescs, 0, sizeof(struct tdes) * MD_NTXDESC);
@@ -1077,16 +1075,16 @@
                i++;
        }
        ETHER_UNLOCK(ec);
-
        if (crc)
-               csr |= AFR_MHTE | AFR_HPF; /* use hash+perfect */
+               csr |= AFR_MHTE;
+       csr |= AFR_HPF; /* use hash+perfect */
        mac_write(sc, GMACMHTH, mchash[1]);
        mac_write(sc, GMACMHTL, mchash[0]);
        mac_write(sc, GMACAFR, csr);
        return;
 
  update:
-       /* With PM or AM, MHTE/MHT0-7 are never consulted. really? */
+       /* With PR or PM, MHTE/MHTL/MHTH are never consulted. really? */
        if (ifp->if_flags & IFF_PROMISC)
                csr |= AFR_PR;  /* run promisc. mode */
        else
@@ -1095,39 +1093,6 @@
        return;
 }
 
-static int
-scx_ifmedia_upd(struct ifnet *ifp)
-{
-       struct scx_softc *sc = ifp->if_softc;
-       struct ifmedia *ifm = &sc->sc_mii.mii_media;
-
-       if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_AUTO) {
-               ; /* restart AN */
-               ; /* enable AN */
-               ; /* advertise flow control pause */
-               ; /* adv. 1000FDX,100FDX,100HDX,10FDX,10HDX */
-       } else {
-#if 1 /* XXX not sure to belong here XXX */
-               uint32_t mcr = mac_read(sc, GMACMCR);
-               if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_1000_T)
-                       mcr &= ~MCR_USEMII; /* RGMII+SPD1000 */
-               else {
-                       if (IFM_SUBTYPE(ifm->ifm_cur->ifm_media) == IFM_100_TX
-                           && sc->sc_100mii)
-                               mcr |= MCR_SPD100;
-                       mcr |= MCR_USEMII;
-               }
-               if (ifm->ifm_cur->ifm_media & IFM_FDX)
-                       mcr |= MCR_USEFDX;
-               mcr |= MCR_CST | MCR_JE;
-               if (sc->sc_100mii == 0)
-                       mcr |= MCR_IBN;
-               mac_write(sc, GMACMCR, mcr);
-#endif
-       }
-       return 0;
-}
-
 static void
 scx_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
 {
@@ -1145,7 +1110,8 @@
 {
        struct scx_softc *sc = ifp->if_softc;
        struct mii_data *mii = &sc->sc_mii;
-       uint32_t fcr;
+       struct ifmedia * ifm = &mii->mii_media;
+       uint32_t mcr, fcr;
 
 #if 1
        /* decode MIISR register value */
@@ -1165,14 +1131,31 @@
            (mii->mii_media_active & IFM_ETH_FMASK) != sc->sc_flowflags)
                sc->sc_flowflags = mii->mii_media_active & IFM_ETH_FMASK;
 



Home | Main Index | Thread Index | Old Index