History log of /openbsd-current/sys/dev/pci/if_bgereg.h
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.136 04-Jul-2023 jmatthew

Make the hardware counters available on BCM5705 and newer available as
kstats. Some of the hardware counters are already used in
bge_stats_update_regs() to update interface counters and work around
hardware bugs, and all counters reset on read, so to keep things simple
the work is split between that function and bge_kstat_read(), which
reads the rest of the counters.

tested by bluhm@ on BCM5720 (with counters) and BCM5704 (without), and
by me on BCM5720 A0 (with counters and hardware bugs)
ok bluhm@ dlg@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.135 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.134 31-Aug-2021 jasper

remove empty forward structs fro bge_ring_data as found with ctfconv.

tested by and ok jmatthew@


# 1.133 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.132 19-Apr-2021 kettenis

Recognize BCM57762 A0 and A1. My diff for this only added the A0 revision,
but the A1 revision has been seen in the wild and Brad Smith provided
a diff that adds both.

ok jsg@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


# 1.135 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.134 31-Aug-2021 jasper

remove empty forward structs fro bge_ring_data as found with ctfconv.

tested by and ok jmatthew@


# 1.133 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.132 19-Apr-2021 kettenis

Recognize BCM57762 A0 and A1. My diff for this only added the A0 revision,
but the A1 revision has been seen in the wild and Brad Smith provided
a diff that adds both.

ok jsg@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


# 1.134 31-Aug-2021 jasper

remove empty forward structs fro bge_ring_data as found with ctfconv.

tested by and ok jmatthew@


# 1.133 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.132 19-Apr-2021 kettenis

Recognize BCM57762 A0 and A1. My diff for this only added the A0 revision,
but the A1 revision has been seen in the wild and Brad Smith provided
a diff that adds both.

ok jsg@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


# 1.133 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.132 19-Apr-2021 kettenis

Recognize BCM57762 A0 and A1. My diff for this only added the A0 revision,
but the A1 revision has been seen in the wild and Brad Smith provided
a diff that adds both.

ok jsg@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


# 1.132 19-Apr-2021 kettenis

Recognize BCM57762 A0 and A1. My diff for this only added the A0 revision,
but the A1 revision has been seen in the wild and Brad Smith provided
a diff that adds both.

ok jsg@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


# 1.131 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.130 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.129 10-Nov-2015 miod

The window accessible with BGE_MEMWIN_{READ,WRITE} only spans 32KB, so
program it as such and not as a 64KB window; fortunately none of the current
users of these macros would cross a 32KB boundary.

ok dlg@


# 1.128 19-Oct-2015 jmatthew

Move bge rxeof and txeof outside the kernel lock.
To make rxeof safe, use a separate ring refill timeout for each ring.
We activate the refill timeout for a ring when it's too empty to receive
packets, which ensures we won't attempt to refill it from interrupt context.

To make txeof safe, remove the list of dma maps and just allocate maps based on
the ring slots occupied by the packet, and use atomic operations to adjust
bge_txcnt. Rework some parts of the txeof and start loops so that we only
adjust bge_txcnt after exiting the loop, and only take actions such as setting
or clearing OACTIVE based on the final value.

tested on 5703, 5714, 5721 by me, 5753 by semarie@, 5761 by naddy@, and
also in snapshots for a while
ok mpi@, dlg@


# 1.127 11-Sep-2015 stsp

Make room for media types of the future. Extend the ifmedia word to 64 bits.
This changes numbers of the SIOCSIFMEDIA and SIOCGIFMEDIA ioctls and
grows struct ifmediareq.

Old ifconfig and dhclient binaries can still assign addresses, however
the 'media' subcommand stops working. Recompiling ifconfig and dhclient
with new headers before a reboot should not be necessary unless in very
special circumstances where non-default media settings must be used to
get link and console access is not available.

There may be some MD fallout but that will be cleared up later.

ok deraadt miod
with help and suggestions from several sharks attending l2k15


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.126 02-Sep-2014 brad

Add Jumbo support for BCM5714 / BCM5780 and BCM5717 / BCM5719 / BCM5720 / BCM57765 / BCM57766
chipsets.

