Module Name:    src
Committed By:   msaitoh
Date:           Tue Feb 26 11:06:24 UTC 2013

Modified Files:
        src/sys/dev/pci: if_bge.c if_bgereg.h

Log Message:
Add some bugfixes and enhancement from FreeBSD:

- Workaround for BCM5906 silicon bug. When auto-negotiation results in
 half-duplex operation, excess collision on the ethernet link may cause
 internal chip delays that may result in subsequent valid frames being
 dropped due to insufficient receive buffer resources.
 (FreeBSD: r214219, r214251, r214292)

- Allow write DMA to request larger DMA burst size to get better
 performance on BCM5785.
 (FreeBSD r213333: OpenBSD 1.294)

- Enable TX MAC state machine lockup fix for both BCM5755 or higher
 and BCM5906. Publicly available data sheet just says it may happen
 due to corrupted TxMbuf.
 (FreeBSD r214216)

- Follow Broadcom datasheet:
 Delay 100 microseconds after enabling transmit MAC.
 Delay 10 microseconds after enabling receive MAC.
 (FreeBSD r241220)


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/pci/if_bge.c
cvs rdiff -u -r1.59 -r1.60 src/sys/dev/pci/if_bgereg.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_bge.c
diff -u src/sys/dev/pci/if_bge.c:1.205 src/sys/dev/pci/if_bge.c:1.206
--- src/sys/dev/pci/if_bge.c:1.205	Tue Feb 26 11:03:17 2013
+++ src/sys/dev/pci/if_bge.c	Tue Feb 26 11:06:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bge.c,v 1.205 2013/02/26 11:03:17 msaitoh Exp $	*/
+/*	$NetBSD: if_bge.c,v 1.206 2013/02/26 11:06:23 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.205 2013/02/26 11:03:17 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.206 2013/02/26 11:06:23 msaitoh Exp $");
 
 #include "vlan.h"
 
@@ -699,6 +699,7 @@ static const struct bge_revision {
 	{ BGE_CHIPID_BCM5787_A0, "BCM5754/5787 A0" },
 	{ BGE_CHIPID_BCM5787_A1, "BCM5754/5787 A1" },
 	{ BGE_CHIPID_BCM5787_A2, "BCM5754/5787 A2" },
+	{ BGE_CHIPID_BCM5906_A0, "BCM5906 A0" },
 	{ BGE_CHIPID_BCM5906_A1, "BCM5906 A1" },
 	{ BGE_CHIPID_BCM5906_A2, "BCM5906 A2" },
 	{ BGE_CHIPID_BCM57780_A0, "BCM57780 A0" },
@@ -2097,6 +2098,14 @@ bge_blockinit(struct bge_softc *sc)
 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
 	}
 
+	/* Choose de-pipeline mode for BCM5906 A0, A1 and A2. */
+	if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906) {
+		if (sc->bge_chipid == BGE_CHIPID_BCM5906_A0 ||
+		    sc->bge_chipid == BGE_CHIPID_BCM5906_A1 ||
+		    sc->bge_chipid == BGE_CHIPID_BCM5906_A2)
+			CSR_WRITE_4(sc, BGE_ISO_PKT_TX,
+			    (CSR_READ_4(sc, BGE_ISO_PKT_TX) & ~3) | 2);
+	}
 	/*
 	 * Set the BD ring replenish thresholds. The recommended
 	 * values are 1/8th the number of descriptors allocated to
@@ -2309,6 +2318,9 @@ bge_blockinit(struct bge_softc *sc)
 	if (BGE_IS_5755_PLUS(sc))
 		val |= BGE_WDMAMODE_STATUS_TAG_FIX;
 
+	if (BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5785)
+		val |= BGE_WDMAMODE_BURST_ALL_DATA;
+
 	/* Turn on write DMA state machine */
 	CSR_WRITE_4(sc, BGE_WDMA_MODE, val);
 
