Deleted Added
full compact
if_bge.c (270876) if_bge.c (271782)
1/*-
2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2001
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 18 unchanged lines hidden (view full) ---

27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2001
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 18 unchanged lines hidden (view full) ---

27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/bge/if_bge.c 270876 2014-08-31 12:48:13Z glebius $");
35__FBSDID("$FreeBSD: head/sys/dev/bge/if_bge.c 271782 2014-09-18 15:56:14Z glebius $");
36
37/*
38 * Broadcom BCM57xx(x)/BCM590x NetXtreme and NetLink family Ethernet driver
39 *
40 * The Broadcom BCM5700 is based on technology originally developed by
41 * Alteon Networks as part of the Tigon I and Tigon II Gigabit Ethernet
42 * MAC chips. The BCM5700, sometimes referred to as the Tigon III, has
43 * two on-board MIPS R4000 CPUs and can have as much as 16MB of external

--- 385 unchanged lines hidden (view full) ---

429static void bge_init(void *);
430static void bge_stop_block(struct bge_softc *, bus_size_t, uint32_t);
431static void bge_stop(struct bge_softc *);
432static void bge_watchdog(struct bge_softc *);
433static int bge_shutdown(device_t);
434static int bge_ifmedia_upd_locked(if_t);
435static int bge_ifmedia_upd(if_t);
436static void bge_ifmedia_sts(if_t, struct ifmediareq *);
36
37/*
38 * Broadcom BCM57xx(x)/BCM590x NetXtreme and NetLink family Ethernet driver
39 *
40 * The Broadcom BCM5700 is based on technology originally developed by
41 * Alteon Networks as part of the Tigon I and Tigon II Gigabit Ethernet
42 * MAC chips. The BCM5700, sometimes referred to as the Tigon III, has
43 * two on-board MIPS R4000 CPUs and can have as much as 16MB of external

--- 385 unchanged lines hidden (view full) ---

429static void bge_init(void *);
430static void bge_stop_block(struct bge_softc *, bus_size_t, uint32_t);
431static void bge_stop(struct bge_softc *);
432static void bge_watchdog(struct bge_softc *);
433static int bge_shutdown(device_t);
434static int bge_ifmedia_upd_locked(if_t);
435static int bge_ifmedia_upd(if_t);
436static void bge_ifmedia_sts(if_t, struct ifmediareq *);
437static uint64_t bge_get_counter(if_t, ift_counter);
437
438static uint8_t bge_nvram_getbyte(struct bge_softc *, int, uint8_t *);
439static int bge_read_nvram(struct bge_softc *, caddr_t, int, int);
440
441static uint8_t bge_eeprom_getbyte(struct bge_softc *, int, uint8_t *);
442static int bge_read_eeprom(struct bge_softc *, caddr_t, int, int);
443
444static void bge_setpromisc(struct bge_softc *);

--- 3288 unchanged lines hidden (view full) ---

3733 goto fail;
3734 }
3735 if_setsoftc(ifp, sc);
3736 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
3737 if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
3738 if_setioctlfn(ifp, bge_ioctl);
3739 if_setstartfn(ifp, bge_start);
3740 if_setinitfn(ifp, bge_init);
438
439static uint8_t bge_nvram_getbyte(struct bge_softc *, int, uint8_t *);
440static int bge_read_nvram(struct bge_softc *, caddr_t, int, int);
441
442static uint8_t bge_eeprom_getbyte(struct bge_softc *, int, uint8_t *);
443static int bge_read_eeprom(struct bge_softc *, caddr_t, int, int);
444
445static void bge_setpromisc(struct bge_softc *);

--- 3288 unchanged lines hidden (view full) ---

3734 goto fail;
3735 }
3736 if_setsoftc(ifp, sc);
3737 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
3738 if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
3739 if_setioctlfn(ifp, bge_ioctl);
3740 if_setstartfn(ifp, bge_start);
3741 if_setinitfn(ifp, bge_init);
3742 if_setgetcounterfn(ifp, bge_get_counter);
3741 if_setsendqlen(ifp, BGE_TX_RING_CNT - 1);
3742 if_setsendqready(ifp);
3743 if_sethwassist(ifp, sc->bge_csum_features);
3744 if_setcapabilities(ifp, IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING |
3745 IFCAP_VLAN_MTU);
3746 if ((sc->bge_flags & (BGE_FLAG_TSO | BGE_FLAG_TSO3)) != 0) {
3747 if_sethwassistbits(ifp, CSUM_TSO, 0);
3748 if_setcapabilitiesbit(ifp, IFCAP_TSO4 | IFCAP_VLAN_HWTSO, 0);

--- 610 unchanged lines hidden (view full) ---

4359 jumbocnt++;
4360 m = sc->bge_cdata.bge_rx_jumbo_chain[rxidx];
4361 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
4362 bge_rxreuse_jumbo(sc, rxidx);
4363 continue;
4364 }
4365 if (bge_newbuf_jumbo(sc, rxidx) != 0) {
4366 bge_rxreuse_jumbo(sc, rxidx);
3743 if_setsendqlen(ifp, BGE_TX_RING_CNT - 1);
3744 if_setsendqready(ifp);
3745 if_sethwassist(ifp, sc->bge_csum_features);
3746 if_setcapabilities(ifp, IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING |
3747 IFCAP_VLAN_MTU);
3748 if ((sc->bge_flags & (BGE_FLAG_TSO | BGE_FLAG_TSO3)) != 0) {
3749 if_sethwassistbits(ifp, CSUM_TSO, 0);
3750 if_setcapabilitiesbit(ifp, IFCAP_TSO4 | IFCAP_VLAN_HWTSO, 0);

--- 610 unchanged lines hidden (view full) ---

4361 jumbocnt++;
4362 m = sc->bge_cdata.bge_rx_jumbo_chain[rxidx];
4363 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
4364 bge_rxreuse_jumbo(sc, rxidx);
4365 continue;
4366 }
4367 if (bge_newbuf_jumbo(sc, rxidx) != 0) {
4368 bge_rxreuse_jumbo(sc, rxidx);
4367 if_inciqdrops(ifp, 1);
4369 if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
4368 continue;
4369 }
4370 BGE_INC(sc->bge_jumbo, BGE_JUMBO_RX_RING_CNT);
4371 } else {
4372 stdcnt++;
4373 m = sc->bge_cdata.bge_rx_std_chain[rxidx];
4374 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
4375 bge_rxreuse_std(sc, rxidx);
4376 continue;
4377 }
4378 if (bge_newbuf_std(sc, rxidx) != 0) {
4379 bge_rxreuse_std(sc, rxidx);
4370 continue;
4371 }
4372 BGE_INC(sc->bge_jumbo, BGE_JUMBO_RX_RING_CNT);
4373 } else {
4374 stdcnt++;
4375 m = sc->bge_cdata.bge_rx_std_chain[rxidx];
4376 if (cur_rx->bge_flags & BGE_RXBDFLAG_ERROR) {
4377 bge_rxreuse_std(sc, rxidx);
4378 continue;
4379 }
4380 if (bge_newbuf_std(sc, rxidx) != 0) {
4381 bge_rxreuse_std(sc, rxidx);
4380 if_inciqdrops(ifp, 1);
4382 if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
4381 continue;
4382 }
4383 BGE_INC(sc->bge_std, BGE_STD_RX_RING_CNT);
4384 }
4385
4383 continue;
4384 }
4385 BGE_INC(sc->bge_std, BGE_STD_RX_RING_CNT);
4386 }
4387
4386 if_incipackets(ifp, 1);
4388 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
4387#ifndef __NO_STRICT_ALIGNMENT
4388 /*
4389 * For architectures with strict alignment we must make sure
4390 * the payload is aligned.
4391 */
4392 if (sc->bge_flags & BGE_FLAG_RX_ALIGNBUG) {
4393 bcopy(m->m_data, m->m_data + ETHER_ALIGN,
4394 cur_rx->bge_len);

--- 112 unchanged lines hidden (view full) ---

4507 * frames that have been sent.
4508 */
4509 while (sc->bge_tx_saved_considx != tx_cons) {
4510 uint32_t idx;
4511
4512 idx = sc->bge_tx_saved_considx;
4513 cur_tx = &sc->bge_ldata.bge_tx_ring[idx];
4514 if (cur_tx->bge_flags & BGE_TXBDFLAG_END)
4389#ifndef __NO_STRICT_ALIGNMENT
4390 /*
4391 * For architectures with strict alignment we must make sure
4392 * the payload is aligned.
4393 */
4394 if (sc->bge_flags & BGE_FLAG_RX_ALIGNBUG) {
4395 bcopy(m->m_data, m->m_data + ETHER_ALIGN,
4396 cur_rx->bge_len);

--- 112 unchanged lines hidden (view full) ---

4509 * frames that have been sent.
4510 */
4511 while (sc->bge_tx_saved_considx != tx_cons) {
4512 uint32_t idx;
4513
4514 idx = sc->bge_tx_saved_considx;
4515 cur_tx = &sc->bge_ldata.bge_tx_ring[idx];
4516 if (cur_tx->bge_flags & BGE_TXBDFLAG_END)
4515 if_incopackets(ifp, 1);
4517 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
4516 if (sc->bge_cdata.bge_tx_chain[idx] != NULL) {
4517 bus_dmamap_sync(sc->bge_cdata.bge_tx_mtag,
4518 sc->bge_cdata.bge_tx_dmamap[idx],
4519 BUS_DMASYNC_POSTWRITE);
4520 bus_dmamap_unload(sc->bge_cdata.bge_tx_mtag,
4521 sc->bge_cdata.bge_tx_dmamap[idx]);
4522 m_freem(sc->bge_cdata.bge_tx_chain[idx]);
4523 sc->bge_cdata.bge_tx_chain[idx] = NULL;

--- 388 unchanged lines hidden (view full) ---

4912 sc->bge_chipid != BGE_CHIPID_BCM5720_A0)
4913 stats->InputDiscards +=
4914 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_DROPS);
4915 stats->InputErrors +=
4916 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_ERRORS);
4917 stats->RecvThresholdHit +=
4918 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_RXTHRESH_HIT);
4919
4518 if (sc->bge_cdata.bge_tx_chain[idx] != NULL) {
4519 bus_dmamap_sync(sc->bge_cdata.bge_tx_mtag,
4520 sc->bge_cdata.bge_tx_dmamap[idx],
4521 BUS_DMASYNC_POSTWRITE);
4522 bus_dmamap_unload(sc->bge_cdata.bge_tx_mtag,
4523 sc->bge_cdata.bge_tx_dmamap[idx]);
4524 m_freem(sc->bge_cdata.bge_tx_chain[idx]);
4525 sc->bge_cdata.bge_tx_chain[idx] = NULL;

--- 388 unchanged lines hidden (view full) ---

4914 sc->bge_chipid != BGE_CHIPID_BCM5720_A0)
4915 stats->InputDiscards +=
4916 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_DROPS);
4917 stats->InputErrors +=
4918 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_IFIN_ERRORS);
4919 stats->RecvThresholdHit +=
4920 CSR_READ_4(sc, BGE_RXLP_LOCSTAT_RXTHRESH_HIT);
4921
4920 if_setcollisions(ifp, (u_long)stats->etherStatsCollisions);
4921 if_setierrors(ifp, (u_long)(stats->NoMoreRxBDs + stats->InputDiscards +
4922 stats->InputErrors));
4923
4924 if (sc->bge_flags & BGE_FLAG_RDMA_BUG) {
4925 /*
4926 * If controller transmitted more than BGE_NUM_RDMA_CHANNELS
4927 * frames, it's safe to disable workaround for DMA engine's
4928 * miscalculation of TXMBUF space.
4929 */
4930 if (stats->ifHCOutUcastPkts + stats->ifHCOutMulticastPkts +
4931 stats->ifHCOutBroadcastPkts > BGE_NUM_RDMA_CHANNELS) {

--- 60 unchanged lines hidden (view full) ---

4992 ifp = sc->bge_ifp;
4993
4994 stats = BGE_MEMWIN_START + BGE_STATS_BLOCK;
4995
4996#define READ_STAT(sc, stats, stat) \
4997 CSR_READ_4(sc, stats + offsetof(struct bge_stats, stat))
4998
4999 cnt = READ_STAT(sc, stats, txstats.etherStatsCollisions.bge_addr_lo);
4922 if (sc->bge_flags & BGE_FLAG_RDMA_BUG) {
4923 /*
4924 * If controller transmitted more than BGE_NUM_RDMA_CHANNELS
4925 * frames, it's safe to disable workaround for DMA engine's
4926 * miscalculation of TXMBUF space.
4927 */
4928 if (stats->ifHCOutUcastPkts + stats->ifHCOutMulticastPkts +
4929 stats->ifHCOutBroadcastPkts > BGE_NUM_RDMA_CHANNELS) {

--- 60 unchanged lines hidden (view full) ---

4990 ifp = sc->bge_ifp;
4991
4992 stats = BGE_MEMWIN_START + BGE_STATS_BLOCK;
4993
4994#define READ_STAT(sc, stats, stat) \
4995 CSR_READ_4(sc, stats + offsetof(struct bge_stats, stat))
4996
4997 cnt = READ_STAT(sc, stats, txstats.etherStatsCollisions.bge_addr_lo);
5000 if_inccollisions(ifp, (uint32_t)(cnt - sc->bge_tx_collisions));
4998 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, cnt - sc->bge_tx_collisions);
5001 sc->bge_tx_collisions = cnt;
5002
5003 cnt = READ_STAT(sc, stats, nicNoMoreRxBDs.bge_addr_lo);
4999 sc->bge_tx_collisions = cnt;
5000
5001 cnt = READ_STAT(sc, stats, nicNoMoreRxBDs.bge_addr_lo);
5004 if_incierrors(ifp, (uint32_t)(cnt - sc->bge_rx_nobds));
5002 if_inc_counter(ifp, IFCOUNTER_IERRORS, cnt - sc->bge_rx_nobds);
5005 sc->bge_rx_nobds = cnt;
5006 cnt = READ_STAT(sc, stats, ifInErrors.bge_addr_lo);
5003 sc->bge_rx_nobds = cnt;
5004 cnt = READ_STAT(sc, stats, ifInErrors.bge_addr_lo);
5007 if_incierrors(ifp, (uint32_t)(cnt - sc->bge_rx_inerrs));
5005 if_inc_counter(ifp, IFCOUNTER_IERRORS, cnt - sc->bge_rx_inerrs);
5008 sc->bge_rx_inerrs = cnt;
5009 cnt = READ_STAT(sc, stats, ifInDiscards.bge_addr_lo);
5006 sc->bge_rx_inerrs = cnt;
5007 cnt = READ_STAT(sc, stats, ifInDiscards.bge_addr_lo);
5010 if_incierrors(ifp, (uint32_t)(cnt - sc->bge_rx_discards));
5008 if_inc_counter(ifp, IFCOUNTER_IERRORS, cnt - sc->bge_rx_discards);
5011 sc->bge_rx_discards = cnt;
5012
5013 cnt = READ_STAT(sc, stats, txstats.ifOutDiscards.bge_addr_lo);
5009 sc->bge_rx_discards = cnt;
5010
5011 cnt = READ_STAT(sc, stats, txstats.ifOutDiscards.bge_addr_lo);
5014 if_incoerrors(ifp, (uint32_t)(cnt - sc->bge_tx_discards));
5012 if_inc_counter(ifp, IFCOUNTER_OERRORS, cnt - sc->bge_tx_discards);
5015 sc->bge_tx_discards = cnt;
5016
5017#undef READ_STAT
5018}
5019
5020/*
5021 * Pad outbound frame to ETHER_MIN_NOPAD for an unusual reason.
5022 * The bge hardware will pad out Tx runts to ETHER_MIN_NOPAD,

--- 922 unchanged lines hidden (view full) ---

5945
5946 ifp = sc->bge_ifp;
5947
5948 if_printf(ifp, "watchdog timeout -- resetting\n");
5949
5950 if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
5951 bge_init_locked(sc);
5952
5013 sc->bge_tx_discards = cnt;
5014
5015#undef READ_STAT
5016}
5017
5018/*
5019 * Pad outbound frame to ETHER_MIN_NOPAD for an unusual reason.
5020 * The bge hardware will pad out Tx runts to ETHER_MIN_NOPAD,

--- 922 unchanged lines hidden (view full) ---

5943
5944 ifp = sc->bge_ifp;
5945
5946 if_printf(ifp, "watchdog timeout -- resetting\n");
5947
5948 if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
5949 bge_init_locked(sc);
5950
5953 if_incoerrors(ifp, 1);
5951 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
5954}
5955
5956static void
5957bge_stop_block(struct bge_softc *sc, bus_size_t reg, uint32_t bit)
5958{
5959 int i;
5960
5961 BGE_CLRBIT(sc, reg, bit);

--- 803 unchanged lines hidden (view full) ---

6765 const bge_eaddr_fcn_t *func;
6766
6767 for (func = bge_eaddr_funcs; *func != NULL; ++func) {
6768 if ((*func)(sc, eaddr) == 0)
6769 break;
6770 }
6771 return (*func == NULL ? ENXIO : 0);
6772}
5952}
5953
5954static void
5955bge_stop_block(struct bge_softc *sc, bus_size_t reg, uint32_t bit)
5956{
5957 int i;
5958
5959 BGE_CLRBIT(sc, reg, bit);

--- 803 unchanged lines hidden (view full) ---

6763 const bge_eaddr_fcn_t *func;
6764
6765 for (func = bge_eaddr_funcs; *func != NULL; ++func) {
6766 if ((*func)(sc, eaddr) == 0)
6767 break;
6768 }
6769 return (*func == NULL ? ENXIO : 0);
6770}
6771
6772static uint64_t
6773bge_get_counter(if_t ifp, ift_counter cnt)
6774{
6775 struct bge_softc *sc;
6776 struct bge_mac_stats *stats;
6777
6778 sc = if_getsoftc(ifp);
6779 if (!BGE_IS_5705_PLUS(sc))
6780 return (if_get_counter_default(ifp, cnt));
6781 stats = &sc->bge_mac_stats;
6782
6783 switch (cnt) {
6784 case IFCOUNTER_IERRORS:
6785 return (stats->NoMoreRxBDs + stats->InputDiscards +
6786 stats->InputErrors);
6787 case IFCOUNTER_COLLISIONS:
6788 return (stats->etherStatsCollisions);
6789 default:
6790 return (if_get_counter_default(ifp, cnt));
6791 }
6792}