Source-Changes-HG archive

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

[src/netbsd-1-5]: src Pullups approved by thorpej --



details:   https://anonhg.NetBSD.org/src/rev/d20202291965
branches:  netbsd-1-5
changeset: 488891:d20202291965
user:      briggs <briggs%NetBSD.org@localhost>
date:      Sun Aug 06 02:12:13 2000 +0000

description:
Pullups approved by thorpej --
Add MII support to smc91cxx driver.  This is supported for the 91c100
and 91c100FD (FEAST) controllers.  Existing controllers should continue
to work as they have.  Added the card's memory to the probe message.

Make sure that we do not call bus_space_*_multi_* with zero count.
Use bus_space_read/write_multi_stream_2 for FIFO instead of bsr/w_multi_2.

diffstat:

 share/man/man4/sm.4           |   22 +++-
 sys/conf/files                |    4 +-
 sys/dev/ic/smc91cxx.c         |  245 +++++++++++++++++++++++++++++++++++++----
 sys/dev/ic/smc91cxxreg.h      |   14 ++-
 sys/dev/ic/smc91cxxvar.h      |    9 +-
 sys/dev/isa/if_sm_isa.c       |    5 +-
 sys/dev/pcmcia/if_sm_pcmcia.c |    5 +-
 sys/dev/pcmcia/mhzc.c         |    5 +-
 8 files changed, 271 insertions(+), 38 deletions(-)

diffs (truncated from 617 to 300 lines):

diff -r c5551c40ad84 -r d20202291965 share/man/man4/sm.4
--- a/share/man/man4/sm.4       Sun Aug 06 02:08:01 2000 +0000
+++ b/share/man/man4/sm.4       Sun Aug 06 02:12:13 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sm.4,v 1.7 1999/12/15 22:07:33 abs Exp $
+.\"    $NetBSD: sm.4,v 1.7.4.1 2000/08/06 02:12:18 briggs Exp $
 .\"
 .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -40,15 +40,16 @@
 .Os
 .Sh NAME
 .Nm sm
-.Nd SMC91C9x-based Ethernet interfaces device driver
+.Nd SMC91Cxx-based Ethernet interfaces device driver
 .Sh SYNOPSIS
 .Cd "sm0 at isa? port 0x300 irq 10"
 .Cd "sm* at mhzc?"
 .Cd "sm* at pcmcia? function ?"
+.Cd "sm* at nubus?"
 .Sh DESCRIPTION
 The
 .Nm
-device driver supports SMC91C9x-based Ethernet interfaces.
+device driver supports SMC91C9x-based and SMC91C1xx-based Ethernet interfaces.
 .Pp
 The ISA attachment of the
 .Nm
@@ -64,8 +65,14 @@
 The PCMCIA attachment of the
 .Nm
 driver supports Megahertz X-JACK Ethernet cards.
+.Pp
+The nubus attachment of the
+.Nm
+driver supports SMC-based ethernet cards for the macintosh.
 .Sh MEDIA SELECTION
-The SMC91C9x supports AUI and UTP media types.
+The SMC91C1xx supports the MII interface and so the list of supported
+media depends on several factors, including which PHY is attached.  The
+SMC91C9x supports AUI and UTP media types.
 .Pp
 To enable the AUI media, select the
 .Em 10base5
@@ -79,6 +86,12 @@
 or
 .Em utp
 media type.
+.Pp
+.Xr ifconfig 8 's
+.Sq -m
+option will display the full list of supported
+.Sq media
+directives for a particular configuration.
 .Sh DIAGNOSTICS
 .Bl -diag
 .It "sm0: unable to read MAC address from CIS"
@@ -92,4 +105,5 @@
 .Xr intro 4 ,
 .Xr isa 4 ,
 .Xr mhzc 4 ,
+.Xr mii 4 ,
 .Xr pcmcia 4
diff -r c5551c40ad84 -r d20202291965 sys/conf/files
--- a/sys/conf/files    Sun Aug 06 02:08:01 2000 +0000
+++ b/sys/conf/files    Sun Aug 06 02:12:13 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.373.2.3 2000/07/30 17:54:11 bouyer Exp $
+#      $NetBSD: files,v 1.373.2.4 2000/08/06 02:12:13 briggs Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -347,7 +347,7 @@
 file   dev/ic/i82557.c                 fxp
 
 # SMC 91Cxx Ethernet Controller
-device sm: arp, ether, ifnet
+device sm: arp, ether, ifnet, mii, mii_bitbang
 file   dev/ic/smc91cxx.c               sm
 
 # SMC 83C170 EPIC/100 Fast Ethernet Controller
