Module Name:    src
Committed By:   bouyer
Date:           Thu Apr 28 17:32:48 UTC 2011

Modified Files:
        src/sys/dev/pci: if_vte.c if_vtereg.h

Log Message:
- Properly count collisions
- call vte_rxfilter() after starting transmit/receive; this seems to
  fix some IPv6-related multicast issues for me
- when the MCR0_BROADCAST bit is set broadcast receive is disabled.
  Rename it to MCR0_BROADCAST_DIS to reflect its function, and fix usage.
- Fix loop over multicast addresses to not set the same address in the
  3 perfect filter slots.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pci/if_vte.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/pci/if_vtereg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_vte.c
diff -u src/sys/dev/pci/if_vte.c:1.2 src/sys/dev/pci/if_vte.c:1.3
--- src/sys/dev/pci/if_vte.c:1.2	Sat Apr  2 08:11:31 2011
+++ src/sys/dev/pci/if_vte.c	Thu Apr 28 17:32:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vte.c,v 1.2 2011/04/02 08:11:31 mbalmer Exp $	*/
+/*	$NetBSD: if_vte.c,v 1.3 2011/04/28 17:32:48 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2011 Manuel Bouyer.  All rights reserved.
@@ -55,7 +55,7 @@
 /* Driver for DM&P Electronics, Inc, Vortex86 RDC R6040 FastEthernet. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vte.c,v 1.2 2011/04/02 08:11:31 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vte.c,v 1.3 2011/04/28 17:32:48 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -948,7 +948,6 @@
 
 	/* Update ifp counters. */
 	ifp->if_opackets = stat->tx_frames;
-	ifp->if_collisions = stat->tx_late_colls;
 	ifp->if_oerrors = stat->tx_late_colls + stat->tx_underruns;
 	ifp->if_ipackets = stat->rx_frames;
 	ifp->if_ierrors = stat->rx_crcerrs + stat->rx_runts +
@@ -1024,6 +1023,8 @@
 		status = le16toh(txd->tx_desc->dtst);
 		if ((status & VTE_DTST_TX_OWN) != 0)
 			break;
+		if ((status & VTE_DTST_TX_OK) != 0)
+			ifp->if_collisions += (status & 0xf);
 		sc->vte_cdata.vte_tx_cnt--;
 		/* Reclaim transmitted mbufs. */
 		bus_dmamap_sync(sc->vte_dmatag, txd->tx_dmamap, 0, 
@@ -1352,6 +1353,7 @@
 	ifp->if_flags |= IFF_RUNNING;
 	ifp->if_flags &= ~IFF_OACTIVE;
 
+	/* calling mii_mediachg will call back vte_start_mac() */
 	if ((error = mii_mediachg(&sc->vte_mii)) == ENXIO)
 		error = 0;
 	else if (error != 0) {
@@ -1456,6 +1458,7 @@
 			aprint_error_dev(sc->vte_dev,
 			    "could not enable RX/TX MAC(0x%04x)!\n", mcr);
 	}
+	vte_rxfilter(sc);
 }
 
 static void
@@ -1577,7 +1580,7 @@
 	ifp = &sc->vte_if;
 
 	DPRINTF(("vte_rxfilter\n"));
-	bzero(mchash, sizeof(mchash));
+	memset(mchash, 0, sizeof(mchash));
 	for (i = 0; i < VTE_RXFILT_PERFECT_CNT; i++) {
 		rxfilt_perf[i][0] = 0xFFFF;
 		rxfilt_perf[i][1] = 0xFFFF;
@@ -1586,9 +1589,9 @@
 
 	mcr = CSR_READ_2(sc, VTE_MCR0);
 	DPRINTF(("vte_rxfilter mcr 0x%x\n", mcr));
-	mcr &= ~(MCR0_PROMISC | MCR0_BROADCAST | MCR0_MULTICAST);
-	if ((ifp->if_flags & IFF_BROADCAST) != 0)
-		mcr |= MCR0_BROADCAST;
+	mcr &= ~(MCR0_PROMISC | MCR0_BROADCAST_DIS | MCR0_MULTICAST);
+	if ((ifp->if_flags & IFF_BROADCAST) == 0)
+		mcr |= MCR0_BROADCAST_DIS;
 	if ((ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0) {
 		if ((ifp->if_flags & IFF_PROMISC) != 0)
 			mcr |= MCR0_PROMISC;
@@ -1604,7 +1607,7 @@
 	ETHER_FIRST_MULTI(step, &sc->vte_ec, enm);
 	nperf = 0;
 	while (enm != NULL) {
-		if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
+		if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
 			sc->vte_if.if_flags |= IFF_ALLMULTI;
 			mcr |= MCR0_MULTICAST;
 			mchash[0] = 0xFFFF;
@@ -1624,10 +1627,10 @@
 			rxfilt_perf[nperf][1] = eaddr[3] << 8 | eaddr[2];
 			rxfilt_perf[nperf][2] = eaddr[5] << 8 | eaddr[4];
 			nperf++;
-			continue;
+		} else {
+			crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
+			mchash[crc >> 30] |= 1 << ((crc >> 26) & 0x0F);
 		}
-		crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
-		mchash[crc >> 30] |= 1 << ((crc >> 26) & 0x0F);
 		ETHER_NEXT_MULTI(step, enm);
 	}
 	if (mchash[0] != 0 || mchash[1] != 0 || mchash[2] != 0 ||

Index: src/sys/dev/pci/if_vtereg.h
diff -u src/sys/dev/pci/if_vtereg.h:1.1 src/sys/dev/pci/if_vtereg.h:1.2
--- src/sys/dev/pci/if_vtereg.h:1.1	Wed Jan 26 18:48:13 2011
+++ src/sys/dev/pci/if_vtereg.h	Thu Apr 28 17:32:48 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vtereg.h,v 1.1 2011/01/26 18:48:13 bouyer Exp $	*/
+/*	$NetBSD: if_vtereg.h,v 1.2 2011/04/28 17:32:48 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2010, Pyun YongHyeon <yong...@freebsd.org>
@@ -44,7 +44,7 @@
 #define	MCR0_ACCPT_LONG_PKT		0x0008
 #define	MCR0_ACCPT_DRIBBLE		0x0010
 #define	MCR0_PROMISC			0x0020
-#define	MCR0_BROADCAST			0x0040
+#define	MCR0_BROADCAST_DIS		0x0040
 #define	MCR0_RX_EARLY_INTR		0x0080
 #define	MCR0_MULTICAST			0x0100
 #define	MCR0_FC_ENB			0x0200

Reply via email to