ok mikeb@ "i think it should go in" dlg@


# 1.125 24-Aug-2014 brad

Add some TX BD flags for BCM5717 family chips.


Revision tags: OPENBSD_5_6_BASE
# 1.124 08-Jul-2014 dlg

cut things that relied on mclgeti for rx ring accounting/restriction over
to using if_rxr.

cut the reporting systat did over to the rxr ioctl.

tested as much as i can on alpha, amd64, and sparc64.
mpi@ has run it on macppc.
ok mpi@


Revision tags: OPENBSD_5_5_BASE
# 1.123 05-Feb-2014 brad

- Recognize BCM5762 A0 chipset.

- Have the BGE_RXLP_LOCSTAT_IFIN_DROPS workaround cover for the BCM5762 ASIC.
From Linux

ok naddy@


# 1.122 01-Feb-2014 brad

Split bge(4)'s feature flags into bge_flags and bge_phy_flags.

ok naddy@


# 1.121 28-Jan-2014 sthen

unbreak 32-bit kernel builds by forcing ULL for the new macros; ok naddy@


# 1.120 28-Jan-2014 brad

- Bring in some fixes/workarounds for BCM5719 / BCM5720 / BCM57765 and BCM57766
chipsets
- Add support for the new BCM5762 ASIC (BCM5725 / BCM5727 / BCM57767)
- Add all of the newer PCI ids

Tested with BCM5719 / BCM5720 and BCM57765 / BCM57766 and a bunch of older
chipsets.

ok naddy@


# 1.119 07-Jan-2014 brad

Increase the size of the bge_flags field to allow for more flags.

ok mikeb@


# 1.118 30-Dec-2013 brad

Expand the MSI support to cover most of the remaining bge(4) chipsets with the
exception being the BCM5714 family for now.

Tested on a variety of newer chipsets.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.117 28-Jun-2013 mikeb

Turns out that BGE_STATFLAG_UPDATED bit in the status block doesn't get
properly updated by the newer hardware (seen in the TX completion case).
This leads to very poor transmit performance in the beginning of a TCP
connection. Linux and FreeBSD don't rely on BGE_STATFLAG_UPDATED bit
since they enable MSI and tagged status for 5717+. Doing the same does
indeed fix an issue.

Change was tested by David Imhoff on 5719, 5720 and 5721/5750, Hrvoje
Popovski on 5704 B0, sthen@ on 5723/5784, benno@ on 5704 A3, and
me on 5719, 5720 adn 5714/5715. No objections from kettenis@ and dlg@.


# 1.116 13-Jun-2013 mikeb

Random TX Backoff Register mask must be 0x3FF; ok beck, dlg


# 1.115 31-May-2013 mikeb

New logic to accommodate the E5/C600 and 5719/5720 changes in PCI-E
maximum payload size handling from FreeBSD. Fixes RX path on 5719
found in newer machines such as HP DL3[68]0 G8 and Dell R320.

Tested by dlg@ on 5714, 5719 (Sun V445) and 5720, 5721 (Dell R420);
David Imhoff on 5719, 5720, 5721 (various Dell servers);
Rob Sessnik on 5719 (HP DL360p G8); mikeb@ on 5719 (HP DL380p G8).

ok dlg


# 1.114 29-May-2013 mikeb

PHY auto-polling mode should not be used for anything newer than BCM5705.
Figured out by David Imhoff, checked against FreeBSD, Linux and official
documentation. Fixes up link negotiation on BCM5719.

Original diff by David, tweaked by me; tested on BCM5702X and BCM5761 by
naddy@; BCM5714, BCM5719, BCM5720 and BCM5721 by dlg@, BCM5721 and
BCM5719 by David and BCM5719 by me. ok dlg


Revision tags: OPENBSD_5_3_BASE
# 1.113 22-Feb-2013 dlg

bring back 5718/5719/5720 support again. deraadt pointed out that
the problems i had on the xserve g5 are mostly likely specific to
that machine and im inclined to agree. we're going to see a lot
more machines with the new chips than people with xserve g5s.

this also includes fixes for ip checksum handling compared to the
code i put in before.

tested by various people again.
sthen@ and claudio@ have agreed to babysit this. they can back it
out if im not around.
ok deraadt@


