Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Handle allmulti case correctly as a NetBSD network d...



details:   https://anonhg.NetBSD.org/src/rev/d2db9c4af3c0
branches:  trunk
changeset: 503024:d2db9c4af3c0
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Jan 29 01:24:42 2001 +0000

description:
Handle allmulti case correctly as a NetBSD network driver;
if we are requested range of multicast address or too many multicast address,
program multicast filter to receive all multicast address.   And set/clear
IFF_ALLMULTI flag properly.

diffstat:

 sys/dev/ic/rtl81x9.c |  10 +++++--
 sys/dev/pci/if_ti.c  |  66 +++++++++++++++++++++++++++++++++++----------------
 sys/dev/pci/if_vr.c  |  13 +++++++---
 sys/dev/usb/if_aue.c |  18 +++++++-------
 sys/dev/usb/if_cue.c |  18 +++++++-------
 sys/dev/usb/if_kue.c |  33 +++++++++++--------------
 6 files changed, 93 insertions(+), 65 deletions(-)

diffs (truncated from 341 to 300 lines):

diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/ic/rtl81x9.c
--- a/sys/dev/ic/rtl81x9.c      Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/ic/rtl81x9.c      Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtl81x9.c,v 1.27 2001/01/11 14:38:58 tsutsui Exp $     */
+/*     $NetBSD: rtl81x9.c,v 1.28 2001/01/29 01:24:42 enami Exp $       */
 
 /*
  * Copyright (c) 1997, 1998
@@ -564,7 +564,9 @@
 
        rxfilt = CSR_READ_4(sc, RTK_RXCFG);
 
-       if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+       if (ifp->if_flags & IFF_PROMISC) {
+allmulti:
+               ifp->if_flags |= IFF_ALLMULTI;
                rxfilt |= RTK_RXCFG_RX_MULTI;
                CSR_WRITE_4(sc, RTK_RXCFG, rxfilt);
                CSR_WRITE_4(sc, RTK_MAR0, 0xFFFFFFFF);
@@ -581,7 +583,7 @@
        while (enm != NULL) {
                if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
                    ETHER_ADDR_LEN) != 0)
-                       continue;
+                       goto allmulti;
 
                h = rtk_calchash(enm->enm_addrlo);
                if (h < 32)
@@ -592,6 +594,8 @@
                ETHER_NEXT_MULTI(step, enm);
        }
 
+       ifp->if_flags &= ~IFF_ALLMULTI;
+
        if (mcnt)
                rxfilt |= RTK_RXCFG_RX_MULTI;
        else
diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/pci/if_ti.c
--- a/sys/dev/pci/if_ti.c       Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/pci/if_ti.c       Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.19 2001/01/18 20:28:15 jdolecek Exp $ */
+/* $NetBSD: if_ti.c,v 1.20 2001/01/29 01:24:42 enami Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -1189,40 +1189,62 @@
 
        ifp = &sc->ethercom.ec_if;
 
-       if (ifp->if_flags & IFF_ALLMULTI) {
-               TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0);
-               return;
-       } else {
-               TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0);
-       }
-
        /* Disable interrupts. */
        intrs = CSR_READ_4(sc, TI_MB_HOSTINTR);
        CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1);
 
        /* First, zot all the existing filters. */
-       while (SIMPLEQ_FIRST(&sc->ti_mc_listhead) != NULL) {
-               mc = SIMPLEQ_FIRST(&sc->ti_mc_listhead);
+       while ((mc = SIMPLEQ_FIRST(&sc->ti_mc_listhead)) != NULL) {
                ti_del_mcast(sc, &mc->mc_addr);
                SIMPLEQ_REMOVE_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
                free(mc, M_DEVBUF);
        }
 
-       /* Now program new ones. */
+       /*
+        * Remember all multicast addresses so that we can delete them
+        * later.  Punt if there is a range of addresses or memory shortage.
+        */
        ETHER_FIRST_MULTI(step, &sc->ethercom, enm);
        while (enm != NULL) {
-               mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF, M_NOWAIT);
-               bcopy(enm->enm_addrlo,
-                   (char *)&mc->mc_addr, ETHER_ADDR_LEN);
+               if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
+                   ETHER_ADDR_LEN) != 0)
+                       goto allmulti;
+               if ((mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF,
+                   M_NOWAIT)) == NULL)
+                       goto allmulti;
+               memcpy(&mc->mc_addr, enm->enm_addrlo, ETHER_ADDR_LEN);
                SIMPLEQ_INSERT_HEAD(&sc->ti_mc_listhead, mc, mc_entries);