diff -r c5551c40ad84 -r d20202291965 sys/dev/ic/smc91cxx.c
--- a/sys/dev/ic/smc91cxx.c     Sun Aug 06 02:08:01 2000 +0000
+++ b/sys/dev/ic/smc91cxx.c     Sun Aug 06 02:12:13 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smc91cxx.c,v 1.25 2000/05/29 17:37:14 jhawk Exp $      */
+/*     $NetBSD: smc91cxx.c,v 1.25.2.1 2000/08/06 02:12:15 briggs Exp $ */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -90,6 +90,7 @@
 #include <sys/syslog.h>
 #include <sys/socket.h>
 #include <sys/device.h>
+#include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/ioctl.h> 
 #include <sys/errno.h>
@@ -131,6 +132,10 @@
 #include <net/bpfdesc.h>
 #endif
 
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include <dev/mii/mii_bitbang.h>
+
 #include <dev/ic/smc91cxxreg.h>
 #include <dev/ic/smc91cxxvar.h>
 
@@ -146,7 +151,7 @@
        "SMC91C95",                     /* 5 */
        NULL,                           /* 6 */
        "SMC91C100",                    /* 7 */
-       NULL,                           /* 8 */
+       "SMC91C100FD",                  /* 8 */
        NULL,                           /* 9 */
        NULL,                           /* 10 */
        NULL,                           /* 11 */
@@ -163,6 +168,30 @@
 };
 #define        NSMC91CxxMEDIA  (sizeof(smc91cxx_media) / sizeof(smc91cxx_media[0]))
 
+/*
+ * MII bit-bang glue.
+ */
+u_int32_t smc91cxx_mii_bitbang_read __P((struct device *));
+void smc91cxx_mii_bitbang_write __P((struct device *, u_int32_t));
+
+const struct mii_bitbang_ops smc91cxx_mii_bitbang_ops = {
+       smc91cxx_mii_bitbang_read,
+       smc91cxx_mii_bitbang_write,
+       {
+               MR_MDO,         /* MII_BIT_MDO */
+               MR_MDI,         /* MII_BIT_MDI */
+               MR_MCLK,        /* MII_BIT_MDC */
+               MR_MDOE,        /* MII_BIT_DIR_HOST_PHY */
+               0,              /* MII_BIT_DIR_PHY_HOST */
+       }
+};
+
+/* MII callbacks */
+int    smc91cxx_mii_readreg __P((struct device *, int, int));
+void   smc91cxx_mii_writereg __P((struct device *, int, int, int));
+void   smc91cxx_statchg __P((struct device *));
+void   smc91cxx_tick __P((void *));
+
 int    smc91cxx_mediachange __P((struct ifnet *));
 void   smc91cxx_mediastatus __P((struct ifnet *, struct ifmediareq *));
 
@@ -197,28 +226,41 @@
        struct ifnet *ifp = &sc->sc_ec.ec_if;
        bus_space_tag_t bst = sc->sc_bst;
        bus_space_handle_t bsh = sc->sc_bsh;
+       struct ifmedia *ifm = &sc->sc_mii.mii_media;
        const char *idstr;
+       u_int32_t miicapabilities;
        u_int16_t tmp;
        u_int8_t enaddr[ETHER_ADDR_LEN];
-       int i, aui;
+       int i, aui, mult, memsize;
+       char pbuf[9];
 
        /* Make sure the chip is stopped. */
        smc91cxx_stop(sc);
 
        SMC_SELECT_BANK(sc, 3);
        tmp = bus_space_read_2(bst, bsh, REVISION_REG_W);
+       sc->sc_chipid = RR_ID(tmp);
        /* check magic number */
        if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) {
                idstr = NULL;
                printf("%s: invalid BSR 0x%04x\n", sc->sc_dev.dv_xname, tmp);
        } else
-               idstr = smc91cxx_idstrs[RR_ID(tmp)];
+               idstr = smc91cxx_idstrs[sc->sc_chipid];
        printf("%s: ", sc->sc_dev.dv_xname);
        if (idstr != NULL)
                printf("%s, ", idstr);
        else
-               printf("unknown chip id %d, ", RR_ID(tmp));
-       printf("revision %d\n", RR_REV(tmp));
+               printf("unknown chip id %d, ", sc->sc_chipid);
+       printf("revision %d, ", RR_REV(tmp));
+
+       SMC_SELECT_BANK(sc, 0);
+       mult = MCR_MEM_MULT(bus_space_read_2(bst, bsh, MEM_CFG_REG_W));
+       memsize = bus_space_read_2(bst, bsh, MEM_INFO_REG_W) & MIR_TOTAL_MASK;
+       if (memsize == 255) memsize++;
+       memsize *= 256 * mult;
+
+       format_bytes(pbuf, sizeof(pbuf), memsize);
+       printf("buffer size: %s\n", pbuf);
 
        /* Read the station address from the chip. */
        SMC_SELECT_BANK(sc, 1);