# 1.112 09-Feb-2013 brad

- Use a switch statement for setting the chipset flags
- Add some macros for working with the various newer generations of chipsets
- Make use of the 5717 macro in a few places
- Add some bits for identifying and supporting some of the newer chipsets

ok sthen@


# 1.111 30-Jan-2013 dlg

backout 5718/5719/5720 support. the diff breaks the 5704C on my xserve g5
and i cant fix it without breaking a 5721 in another box.

sthen@ agrees it is sad.


# 1.110 29-Jan-2013 dlg

big pullup of bge to support the 5718 family of chips including the
5719 and 5720 chips that have popped up in a lot of new machines.

this diff is largely a merge of the freebsd code. thanks to srebrenko
sehic for providing me hardware to do the work on. also, a huge
thanks to claudio for trawling through the diff to fix merge issues,
understand the changes, and actually make it work.

tested by sthen@ naddy@ jmatthew@ claudio@ jj@ and me

tested chips include:

bge0 at pci2 dev 3 function 0 "Broadcom BCM5704C" rev 0x10, BCM5704 B0 (0x2100): apic 2 int 8, address 00:30:48:59:52:44
brgphy0 at bge0 phy 1: BCM5704 10/100/1000baseT PHY, rev. 0

bge0 at pci3 dev 0 function 0 "Broadcom BCM5723" rev 0x10, BCM5784 A1 (0x5784100): apic 2 int 18, address e4:11:5b:12:bd:d6
brgphy0 at bge0 phy 1: BCM5784 10/100/1000baseT PHY, rev. 4

bge0 at pci3 dev 4 function 0 "Broadcom BCM5714" rev 0xa3, BCM5715 A3 (0x9003): ivec 0x795, address 00:14:4f:a9:34:90
brgphy0 at bge0 phy 1: BCM5714 10/100/1000baseT/SX PHY, rev. 0

bge0 at pci2 dev 0 function 0 "Broadcom BCM5761" rev 0x10, BCM5761 A1 (0x5761100): apic 2 int 18, address 00:10:18:4b:23:b4
brgphy0 at bge0 phy 1: BCM5761 10/100/1000baseT PHY, rev. 0

bge0 at pci0 dev 5 function 0 "Broadcom BCM5702X" rev 0x02, BCM5702/5703 A2 (0x1002): eb164 irq 2, address 00:10:18:00:98:e9
brgphy0 at bge0 phy 1: BCM5703 10/100/1000baseT PHY, rev. 2

bge0 at pci2 dev 2 function 0 "Broadcom BCM5703" rev 0x00, BCM5702/5703 A2 (0x1002): ivec 0x7dc, address 00:14:4f:16:a0:23

and of course:
bge1 at pci5 dev 0 function 0 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 16, address d4:ae:52:a7:05:38
brgphy1 at bge1 phy 1: BCM5720C 10/100/1000baseT PHY, rev. 0
bge2 at pci5 dev 0 function 1 "Broadcom BCM5720" rev 0x00, BCM5720 A0 (0x5720000), APE firmware NCSI 1.0.85.0: apic 0 int 17, address d4:ae:52:a7:05:39
brgphy2 at bge2 phy 2: BCM5720C 10/100/1000baseT PHY, rev. 0

either sthen@ or i will be around to handle any issues after this commit.


# 1.109 16-Jan-2013 miod

Fight global eye bleeding by fixing evil typos.


# 1.108 15-Jan-2013 claudio

More syncing with FreeBSD bge version. No binary change.


# 1.107 15-Jan-2013 claudio

put a tab after #define to make the diff between Fx and Ox smaller.
No binary change.


# 1.106 10-Jan-2013 dlg

dont hardcode the phy address at 1. the 5718 family of chips can have
phys as 1, 2, 8, or 9 depending on which pci function its on and whether
its serdes.

this tells every other bge that the phy is still at 1, so they still work.


# 1.105 10-Jan-2013 dlg

macros describing necessary bits on newer chips.

just extra cruft, it doesnt change anything that already exists so it cant
(and empirically doesnt) change existing chip support.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.104 15-Feb-2011 robert

