Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Avoid feeding negative values to the `roundup()' ...



details:   https://anonhg.NetBSD.org/src/rev/f23ded0b6547
branches:  trunk
changeset: 479674:f23ded0b6547
user:      pk <pk%NetBSD.org@localhost>
date:      Fri Dec 17 14:37:15 1999 +0000

description:
Avoid feeding negative values to the `roundup()' macro.
Configure the MII management interface earlier.

diffstat:

 sys/dev/ic/hme.c |  57 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 40 insertions(+), 17 deletions(-)

diffs (136 lines):

diff -r 41b93d7387c1 -r f23ded0b6547 sys/dev/ic/hme.c
--- a/sys/dev/ic/hme.c  Fri Dec 17 14:34:25 1999 +0000
+++ b/sys/dev/ic/hme.c  Fri Dec 17 14:37:15 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hme.c,v 1.3 1999/12/15 10:33:31 pk Exp $       */
+/*     $NetBSD: hme.c,v 1.4 1999/12/17 14:37:15 pk Exp $       */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -100,6 +100,7 @@
 void           hme_shutdown __P((void *));
 void           hme_init __P((struct hme_softc *));
 void           hme_meminit __P((struct hme_softc *));
+void           hme_mifinit __P((struct hme_softc *));
 void           hme_reset __P((struct hme_softc *));
 void           hme_setladrf __P((struct hme_softc *));
 
@@ -242,6 +243,8 @@
 
        ifmedia_init(&mii->mii_media, 0, hme_mediachange, hme_mediastatus);
 
+       hme_mifinit(sc);
+
        mii_phy_probe(&sc->sc_dev, mii, 0xffffffff,
                        MII_PHY_ANY, MII_OFFSET_ANY);
 
@@ -340,17 +343,20 @@
        hr->rb_txddma = dma;
        p += ntbuf * HME_XD_SIZE;
        dma += ntbuf * HME_XD_SIZE;
+       /* We have reserved descriptor space until the next 2048 byte boundary.*/
+       dma = (bus_addr_t)roundup((u_long)dma, 2048);
+       p = (caddr_t)roundup((u_long)p, 2048);
 
        /*
         * Allocate receive descriptors
-        * Buffer descriptors must be aligned on a 2048 byte boundary.
         */
-       dma = (bus_addr_t)roundup((long)dma, 2048);
-       p = (caddr_t)roundup((long)p, 2048);
        hr->rb_rxd = p;
        hr->rb_rxddma = dma;
        p += nrbuf * HME_XD_SIZE;
        dma += nrbuf * HME_XD_SIZE;
+       /* Again move forward to the next 2048 byte boundary.*/
+       dma = (bus_addr_t)roundup((u_long)dma, 2048);
+       p = (caddr_t)roundup((u_long)p, 2048);
 
 
        /*
@@ -419,6 +425,9 @@
        /* step 1 & 2. Reset the Ethernet Channel */
        hme_stop(sc);
 
+       /* Re-initialize the MIF */
+       hme_mifinit(sc);
+
        /* Call MI reset function if any */
        if (sc->sc_hwreset)
                (*sc->sc_hwreset)(sc);
@@ -531,9 +540,9 @@
        /* step 11. XIF Configuration */
        v = bus_space_read_4(t, mac, HME_MACI_XIF);
        v |= HME_MAC_XIF_OE;
-       /* If an external transceiver is connected, disable MII drivers */
+       /* If an external transceiver is connected, enable its MII drivers */
        if ((bus_space_read_4(t, mif, HME_MIFI_CFG) & HME_MIF_CFG_MDI1) != 0)
-               v |= HME_MAC_XIF_MIIDISAB;
+               v |= HME_MAC_XIF_MIIENABLE;
        bus_space_write_4(t, mac, HME_MACI_XIF, v);
 
 
@@ -549,14 +558,6 @@
 
        /* step 14. Issue Transmit Pending command */
 
-       /*
-        * Put MIF in frame mode
-        * XXX - do bit-bang mode later
-        */
-       v = bus_space_read_4(t, mif, HME_MIFI_CFG);
-       v &= ~HME_MIF_CFG_BBMODE;
-       bus_space_write_4(t, mif, HME_MIFI_CFG, v);
-
        /* Call MI initialization function if any */
        if (sc->sc_hwinit)
                (*sc->sc_hwinit)(sc);
@@ -727,7 +728,7 @@
 
                if ((ifp->if_flags & IFF_PROMISC) != 0 &&
                    (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
-                   ether_cmp(eh->ether_dhost, sc->sc_enaddr)) {
+                   ether_cmp(eh->ether_dhost, sc->sc_enaddr) == 0) {
                        m_freem(m);
                        return;
                }
@@ -878,8 +879,13 @@
                if (flags & HME_XD_OWN)
                        break;
 
-               len = HME_XD_DECODE_RSIZE(flags);
-               hme_read(sc, ri, len);
+               if (flags & HME_XD_OFL) {
+                       printf("%s: buffer overflow, ri=%d; flags=0x%x\n",
+                                       sc->sc_dev.dv_xname, ri, flags);
+               } else {
+                       len = HME_XD_DECODE_RSIZE(flags);
+                       hme_read(sc, ri, len);
+               }
 
                /* This buffer can be used by the hardware again */
                HME_XD_SETFLAGS(xdr, ri,
@@ -949,6 +955,23 @@
 }
 
 /*
+ * Initialize the MII Management Interface
+ */
+void
+hme_mifinit(sc)
+       struct hme_softc *sc;
+{
+       bus_space_tag_t t = sc->sc_bustag;
+       bus_space_handle_t mif = sc->sc_mif;
+       u_int32_t v;
+
+       /* Configure the MIF in frame mode */
+       v = bus_space_read_4(t, mif, HME_MIFI_CFG);
+       v &= ~HME_MIF_CFG_BBMODE;
+       bus_space_write_4(t, mif, HME_MIFI_CFG, v);
+}
+
+/*
  * MII interface
  */
 static int



Home | Main Index | Thread Index | Old Index