From b60e50e12287c7d8308ec2129713ded54575d33d Mon Sep 17 00:00:00 2001 From: jkim Date: Fri, 1 Dec 2006 01:08:52 +0000 Subject: Simplify statistics updates, remove redundant register reads, and add discarded RX packets to input error for BCM5705 or newer chipset as the others. Unfortunately we cannot do the same for output errors because ifOutDiscards equivalent register does not exist. While I am here, replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with BGE_MAC_STATS. They were reversed but worked accidently. --- sys/dev/bge/if_bge.c | 38 +++++++++++++++----------------------- sys/dev/bge/if_bgereg.h | 9 ++++----- 2 files changed, 19 insertions(+), 28 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c index d9aca67..2150372 100644 --- a/sys/dev/bge/if_bge.c +++ b/sys/dev/bge/if_bge.c @@ -2979,27 +2979,19 @@ bge_tick(void *xsc) static void bge_stats_update_regs(struct bge_softc *sc) { - struct bge_mac_stats_regs stats; struct ifnet *ifp; - uint32_t *s; - u_long cnt; /* current register value */ - int i; + uint32_t cnt; /* current register value */ ifp = sc->bge_ifp; - s = (uint32_t *)&stats; - for (i = 0; i < sizeof(struct bge_mac_stats_regs); i += 4) { - *s = CSR_READ_4(sc, BGE_RX_STATS + i); - s++; - } - - cnt = stats.dot3StatsSingleCollisionFrames + - stats.dot3StatsMultipleCollisionFrames + - stats.dot3StatsExcessiveCollisions + - stats.dot3StatsLateCollisions; - ifp->if_collisions += cnt >= sc->bge_tx_collisions ? - cnt - sc->bge_tx_collisions : cnt; + cnt = CSR_READ_4(sc, BGE_MAC_STATS + + offsetof(struct bge_mac_stats_regs, etherStatsCollisions)); + ifp->if_collisions += (u_long)(cnt - sc->bge_tx_collisions); sc->bge_tx_collisions = cnt; + + cnt = CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_DROPS); + ifp->if_ierrors += (u_long)(cnt - sc->bge_rx_discards); + sc->bge_rx_discards = cnt; } static void @@ -3007,7 +2999,7 @@ bge_stats_update(struct bge_softc *sc) { struct ifnet *ifp; bus_size_t stats; - u_long cnt; /* current register value */ + uint32_t cnt; /* current register value */ ifp = sc->bge_ifp; @@ -3024,18 +3016,15 @@ bge_stats_update(struct bge_softc *sc) txstats.dot3StatsExcessiveCollisions.bge_addr_lo); cnt += READ_STAT(sc, stats, txstats.dot3StatsLateCollisions.bge_addr_lo); - ifp->if_collisions += cnt >= sc->bge_tx_collisions ? - cnt - sc->bge_tx_collisions : cnt; + ifp->if_collisions += (u_long)(cnt - sc->bge_tx_collisions); sc->bge_tx_collisions = cnt; cnt = READ_STAT(sc, stats, ifInDiscards.bge_addr_lo); - ifp->if_ierrors += cnt >= sc->bge_rx_discards ? - cnt - sc->bge_rx_discards : cnt; + ifp->if_ierrors += (u_long)(cnt - sc->bge_rx_discards); sc->bge_rx_discards = cnt; cnt = READ_STAT(sc, stats, txstats.ifOutDiscards.bge_addr_lo); - ifp->if_oerrors += cnt >= sc->bge_tx_discards ? - cnt - sc->bge_tx_discards : cnt; + ifp->if_oerrors += (u_long)(cnt - sc->bge_tx_discards); sc->bge_tx_discards = cnt; #undef READ_STAT @@ -3369,6 +3358,9 @@ bge_init_locked(struct bge_softc *sc) /* Init our RX return ring index. */ sc->bge_rx_saved_considx = 0; + /* Init our RX/TX stat counters. */ + sc->bge_rx_discards = sc->bge_tx_discards = sc->bge_tx_collisions = 0; + /* Init TX ring. */ bge_init_tx_ring(sc); diff --git a/sys/dev/bge/if_bgereg.h b/sys/dev/bge/if_bgereg.h index 61168fa..628694d 100644 --- a/sys/dev/bge/if_bgereg.h +++ b/sys/dev/bge/if_bgereg.h @@ -574,8 +574,7 @@ #define BGE_SERDES_STS 0x0594 #define BGE_SGDIG_CFG 0x05B0 #define BGE_SGDIG_STS 0x05B4 -#define BGE_RX_STATS 0x0800 -#define BGE_TX_STATS 0x0880 +#define BGE_MAC_STATS 0x0800 /* Ethernet MAC Mode register */ #define BGE_MACMODE_RESET 0x00000001 @@ -2490,9 +2489,9 @@ struct bge_softc { struct callout bge_stat_ch; char *bge_vpd_prodname; char *bge_vpd_readonly; - u_long bge_rx_discards; - u_long bge_tx_discards; - u_long bge_tx_collisions; + uint32_t bge_rx_discards; + uint32_t bge_tx_discards; + uint32_t bge_tx_collisions; #ifdef DEVICE_POLLING int rxcycles; #endif /* DEVICE_POLLING */ -- cgit v1.1