Add workaround for BCM5906 A0/1/2 controller 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. The workaround is to choose de-pipeline
method as a flow control decision for SDI. De-pipeline method
allows only 1 data in TxMbuf at a time such that a request to RDMA
from SDI is made only when TxMbuf is empty.
From FreeBSD; ok miod@; ok kettenis@


# 1.103 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


# 1.102 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


Revision tags: OPENBSD_4_8_BASE
# 1.101 09-Jul-2010 sthen

- Setup proper mbuf pool watermarks for BCM5717 / BCM57765 chipsets.
- Disable initiation of multiple DMA reads for BCM5717 chipset
to workaround errata.
- Performance tweak for BCM5785 chipset.
- Correct the return ring count used for BCM5717 / BCM57765 chipsets.
- Fix fiber media detection for BCM5717 chipsets as they use a MII-based
fiber PHY.

From Brad, based on info gleaned from the Linux tg3 driver.
Should only affect the new chipsets, but tested for regressions
anyway (on BCM5701, BCM5703, BCM5704C, BCM5705M Alt, BCM5722, BCM5751,
BCM5751M, BCM5780) by Brad, weerd@, myself and Denis Doroshenko.


Revision tags: OPENBSD_4_7_BASE
# 1.100 09-Jan-2010 naddy

Add support for the Broadcom BCM57765 ASIC and newer Broadcom
BCM577xx chipsets. From Brad.


# 1.99 11-Oct-2009 sthen

Add support for the Broadcom BCM5717 ASIC and the BCM5717 / BCM5718 chipsets.
Based on info gleaned from the Linux tg3 driver. From Brad, ok naddy@


# 1.98 21-Jul-2009 naddy

Add a family flag for the original 5700 series chipsets. Idea from FreeBSD.
But also use the flag where it makes sense. From Brad; ok sthen@


Revision tags: OPENBSD_4_6_BASE
# 1.97 19-Jun-2009 naddy

Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.96 19-Jun-2009 naddy

Some more defines for bge(4). Mainly bits for accessing
info from the firmware. Some of it will be required for
further work on both older and newer chipsets.

Gleaned from the Linux tg3 driver. From Brad.


# 1.95 04-Jun-2009 naddy

replace the cumbersome macros that check for chip revisions with quirk flags
set at attach; from Brad


# 1.94 03-Jun-2009 naddy

register bit definitions instead of magic numbers;
gleaned from the Linux tg3 driver; from Brad


# 1.93 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.92 21-May-2009 sthen

add support for BCM576x, 577xx, and some new 572x/578x devices.
from Brad; testing by phessler, naddy, myself and others on a range
of older and newer devices. ok dlg@.


# 1.91 23-Apr-2009 kettenis

Start using extended buffer descriptors on the jumbo ring and use MCLGETI to
allocate mbufs for it. Another jumbo allocator bites the dust!

ok dlg@


Revision tags: OPENBSD_4_5_BASE
# 1.90 23-Dec-2008 dlg

if we cant put enough packets on the rx ring then schedule a timeout to
try again later.

tested by many


# 1.89 03-Dec-2008 dlg

switch bge over to using MCLGETI when allocating mbufs for the rx ring.

tested by many including henning@ sthen@ naddy@ krw@ robert@ jmc@ jsg@
weerd@ and ingo schwarze on a variety of machines include i386, amd64,
alpha, and sparc64.


# 1.88 08-Nov-2008 deraadt

brad, noone said you could go making changes like that (doubling the
amount of memory and interrupt time each bge uses) without discussing
it with other people. lots of people are complaining about the lack
of communication in your process, and you are going to have to change
that.


# 1.87 08-Nov-2008 brad

Clean up some of the comments.


# 1.86 07-Nov-2008 brad

When initializing the MAC put the PHY into ready state for BCM5906
chipsets.

From the Linux tg3 driver via FreeBSD.

Tested by Jordi Creix <jbcreix dot mail at gmail dot com>


Revision tags: OPENBSD_4_4_BASE
# 1.85 17-Jul-2008 brad

Add a flag and allow the driver to identify the BCM5788 chipsets. They're
slightly different from the other chipsets using the BCM5705 ASIC.