@@ -4304,6 +4316,7 @@ bge_init(struct ifnet *ifp)
 {
 	struct bge_softc *sc = ifp->if_softc;
 	const uint16_t *m;
+	uint32_t mode;
 	int s, error = 0;
 
 	s = splnet();
@@ -4384,11 +4397,19 @@ bge_init(struct ifnet *ifp)
 	/* Init TX ring. */
 	bge_init_tx_ring(sc);
 
+	/* Enable TX MAC state machine lockup fix. */
+	mode = CSR_READ_4(sc, BGE_TX_MODE);
+	if (BGE_IS_5755_PLUS(sc) ||
+	    BGE_ASICREV(sc->bge_chipid) == BGE_ASICREV_BCM5906)
+		mode |= BGE_TXMODE_MBUF_LOCKUP_FIX;
+
 	/* Turn on transmitter */
-	BGE_SETBIT(sc, BGE_TX_MODE, BGE_TXMODE_ENABLE);
+	CSR_WRITE_4(sc, BGE_TX_MODE, mode | BGE_TXMODE_ENABLE);
+	DELAY(100);
 
 	/* Turn on receiver */
 	BGE_SETBIT(sc, BGE_RX_MODE, BGE_RXMODE_ENABLE);
+	DELAY(10);
 
 	CSR_WRITE_4(sc, BGE_MAX_RX_FRAME_LOWAT, 2);
 

Index: src/sys/dev/pci/if_bgereg.h
diff -u src/sys/dev/pci/if_bgereg.h:1.59 src/sys/dev/pci/if_bgereg.h:1.60
--- src/sys/dev/pci/if_bgereg.h:1.59	Tue Feb 26 11:03:17 2013
+++ src/sys/dev/pci/if_bgereg.h	Tue Feb 26 11:06:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bgereg.h,v 1.59 2013/02/26 11:03:17 msaitoh Exp $	*/
+/*	$NetBSD: if_bgereg.h,v 1.60 2013/02/26 11:06:23 msaitoh Exp $	*/
 /*
  * Copyright (c) 2001 Wind River Systems
  * Copyright (c) 1997, 1998, 1999, 2001
@@ -318,6 +318,7 @@
 #define BGE_CHIPID_BCM5787_A0		0xb000
 #define BGE_CHIPID_BCM5787_A1		0xb001
 #define BGE_CHIPID_BCM5787_A2		0xb002
+#define	BGE_CHIPID_BCM5906_A0		0xc000
 #define BGE_CHIPID_BCM5906_A1		0xc001
 #define BGE_CHIPID_BCM5906_A2		0xc002
 #define BGE_CHIPID_BCM57762		0x57766000
@@ -734,6 +735,7 @@
 #define BGE_TXMODE_FLOWCTL_ENABLE	0x00000010
 #define BGE_TXMODE_BIGBACKOFF_ENABLE	0x00000020
 #define BGE_TXMODE_LONGPAUSE_ENABLE	0x00000040
+#define	BGE_TXMODE_MBUF_LOCKUP_FIX	0x00000100
 
 /* Transmit MAC status register */
 #define BGE_TXSTAT_RX_XOFFED		0x00000001
@@ -820,6 +822,7 @@
 #define BGE_SDI_STATS_CTL		0x0C08
 #define BGE_SDI_STATS_ENABLE_MASK	0x0C0C
 #define BGE_SDI_STATS_INCREMENT_MASK	0x0C10
+#define	BGE_ISO_PKT_TX			0x0C20
 #define BGE_LOCSTATS_COS0		0x0C80
 #define BGE_LOCSTATS_COS1		0x0C84
 #define BGE_LOCSTATS_COS2		0x0C88
@@ -1435,6 +1438,7 @@
 #define BGE_WDMAMODE_LOCREAD_TOOBIG	0x00000200
 #define BGE_WDMAMODE_ALL_ATTNS		0x000003FC
 #define BGE_WDMAMODE_STATUS_TAG_FIX	0x20000000
+#define	BGE_WDMAMODE_BURST_ALL_DATA	0xC0000000
 
 /* Write DMA status register */
 #define BGE_WDMASTAT_PCI_TGT_ABRT_ATTN	0x00000004

Reply via email to