-               ti_add_mcast(sc, &mc->mc_addr);
                ETHER_NEXT_MULTI(step, enm);
        }
 
+       /* Accept only programmed multicast addresses */
+       ifp->if_flags &= ~IFF_ALLMULTI;
+       TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0);
+
+       /* Now program new ones. */
+       for (mc = SIMPLEQ_FIRST(&sc->ti_mc_listhead); mc != NULL;
+           mc = SIMPLEQ_NEXT(mc, mc_entries))
+               ti_add_mcast(sc, &mc->mc_addr);
+
        /* Re-enable interrupts. */
        CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs);
 
        return;
+
+allmulti:
+       /* No need to keep individual multicast addresses */
+       while ((mc = SIMPLEQ_FIRST(&sc->ti_mc_listhead)) != NULL) {
+               SIMPLEQ_REMOVE_HEAD(&sc->ti_mc_listhead, mc,
+                   mc_entries);
+               free(mc, M_DEVBUF);
+       }
+
+       /* Accept all multicast addresses */
+       ifp->if_flags |= IFF_ALLMULTI;
+       TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0);
+
+       /* Re-enable interrupts. */
+       CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs);
 }
 
 /*
@@ -1761,6 +1783,8 @@
                goto fail2;
        }
 
+       SIMPLEQ_INIT(&sc->ti_mc_listhead);
+
        /*
         * We really need a better way to tell a 1000baseTX card
         * from a 1000baseSX one, since in theory there could be
@@ -2600,12 +2624,12 @@
                break;
        case SIOCADDMULTI:
        case SIOCDELMULTI:
-               if (command == SIOCADDMULTI)
-                       ether_addmulti(ifr, &sc->ethercom);
-               else
-                       ether_delmulti(ifr, &sc->ethercom);
-               if (ifp->if_flags & IFF_RUNNING) {
-                       ti_setmulti(sc);
+               error = (command == SIOCADDMULTI) ?
+                   ether_addmulti(ifr, &sc->ethercom) :
+                   ether_delmulti(ifr, &sc->ethercom);
+               if (error == ENETRESET) {
+                       if (ifp->if_flags & IFF_RUNNING)
+                               ti_setmulti(sc);
                        error = 0;
                }
                break;
diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/pci/if_vr.c
--- a/sys/dev/pci/if_vr.c       Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/pci/if_vr.c       Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vr.c,v 1.44 2000/12/28 22:59:14 sommerfeld Exp $    */
+/*     $NetBSD: if_vr.c,v 1.45 2001/01/29 01:24:42 enami Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -479,7 +479,9 @@
 
        rxfilt = CSR_READ_1(sc, VR_RXCFG);
 
-       if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+       if (ifp->if_flags & IFF_PROMISC) {
+allmulti:
+               ifp->if_flags |= IFF_ALLMULTI;
                rxfilt |= VR_RXCFG_RX_MULTI;
                CSR_WRITE_1(sc, VR_RXCFG, rxfilt);
                CSR_WRITE_4(sc, VR_MAR0, 0xFFFFFFFF);
@@ -494,8 +496,9 @@
        /* now program new ones */
        ETHER_FIRST_MULTI(step, &sc->vr_ec, enm);
        while (enm != NULL) {
-               if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0)
-                       continue;
+               if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
+                   ETHER_ADDR_LEN) != 0)
+                       goto allmulti;
 
                h = vr_calchash(enm->enm_addrlo);
 
@@ -507,6 +510,8 @@
                mcnt++;
        }
 
+       ifp->if_flags &= ~IFF_ALLMULTI;
+
        if (mcnt)
                rxfilt |= VR_RXCFG_RX_MULTI;
        else
diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/usb/if_aue.c
--- a/sys/dev/usb/if_aue.c      Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/usb/if_aue.c      Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_aue.c,v 1.53 2001/01/21 19:42:29 augustss Exp $     */
+/*     $NetBSD: if_aue.c,v 1.54 2001/01/29 01:24:43 enami Exp $        */
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
  *     Bill Paul <wpaul%ee.columbia.edu@localhost>.  All rights reserved.
@@ -530,7 +530,9 @@
 
        ifp = GET_IFP(sc);
 
-       if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+       if (ifp->if_flags & IFF_PROMISC) {
+allmulti:
+               ifp->if_flags |= IFF_ALLMULTI;
                AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
                return;
        }
@@ -548,18 +550,16 @@
        ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
 #endif
        while (enm != NULL) {
-#if 1
                if (memcmp(enm->enm_addrlo,
-                          enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
-                       ifp->if_flags |= IFF_ALLMULTI;
-                       AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
-                       return;
-               }
-#endif
+                   enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
+                       goto allmulti;
+
                h = aue_crc(enm->enm_addrlo);
                AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
                ETHER_NEXT_MULTI(step, enm);
        }
+
+       ifp->if_flags &= ~IFF_ALLMULTI;
 }
 
 Static void
diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/usb/if_cue.c
--- a/sys/dev/usb/if_cue.c      Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/usb/if_cue.c      Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cue.c,v 1.32 2001/01/23 17:04:30 augustss Exp $     */
+/*     $NetBSD: if_cue.c,v 1.33 2001/01/29 01:24:43 enami Exp $        */
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
  *     Bill Paul <wpaul%ee.columbia.edu@localhost>.  All rights reserved.
@@ -389,7 +389,9 @@
        DPRINTFN(2,("%s: cue_setmulti if_flags=0x%x\n", 
                    USBDEVNAME(sc->cue_dev), ifp->if_flags));
 
-       if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+       if (ifp->if_flags & IFF_PROMISC) {
+allmulti:
+               ifp->if_flags |= IFF_ALLMULTI;
                for (i = 0; i < CUE_MCAST_TABLE_LEN; i++)
                        sc->cue_mctab[i] = 0xFF;
                cue_mem(sc, CUE_CMD_WRITESRAM, CUE_MCAST_TABLE_ADDR,
@@ -408,19 +410,17 @@
        ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
 #endif
        while (enm != NULL) {
-#if 0
                if (memcmp(enm->enm_addrlo,
-                          enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
-                       ifp->if_flags |= IFF_ALLMULTI;
-                       /* XXX what now? */
-                       return;
-               }
-#endif
+                   enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
+                       goto allmulti;
+
                h = cue_crc(enm->enm_addrlo);
                sc->cue_mctab[h >> 3] |= 1 << (h & 0x7);                
                ETHER_NEXT_MULTI(step, enm);
        }
 
+       ifp->if_flags &= ~IFF_ALLMULTI;
+
        /*
         * Also include the broadcast address in the filter
         * so we can receive broadcast frames.
diff -r 6b1d7bc32609 -r d2db9c4af3c0 sys/dev/usb/if_kue.c
--- a/sys/dev/usb/if_kue.c      Mon Jan 29 01:23:22 2001 +0000
+++ b/sys/dev/usb/if_kue.c      Mon Jan 29 01:24:42 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_kue.c,v 1.37 2001/01/21 15:55:05 augustss Exp $     */
+/*     $NetBSD: if_kue.c,v 1.38 2001/01/29 01:24:43 enami Exp $        */
 /*
  * Copyright (c) 1997, 1998, 1999, 2000
  *     Bill Paul <wpaul%ee.columbia.edu@localhost>.  All rights reserved.
@@ -321,7 +321,9 @@
 
        DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__));
 
-       if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
+       if (ifp->if_flags & IFF_PROMISC) {
+allmulti:
+               ifp->if_flags |= IFF_ALLMULTI;
                sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI;



Home | Main Index | Thread Index | Old Index