ok jsg@


# 1.84 16-Jul-2008 brad

Enable the read DMA engine's PCI read request burst length long burst
mode (4KB) for PCIe chips. This resolves the poor TX performance for
the PCIe chips. The result being a bit under double the TX performance
on a Gig connection (roughly 495 Mb/s -> 940 Mb/s).

Tested by reyk@, sthen@, brad@ and a few end users.


# 1.83 20-Apr-2008 brad

Add a workaround for a CRC bug errata with BCM5701 A0 and B0 chipset
revisions.

From Linux via FreeBSD.

ok dlg@


# 1.82 03-Apr-2008 brad

Clean up the DMA read/write control register setup code and add some
comments.

Tested by a number of users with a variety of chipsets.

From FreeBSD

ok kettenis@


Revision tags: OPENBSD_4_3_BASE
# 1.81 02-Mar-2008 brad

Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.

From jdp@FreeBSD

ok kettenis@


# 1.80 20-Feb-2008 brad

When collecting the hardware statistics add the interfaces input errors
counter and out of receive buffer descriptors counter to the network stacks
input errors counter.

Based on a diff from mickey@ though updated for -current and added support
for BCM5705 or newer chipsets from brad@.

Tested it with BCM5704 on i386/amd64, BCM5700 on sparc64, BCM5701/BCM5751M
on i386 and BCM5721/BCM5780 on amd64.

ok krw@ sthen@ dlg@


# 1.79 20-Feb-2008 sthen

when bge has link, use autopolling for link status, not direct mii polls.
fixes input errors on BCM5701/5702X/5704 and may avoid firmware hangs on
some cards if asf/ipmi support is added.

original diff from Oleg Bulyzhin in a freebsd-net post and ported by
mickey; included stats counter changes which don't apply to -current
so they are split out and not included here. "The rest of the diff
looks ok" brad.

tested on 5701/5702X/5703X/5704C/5721 by mpf naddy okan beck sthen

ok beck (before splitting out stats changes), krw, henning.
closes kernel/5699


# 1.78 18-Feb-2008 brad

Add initial bits for fiber support with the BCM5714/BCM5715/BCM5780 chipsets.

Tested by brad@, chl@, sthen@, Johan Mson Lindman and Ian Lindsay <iml04@hampshire.edu>

ok dlg@


# 1.77 02-Feb-2008 brad

- Simplify statistics updates and remove redundant register reads.
- Add discarded RX packets to input errors for the BCM5705 or newer
chipsets. Unfortunately output errors cannot be added because the
equivalent to the ifOutDiscards register does not exist.
- Replace misleading and wrong BGE_RX_STATS/BGE_TX_STATS with
BGE_MAC_STATS. They were reversed but just happened to work.

From FreeBSD

Tested by chl@, landy@, sthen@, krw@, okan@ and brad@

ok dlg@


# 1.76 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.75 17-Nov-2007 brad

Rename fiber TBI flag from BGE_TBI to BGE_PHY_FIBER_TBI. No functional change.

ok dlg@


# 1.74 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.73 11-Oct-2007 kettenis

Make BGE_JUMBO_FRAMELEN big enough to include vlan tag. Fixes problems with
receiving jumbo frames on bge(4).

ok krw@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.72 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.71 30-Jan-2007 krw

Rough in more support for 5787/5755 chips so far known to not work or
unreported in the wild. In this case add a PHY workaround for an eventual
mobile version of the chipset. No change to existing functionality.

From Michael Chan (mchan@broadcom), via Linux tg3 and brad.


# 1.70 10-Jan-2007 kettenis

Flow control support for bge(4)/brgphy(4). From brad@ based on code from
NetBSD.


# 1.69 22-Dec-2006 krw

Remove never used code for a BCM5700 feature (BGE_EXTRAM) that didn't
survive past 1st gen silicon.

From brad. Tested by wilfried@ and Johan Mason Lindman.


# 1.68 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.67 19-Oct-2006 tom

s/Mhz/MHz/ in comments and printf() strings

ok jsg@


# 1.66 17-Oct-2006 brad

disable the firmware fastboot feature on 5752/5755 and 5787 ASICs,
eliminates firmware timeouts.