@@ -233,11 +275,6 @@
        printf("%s: MAC address %s, ", sc->sc_dev.dv_xname,
            ether_sprintf(myea));
 
-       /* ..and default media. */
-       tmp = bus_space_read_2(bst, bsh, CONFIG_REG_W);
-       printf("default media %s\n", (aui = (tmp & CR_AUI_SELECT)) ?
-           "AUI" : "UTP");
-
        /* Initialize the ifnet structure. */
        bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
        ifp->if_softc = sc;
@@ -251,12 +288,53 @@
        if_attach(ifp);
        ether_ifattach(ifp, myea);
 
-       /* Initialize the media structures. */
-       ifmedia_init(&sc->sc_media, 0, smc91cxx_mediachange,
-           smc91cxx_mediastatus);
-       for (i = 0; i < NSMC91CxxMEDIA; i++)
-               ifmedia_add(&sc->sc_media, smc91cxx_media[i], 0, NULL);
-       ifmedia_set(&sc->sc_media, IFM_ETHER | (aui ? IFM_10_5 : IFM_10_T));
+       /*
+        * Initialize our media structures and MII info.  We will
+        * probe the MII if we are on the SMC91Cxx
+        */
+       sc->sc_mii.mii_ifp = ifp;
+       sc->sc_mii.mii_readreg = smc91cxx_mii_readreg;
+       sc->sc_mii.mii_writereg = smc91cxx_mii_writereg;
+       sc->sc_mii.mii_statchg = smc91cxx_statchg;
+       ifmedia_init(ifm, 0, smc91cxx_mediachange, smc91cxx_mediastatus);
+
+       SMC_SELECT_BANK(sc, 1);
+       tmp = bus_space_read_2(bst, bsh, CONFIG_REG_W);
+
+       miicapabilities = BMSR_MEDIAMASK;
+       switch (sc->sc_chipid) {
+       case CHIP_91100:
+               /*
+                * The 91100 does not have full-duplex capabilities,
+                * even if the PHY does.
+                */
+               miicapabilities &= ~(BMSR_100TXFDX | BMSR_10TFDX);
+       case CHIP_91100FD:
+               if (tmp & CR_MII_SELECT) {
+                       printf("default media MII\n");
+                       mii_attach(&sc->sc_dev, &sc->sc_mii, miicapabilities,
+                           MII_PHY_ANY, MII_OFFSET_ANY, 0);
+                       if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
+                               ifmedia_add(&sc->sc_mii.mii_media,
+                                   IFM_ETHER|IFM_NONE, 0, NULL);
+                               ifmedia_set(&sc->sc_mii.mii_media,
+                                   IFM_ETHER|IFM_NONE);
+                       } else {
+                               ifmedia_set(&sc->sc_mii.mii_media,
+                                   IFM_ETHER|IFM_AUTO);
+                       }
+                       sc->sc_flags |= SMC_FLAGS_HAS_MII;
+                       break;
+               }
+               /*FALLTHROUGH*/
+       default:
+               printf("default media %s\n", (aui = (tmp & CR_AUI_SELECT)) ?
+                   "AUI" : "UTP");
+               for (i = 0; i < NSMC91CxxMEDIA; i++)
+                       ifmedia_add(ifm, smc91cxx_media[i], 0, NULL);
+               ifmedia_set(ifm, IFM_ETHER | (aui ? IFM_10_5 : IFM_10_T));
+               break;
+       }
 
 #if NBPFILTER > 0
        bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
@@ -280,7 +358,7 @@
 {
        struct smc91cxx_softc *sc = ifp->if_softc;
 
-       return (smc91cxx_set_media(sc, sc->sc_media.ifm_media));
+       return (smc91cxx_set_media(sc, sc->sc_mii.mii_media.ifm_media));
 }
 
 int
@@ -303,6 +381,9 @@
        if (IFM_TYPE(media) != IFM_ETHER)
                return (EINVAL);
 
+       if (sc->sc_flags & SMC_FLAGS_HAS_MII)
+               return (mii_mediachg(&sc->sc_mii));
+
        switch (IFM_SUBTYPE(media)) {
        case IFM_10_T:
        case IFM_10_5:
@@ -342,6 +423,16 @@
                return;
        }
 
+       /*
+        * If we have MII, go ask the PHY what's going on.
+        */
+       if (sc->sc_flags & SMC_FLAGS_HAS_MII) {
+               mii_pollstat(&sc->sc_mii);
+               ifmr->ifm_active = sc->sc_mii.mii_media_active;
+               ifmr->ifm_status = sc->sc_mii.mii_media_status;
+               return;
+       }
+



Home | Main Index | Thread Index | Old Index