Tested by pedro la peu <pedro at am-gen dot org> with a 5752 ASIC and
Benjamin Black <ben at layer8 dot net> with a 5787 ASIC.


# 1.65 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.64 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.63 07-Oct-2006 brad

add and set PHY workaround flags depending on the ASIC revision
or chip id.


# 1.62 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.61 01-Oct-2006 brad

add the PCI ids for the BCM5722, BCM5756, BCM5906 and BCM5906M chipsets.
the BCM5906/BCM5906M ids are not enabled for now; these chips are quite
a bit different from the others and are currently unsupported.


# 1.60 17-Sep-2006 brad

add a flag to indicate which boards are only capable of 10/100 modes of
operation.


# 1.59 17-Sep-2006 brad

Readd the Dell PHY LED setup workaround and the Jumbo capability flag.


# 1.58 17-Sep-2006 brad

- correct the firmware synchronization in bge_reset(), this
eliminates firmware timeouts for the BCM5752 as the hw
firmware was coming up too fast for the driver.
- remove the redundant firmware check in bge_chipinit().

Tested by pedro la peu <pedro at am-gen dot org> on an IBM ThinksPpad Z61m
with a BCM5752, as well as the 5700/5703/5704 and 5750.

The initial diff for bge_reset() and other information from
David Christensen <davidch at broadcom dot com>.


Revision tags: OPENBSD_4_0_BASE
# 1.57 29-Aug-2006 kettenis

Add support for onboard bge(4)'s on Sun UltraSPARC hardware that apparently
come without an attached SEEPROM.

ok deraadt@


# 1.56 28-Aug-2006 brad

revert flags usage commits. too close to release. will go in post release instead.

requested by deraadt@


# 1.55 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.54 28-Aug-2006 brad

Dell PCI vendor subid.


# 1.53 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.52 16-Aug-2006 brad

remove the sparc64 workarounds for the jumbo frame receive ring sizes now
that the iommu code has been fixed.


# 1.51 18-Jul-2006 brad

increase the number of Jumbo slots a little bit for sparc64.


# 1.50 01-Jul-2006 brad

recognize the 5750 C2.


# 1.49 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.48 19-Jun-2006 brad

some new ASIC revisions.


# 1.47 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.46 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.45 13-Apr-2006 brad

typo


# 1.44 05-Apr-2006 brad

add a power hook for bge(4).

From Thordur I. Bjornsson <thib at mi dot is>


# 1.43 10-Mar-2006 brad

in bge_intr() also check the PCI State register to see if there
are really any interrupts to service.

Based on the Linux tg3 driver though the Broadcom bcm5700 driver
does the same thing.


Revision tags: OPENBSD_3_9_BASE
# 1.42 21-Feb-2006 brad

- Overhaul link state detection code.
- Make use of if_link_state_change() so CARP will now see link state
changes for fibre cards.

revs 1.102, 1.104, 1.113, 1.120, and 1.124.

From FreeBSD

Tested with 5700/5701/5703/5704/5750 and a 5752.


# 1.41 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.40 01-Feb-2006 brad

some more constants.

From NetBSD


# 1.39 25-Jan-2006 brad

- Count packets discarded by RX/TX MAC (cause of FIFO overflow, etc)
as input/output interface errors.
- Keep values of rx/tx discards & tx collisions inside struct bge_softc.
So we can keep statistic across ifconfig down/up runs (cause bringing
bge up will reset chip).

From oleg FreeBSD


# 1.38 21-Jan-2006 brad

some cleaning after removing code for reading the VPD.


# 1.37 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.36 12-Dec-2005 brad

If a PCI-X card is detected then set bge_pcix.


# 1.35 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.34 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.33 27-Nov-2005 brad

add initial support for ASF.
this should allow IPMI BMC pass-through to work once the OS is running.

From Doug Ambrisko on the FreeBSD net list. Based on the Linux tg3 driver.


# 1.32 24-Nov-2005 fgsch

don't redefine BGE_PCIMISCCTL_ENDIAN_WORDSWAP and lower the delay while
waiting for the firmware. tested and ok brad@


# 1.31 19-Nov-2005 brad

Correct a performance bug from Bill Paul's original FreeBSD bge(4) driver:

Each call to the FreeBSD bge_start() routine the transmit producer
pointer index from the chip mailbox register BGE_MBX_TX_HOST_PROD0_LO.
The local copy of that value is then updated by bge_encap() as
bge_encap() encapsulates packets in the Tx ring. If bge_encap()
succeds in encpuslating one or more packets, bge_start() tells the
chip to start sending the newly-encinitiates writes the new value back
to the chip mailbox register.

However, comparison of the Linux drivers (Broadcom-supplied and
open-source tg3.c) and to the OpenSolaris driver confirms that
register BGE_MBX_TX_HOST_PROD0_LO is write-only to software.
Thus, we can just keep a copy in the softc, and eliminate the
(expensive) PCI register write on each call to bge_start().

From jonathan NetBSD

tested by krw@, sturm@ and I on a few different bge NICs.


# 1.30 09-Oct-2005 brad

BGE_RSLOTS is only used in one spot, BGE_TX_RING_CNT
should be used instead.


# 1.29 09-Oct-2005 brad

special case sparc64 for now and lower the Jumbo slots
down from 384 to 54.


# 1.28 04-Sep-2005 brad

add a comment


Revision tags: OPENBSD_3_8_BASE
# 1.27 30-Aug-2005 brad

- add BCM5780 PCI ids
- recognize BCM5704 B0
- recognize BCM5780 which is supposedly part of the BCM5714 family
according to the Linux driver but there is a BCM5714 core too. huh?

ok deraadt@


# 1.26 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.25 02-Jul-2005 brad

add support for PCI-E 5752 core and recognize a few additional
5750 revisions.

Info from the Broadcom Linux driver


# 1.24 29-Jun-2005 brad

- sync bus_dma ops and add bus_dmamap_sync()'s

and

rev 1.25

* bcm5700 chips rev Bx wedge up if given DMA descriptors of
eight bytes or less. Once hit, only reovery is a watchdog timeout/reset.
If the offending packet is retransmitted, the chip will wedge again...
Check for teeny fragments in a Tx request, and either fold the
teeny chunk residue into an adjacent mbuf, or m_dup the entire buffer.

From NetBSD

Tested on alpha/amd64/macppc by krw@ and ok krw@


# 1.23 17-Jun-2005 brad

- fix description for BCM5750 A0, A1 -> A0
- recognize BCM5750 B1


# 1.22 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.21 05-Apr-2005 brad

fix parenthesis for BGE_RCB_MAXLEN_FLAGS

ok krw@


Revision tags: OPENBSD_3_7_BASE
# 1.20 07-Mar-2005 krw

Enable basic big-endian operation. i.e. now works on some big-endian
machines (macppc) but not others (sparc64). No-op for little-endian
architectures.

Diff from NetBSD with tweaks by drahn@.

ok brad@


# 1.19 04-Mar-2005 krw

Put the dmamap for a transmission at the correct array index. Fixes a
crash on sparc64. From FreeBSD.


# 1.18 26-Dec-2004 brad

boundry -> boundary


# 1.17 17-Dec-2004 brad

rev 1.62

Possibloe fix for some bge chip revisions taking a long time to reset
(e.g., polling for a half-second or more at splnet(), blocking most
interrupts, durin an ifconfig down/ifconfig up).

Appears to help for a 5704C rev A3, which is the only chip I've
ever seen that had even a mild version of the reported problem.

rev 1.61

Check for BGE_PCI_PCISTATE register failing to revert on reset.
if it occurs, print a message indicating why the reset took so long.

From NetBSD


# 1.16 16-Dec-2004 brad

rev 1.71

* Set buffer management high water marks for MTU > 1514.

* Set BGE_MAX_RX_FRAME_LOWAT (from Linux driver).

rev 1.25

* Update onchip buffer tunables to recommended values from Linux drivers.

* Increase Tx interrupt-coalescing thresholds, to reduce Tx-done interrupts.

From NetBSD

ok krw@


# 1.15 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.14 12-Dec-2004 brad

add quirk lookup table, isn't used for anything at the moment
except printing the ASIC model and rev in dmesg. will be used
instead of checking ASIC revs all over the place.

From NetBSD


# 1.13 11-Nov-2004 brad

rev 1.71

Add some special case code to fix a problem with the BCM5704 in TBI (fiber)
mode. The 5704 apparently has some s00p3r s33kr1t registers for setting
the advertisement of pause frame ability (i.e flow control) when in
autoneg mode. If we don't set these registers correctly, we may not
be able to negotiate a proper link with some switches. (Symptom is that
the NIC reports the link as up (PCS synched) but no traffic can be
exchanged.)

rev 1.73

Commit patch to supress spurious link change events. Apparently, with
copper NICs, a link change event is posted whenever MII autopolling is
toggled off and on, which happens whenever someone calls
bge_miibus_readreg() or bge_miibus_writereg() to access the PHY
registers. This means anytime someone called the SIOCGIFMEDIA ioctl
on a bge interface, the link would reset. Even a simple "ifconfig bge0"
would do it, though other apps like dhclient or the PPPoE daemon could
trigger it as well. An obvious symptom of this problem is lots of
"bgeX: gigabit link up" messages appearing on the console for no
apparent reason.

Through experimentation, I determined that when a real link change
event occurs, the BGE_MIMODE_AUTOPOLL in the BGE_MI_MODE register
is always set, so now if we have a copper NIC and an link change
event occurs and the BGE_MIMODE_AUTOPOLL bit is clear, we ignore
the event.

Note that this does not apply to the original BCM5700 chip since we
use a different method for sensing link changes with that chip (the
status block method was broken), nor to fiber optic NICs since they
don't use the GMII PHY access registers.

From FreeBSD

ok deraadt@


# 1.12 31-Oct-2004 brad

rev 1.68

Add support for BCM5705K

rev 1.74

Add support for the BCM5750/5751. Unfortunately the documentation
I have from Broadcom does not give much information on these devices,
so the Broadcom Linux driver was used for clues to what these chips
support. It turns out they are similar to the 5705 with the 5751
being the PCI-Express version and needing special work-arounds and
settings.

From FreeBSD


# 1.11 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


Revision tags: OPENBSD_3_6_BASE
# 1.10 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.9 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


Revision tags: OPENBSD_3_5_BASE
# 1.8 19-Mar-2004 miod

Use __LP64__ to check for 64-bit systems.
Why people can't resolve to use this is beyond me.

There are other cases of this misconstruct, but they probably won't be
addressed for the release.

"why are you looking in there! that's gigabit!" then later ok deraadt@


# 1.7 13-Oct-2003 krw

Bring bge and brgphy more up to date with changes from FreeBSD and NetBSD.

Some bug fixes, support for new hardware like the 5704 and 5705.

Testing by deraadt@, danh@, and drahn@ amoung others.

ok deraadt@.


Revision tags: OPENBSD_3_4_BASE
# 1.6 03-Sep-2003 jason

match a bunch more bge devices. May not work completely, but they're no
more broken than before; ok deraadt.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.5 26-Nov-2002 nate

Numerous bug fixes from freebsd and a few from me.
- Add support for the BCM5702X and BCM5703X chips
- Take care of an alignment bug in the PCI-X implementation of a couple revs
of the chip
- Disable memory write invalidate. (Supposedly doesn't always work)
- Add missing splx(s)
- Fix some typos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE UBC_SYNC_B
# 1.4 08-Apr-2002 nate

Make fiber cards work (3com 3c996-SX)
Make the BCM5701 chips work. (3com 3c996B-T)
From FreeBSD


# 1.3 06-Mar-2002 nate

vtophys is no longer used


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.2 09-Oct-2001 nate

branches: 1.2.4; 1.2.6;
Make bge use busdma


# 1.1 05-Oct-2001 nate

Add a driver for the Broadcom BCM570x chips. (a.k.a. Tigon3).
This driver supports the following cards:
3Com 3c996-T (10/100/1000baseTX)
Dell PowerEdge 2550 integrated BCM5700 NIC (10/100/1000baseTX)
SysKonnect SK-9D21 (10/100/1000baseTX)
SysKonnect SK-9D41 (1000baseSX)

From FreeBSD