History log of /openbsd-current/sys/dev/pci/if_bge.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.405 24-May-2024 jsg

remove unneeded includes; ok miod@


# 1.404 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


Revision tags: OPENBSD_7_5_BASE
# 1.403 11-Feb-2024 jmc

recue -> reduce (in comment); from andrius v


# 1.402 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_4_BASE
# 1.401 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_3_BASE
# 1.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.404 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


Revision tags: OPENBSD_7_5_BASE
# 1.403 11-Feb-2024 jmc

recue -> reduce (in comment); from andrius v


# 1.402 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_4_BASE
# 1.401 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_3_BASE
# 1.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.403 11-Feb-2024 jmc

recue -> reduce (in comment); from andrius v


# 1.402 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_4_BASE
# 1.401 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_3_BASE
# 1.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.402 10-Nov-2023 bluhm

Make ifq and ifiq interface MP safe.

Rename ifq_set_maxlen() to ifq_init_maxlen(). This function neither
uses WRITE_ONCE() nor a mutex and is called before the ifq mutex
is initialized. The new name expresses that it should be used only
during interface attach when there is no concurrency.

Protect ifq_len(), ifq_empty(), ifiq_len(), and ifiq_empty() with
READ_ONCE(). They can be used without lock as they only read a
single integer.

OK dlg@


Revision tags: OPENBSD_7_4_BASE
# 1.401 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_3_BASE
# 1.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.401 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_3_BASE
# 1.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.400 18-Jan-2023 kettenis

These days bge_stop() calls intr_barrier(9). So in bge_detach() we need
to disestablish the interrupt *after* calling bge_stop().

ok deraadt@


# 1.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.399 09-Oct-2022 kevlo

Fix typo in debug messages.

ok deraadt@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.398 11-Mar-2022 mpi

Constify struct cfattach.


# 1.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.397 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.396 18-Jun-2021 jsg

recognise BCM5762 B0
from Brad


# 1.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.395 12-Jun-2021 kettenis

Enable code to read MAC address from the device tree on FDT platforms.

ok deraadt@, gkoehler@


# 1.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.394 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_9_BASE
# 1.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.393 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.392 26-Jul-2020 kettenis

Avoid nvram lock timeout on sparc64 systems with onboard BCM5704 instances
that come without a fitted EEPROM/NVRAM.

ok deraadt@, kn@


# 1.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.391 10-Jul-2020 patrick

Change users of IFQ_SET_MAXLEN() and IFQ_IS_EMPTY() to use the "new" API.

ok dlg@ tobhe@


# 1.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.390 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


# 1.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.389 18-Jun-2020 kettenis

BCM5719 A1 seen in the wild.

dlg@, deraadt@, mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.388 09-Nov-2018 claudio

M_LEADINGSPACE() and M_TRAILINGSPACE() are just wrappers for
m_leadingspace() and m_trailingspace(). Convert all callers to call
directly the functions and remove the defines.
OK krw@, mpi@


Revision tags: OPENBSD_6_4_BASE
# 1.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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.387 17-May-2018 yasuoka

Fix iLO/IPMI remote access problem. At least for bge(4) network port
which is shared with IPMI on HPE DL20 Gen9, its link state became down
a while or never became active again.

diff from FreeBSD through Naoki Fukaumi.
https://svnweb.freebsd.org/base?view=revision&revision=248226

ok mpi dlg


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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_6_2_BASE
# 1.386 17-Aug-2017 jsg

Fix asic test. Coverity CID 990792.
ok mpi@ tom@ mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.385 13-Feb-2017 dlg

properly set BGE_HCC_STATS_ADDR_HI by using BGE_HOSTADDR.

this makes it consistent with the rest of the code.


# 1.384 24-Jan-2017 dlg

add support for multiple transmit ifqueues per network interface.

an ifq to transmit a packet is picked by the current traffic
conditioner (ie, priq or hfsc) by providing an index into an array
of ifqs. by default interfaces get a single ifq but can ask for
more using if_attach_queues().

the vast majority of our drivers still think there's a 1:1 mapping
between interfaces and transmit queues, so their if_start routines
take an ifnet pointer instead of a pointer to the ifqueue struct.
instead of changing all the drivers in the tree, drivers can opt
into using an if_qstart routine and setting the IFXF_MPSAFE flag.
the stack provides a compatability wrapper from the new if_qstart
handler to the previous if_start handlers if IFXF_MPSAFE isnt set.

enabling hfsc on an interface configures it to transmit everything
through the first ifq. any other ifqs are left configured as priq,
but unused, when hfsc is enabled.

getting this in now so everyone can kick the tyres.

ok mpi@ visa@ (who provided some tweaks for cnmac).


# 1.383 22-Jan-2017 dlg

move counting if_opackets next to counting if_obytes in if_enqueue.

this means packets are consistently counted in one place, unlike the
many and various ways that drivers thought they should do it.

ok mpi@ deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.382 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.381 29-Dec-2015 dlg

shuffle tx code slightly and mark bge_start as mpsafe.

reviewed by jmatthew@
ok kettenis@


# 1.380 29-Nov-2015 kettenis

Make it possible to detach bge(4).

ok deraadt@


# 1.379 25-Nov-2015 dlg

replace IFF_OACTIVE manipulation with mpsafe operations.

there are two things shared between the network stack and drivers
in the send path: the send queue and the IFF_OACTIVE flag. the send
queue is now protected by a mutex. this diff makes the oactive
functionality mpsafe too.

IFF_OACTIVE is part of if_flags. there are two problems with that.
firstly, if_flags is a short and we dont have any MI atomic operations
to manipulate a short. secondly, while we could make the IFF_OACTIVE
operates mpsafe, all changes to other flags would have to be made
safe at the same time, otherwise a read-modify-write cycle on their
updates could clobber the oactive change.

instead, this moves the oactive mark into struct ifqueue and provides
an API for changing it. there's ifq_set_oactive, ifq_clr_oactive,
and ifq_is_oactive. these are modelled on ifsq_set_oactive,
ifsq_clr_oactive, and ifsq_is_oactive in dragonflybsd.

this diff includes changes to all the drivers manipulating IFF_OACTIVE
to now use the ifsq_{set,clr_is}_oactive API too.

ok kettenis@ mpi@ jmatthew@ deraadt@


# 1.378 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.377 23-Nov-2015 mpi

Include <sys/atomic.h> when atomic operations are used.

This has been masked because <sys/srp.h> is pulled unconditionally.

ok dlg@


# 1.376 17-Nov-2015 jmatthew

Clear if_timer when shutting down the interface so the watchdog timer
doesn't fire a few seconds later.

problem reported by Hrvoje Popovski, ok dlg@


# 1.375 17-Nov-2015 dlg

shuffle transmit to avoid IFQ_POLL.

basically make sure there's enough space in the ring before dequeueing a
packet for it.

ok mpi@ jmatthew@


# 1.374 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.373 12-Nov-2015 miod

Revert 1.372, reported to cause regressions on some models.


# 1.372 10-Nov-2015 miod

In bge_reset(), after figuring out which register access routines to use
depending upon the chip capabilities, use it everywhere instead of hardcoding
one call to bge_writemem_ind() by mistake; this unbreaks the BCM5704 A3 found
on some xserve G5 (RackMac3,1).

Also tested on a few other bge(4) chip models by jmatthew@ (5703X, 5714),
mpi@ (5780), naddy@ (5761) and me (5701).

ok dlg@


# 1.371 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


# 1.370 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@


Revision tags: OPENBSD_5_8_BASE
# 1.369 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.368 24-Jun-2015 mpi

Increment if_ipackets in if_input().

Note that pseudo-drivers not using if_input() are not affected by this
conversion.

ok mikeb@, kettenis@, claudio@, dlg@


# 1.367 19-May-2015 mikeb

Increase a maximum firmware handshake timeout to 10s

BCM5718 Programmers Guide in chapter 7 "Device Control", section
"Device Reset Procedure" states that SEEPROM chips need a larger
timeout than Flash ones.

ok reyk


# 1.366 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.365 09-Feb-2015 dlg

if_input sets m->m_pkthdr.rcvif so we dont have to.


# 1.364 09-Feb-2015 dlg

tweak the new if_input function so it takes an mbuf_list instead
of a single mbuf. this forces us to batch work between the hardware
rx handlers and the stack.

this includes a converstion of bge from ether_input to if_input.

ok claudio@ pelikan@ mpi@


# 1.363 24-Jan-2015 brad

Remove a comment that is no longer true with MCLGETI and jumbos on
some revisions of the chipsets.


# 1.362 22-Dec-2014 tedu

unifdef INET


# 1.361 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.360 26-Aug-2014 mikeb

Revert part of the if_rxr diff that incorrectly moves RX ring tail
index update code from the buf_get success path to the do it all
the time code path. Tested by millert; ok dlg, deraadt


# 1.359 21-Aug-2014 brad

Fix a copy and pasto with the standard ring setup with calling if_rxr_init()
to use BGE_STD_RX_RING_CNT instead of BGE_JUMBO_RX_RING_CNT.

ok dlg@


Revision tags: OPENBSD_5_6_BASE
# 1.358 22-Jul-2014 mpi

branches: 1.358.4;
Fewer <netinet/in_systm.h>


# 1.357 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.356 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@


# 1.355 03-Jul-2014 dlg

sending a heavily fragmented packet will cause the bus_dmamap_load
in bge_encap to fail because the dmamap lacks space, not necessarily
because the ring is full. however, bge_encap failure sets the OACTIVE
flag on the interface and keeps the packet at the start of the send
queue.

the next time we try to fill the tx ring we'll try to load the same
packet and fail. an empty tx ring means bge_txeof hasnt got anything
which is where the OACTIVE condition is cleared.

this diff adds handling of fragmented packets via m_defrag.

this might fix the issues landry@ has been complaining about on his
bulk build machines. i can reproduce the above problem in contrived
circumstances here and this diff fixes it, so its going in so landry@
is forced to test it.


# 1.354 22-Apr-2014 naddy

If VLAN_HWTAGGING is disabled, we tell the chip not to strip the
tag from the received frame. Do not add the tag from the receive
descriptor in this case so that the packet isn't tagged twice.
Matches FreeBSD.
ok brad@


Revision tags: OPENBSD_5_5_BASE
# 1.353 24-Feb-2014 brad

Revert rev 1.348 and disable IPv6 TCP checksum offload for the time being.
It has been reported that the offload support is not working properly with
some of the newer ASICs, specifically BCM57780 and BCM57765. It is unknown
what the issue is whether it could be hw, the driver or the stack; so to
be on the safe side it is being disabled all together until the issue
can be investigated further.

ok deraadt@


# 1.352 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.351 04-Feb-2014 brad

Revert part of rev 1.329 that involved bringing in some code from FreeBSD
and part of it touched upon the link state handling for the BCM5700 B2
revision of chipset. The special casing of the BCM5700 B2 chipset for
link state handling is wrong and doesn't work. This special casing was
removed in rev 1.229.

ok naddy@


# 1.350 01-Feb-2014 brad

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

ok naddy@


# 1.349 31-Jan-2014 brad

Fix a long standing VCPU reset sequence bug on BCM5906. The VCPU (Virtual CPU)
of BCM5906 is used to provide a mechanism to control the bootcode execution and
to pick up configuration data stored inside the EEPROM. The bootcode of BCM5906
will check the BGE_VCPU_STATUS_DRV_RESET bit to decide which boot procedure to
choose. Datasheet indicates the VCPU of BCM5906 should set BGE_VCPU_STATUS_DRV_RESET
bit before VCPU reset or global reset.

From FreeBSD

ok naddy@


# 1.348 28-Jan-2014 naddy

Enable IPv6 TCP checksum offload; ok brad@
(UDP is broken over both IPv4 and IPv6, verified on BCM5761.)


# 1.347 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.346 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@


# 1.345 28-Dec-2013 deraadt

The few network drivers that called their children's (ie. mii PHY
drivers) activate functions at DVACT_RESUME time do not need to do
so, since their PHYs are repaired by IFF_UP.


# 1.344 22-Dec-2013 kettenis

Add support for BCM57786,which seems to be almost indistinguishable from the
BCM57785.

Tested by Mark Rowland.


# 1.343 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.342 26-Nov-2013 deraadt

spelling; Kent R. Spillner


# 1.341 23-Oct-2013 brad

Enable TX checksum offload.

ok naddy@


# 1.340 25-Aug-2013 mikeb

call if_link_state_change when link state actually changes; ok claudio


# 1.339 07-Aug-2013 bluhm

Most network drivers include netinet/in_var.h, but apparently they
don't have to. Just remove these include lines.
Compiled on amd64 i386 sparc64; OK henning@ mikeb@


Revision tags: OPENBSD_5_4_BASE
# 1.338 11-Jul-2013 mikeb

use fls as initially intended


# 1.337 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.336 25-Jun-2013 mikeb

Repair flow control broken in the rev1.329 and make sure that a simple
ifconfig done by a user won't alter our negotiated flow control settings.
Both problems were identified by David Imhoff <dimhoff_devel @ xs4all !nl>
Tested by David on 5719, 5720, 5721, Hrvoje Popovski on 5704 B0, sthen@ on
5723/5784, naddy@ and jmatthew@ on 5702/5703, benno@ on 5704 A3 and me on
5715 and 5719.


# 1.335 10-Jun-2013 mikeb

A couple of changes from Masanobu SAITOH <msaitoh@netbsd.org>:

- fixup the Random Backoff Register value masking;

- keep the GPIO settings when modifying the Misc Local Control
register value.

Tested by Rob Sessink on 5719, David Imhoff on 5719, 5720, 5721,
me on 5719 and 5715; ok dlg


# 1.334 06-Jun-2013 dlg

dont count rx ring overruns as input errors. with MCLGETI controlling the
ring we expect to run out of rx descriptors as a matter of course, its not
an error.

ok mikeb@


# 1.333 04-Jun-2013 mikeb

A couple of style/comment fixes from FreeBSD, with input from
David Imhoff. No functional change.


# 1.332 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. Now with the right defines, doh!


# 1.331 04-Jun-2013 mikeb

Substitute a couple of magic numbers with newly added PCIE
DCTL flag defines. No binary change.


# 1.330 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.329 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


# 1.328 22-May-2013 mikeb

BUS_DMA_WAITOK can't be used in the bge_init path since it
might be called from a timeout(9); ok kettenis, dlg, deraadt


# 1.327 07-Apr-2013 dlg

check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd.

found by david imhoff.
tested by david on a 5719 and by me on a 5720 and 5721


# 1.326 03-Apr-2013 brad

Fix a typo in the bge_ape_lock_init() function.

From David Imhoff.

ok dlg@ sthen@


# 1.325 20-Mar-2013 brad

- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that do not have jumbo support
- Add/sync some of the comments

From FreeBSD

Tested by dlg@ sthen@ naddy@ and OK dlg@ sthen@


# 1.324 17-Mar-2013 brad

- Sync some of the stats counter code to be closer to the FreeBSD code,
but no functional change.
- Add a workaround for BCM5717 / BCM5718 / BCM5719 A0 and BCM5720 A0 chipsets
to not count the interface input drops counter for input errors due to HW
errata.

From FreeBSD

ok sthen@


# 1.323 11-Mar-2013 dlg

flush writes to BGE_MI_COMM by doing a read straight after. helps avoid
"APE lock request failed!" errors with HP 331T (5719) and 332T (5720)
cards.

found and fixed by masanobu saitoh


# 1.322 07-Mar-2013 brad

Add the PCI ids for the BCM57762 and BCM57766 chipsets.

ok sthen@


# 1.321 07-Mar-2013 brad

Correct the location of a DELAY() that was mismerged from FreeBSD in rev 1.319
within the ifmedia update function. It is supposed to come after the BGE_MAC_MODE
register write.

ok sthen@


# 1.320 04-Mar-2013 dlg

fix format string issue when printing an error our on bge's with APE and
more than 4 pci functions.

pointed out by masanobu saitoh


Revision tags: OPENBSD_5_3_BASE
# 1.319 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.318 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.317 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.316 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.315 15-Jan-2013 claudio

Fix typos in comments and change the syntactic sugar of a function to
reduce the diff between Fx and Ox. OK gcc


# 1.314 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.313 10-Jan-2013 dlg

oh hey guys, ive got this cool new thing called a "switch statement". your
if (thing == foo || thing == bar || thing == baz) is ugly.

no functional change.


# 1.312 13-Sep-2012 dlg

tell mii_attach where the phy is on the chip, rather than asking it to
probe every address and have bge_miibus_read fail at the wrong address.

needed to support recent chips which have phys in locations other than
phy address 1 (and removes a conditional in an io path).


Revision tags: OPENBSD_5_2_BASE
# 1.311 04-Jul-2012 kettenis

Invert the logic for detecting fibre interface media adapters.
Only the BCM5700-BCM5704 adapters had TBI interfaces for fibre
and anyting newer uses the MII interface.

From Brad.


# 1.310 04-Jul-2012 kettenis

Set the 10_100_ONLY flag for the BCM57791/BCM57795 chipsets
as they're FastE chipsets. So ifconfig media doesn't list
GigE for FastE-only capable PHY.

From Brad.


# 1.309 28-Jun-2012 mikeb

Devices with BCM5724 BCM5750 and BCM5750M PCI IDs were never released
to the public; from broadcom/linux via brad


# 1.308 09-Jun-2012 dlg

we dont support the BCM5720. the macro wasnt even referring to the products
actual id.

ok kettenis@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.307 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.306 05-Apr-2011 henning

mechanic rename M_{TCP|UDP}V4_CSUM_OUT -> M_{TCP|UDP}_CSUM_OUT
ok claudio krw


Revision tags: OPENBSD_4_9_BASE
# 1.305 22-Feb-2011 robert

Disable PCIe Active State Power Management (ASPM) to avoid bge(4) randomly
detaching from the bus on some of the machines.
tested by many, ok miod@


# 1.304 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.303 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.302 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


# 1.301 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


# 1.300 31-Aug-2010 deraadt

activate function should return result of config_activate_children


# 1.299 27-Aug-2010 deraadt

The powerhook only did stuff at resume; but suspend matters too!
Instead of fixing it, make it call the activate function which does
the full job
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.298 07-Aug-2010 krw

No "\n" needed at the end of panic() strings.

Bogus chunks pointed out by matthew@ and miod@. No cookies for
marco@ and jasper@.

ok deraadt@ miod@ matthew@ jasper@ macro@


# 1.297 02-Aug-2010 kettenis

There is no reason to call the start function upon resume; the network stack
is perfectly capable to get things going again all by itself.

ok deraadt@


# 1.296 27-Jul-2010 todd

spacing; ok deraadt@


# 1.295 27-Jul-2010 kettenis

Make sure we stop DMA before we suspend.

ok deraadt@


# 1.294 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.


# 1.293 06-Apr-2010 naddy

A fix for the PCI-X check so that this is only tested on controllers
that could be PCI-X. This bit is not valid for PCIe controllers.
From Brad


# 1.292 30-Mar-2010 naddy

Have bge_start check if there are less than 16 free send BDs and if not
set IFF_OACTIVE and try again later. Previously bge(4) reserved 16 send
BDs after loading DMA maps but the hardware only requires one reserved
send BD.

From FreeBSD, via Brad


Revision tags: OPENBSD_4_7_BASE
# 1.291 10-Jan-2010 naddy

Do not try to reevaluate the current RX production index on each
loop iteration as it can be updated by the card while we process
the RX ring, forcing us to process RX descriptors for which DMA
synchronisation has not been performed. This fixes a bug where
bge(4) will drop packets packets under heavy load.

Adapted from FreeBSD by Brad.


# 1.290 09-Jan-2010 naddy

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


# 1.289 17-Dec-2009 sthen

- correct the PCI ids for the BCM5717 and BCM5718 chipsets
- add BCM5724 chipset

from Linux driver via Brad.

- sort by device-id


# 1.288 09-Dec-2009 naddy

Do not count input errors twice. We always read input errors from
the MAC in bge_tick(). Previously this would result in bge(4) claiming
a greater number of input errors than what has actually occurred.

From FreeBSD via Brad


# 1.287 30-Nov-2009 kettenis

Re-initialise the interface upon resume.

ok deraadt@, pirofti@, claudio@


# 1.286 11-Oct-2009 sthen

Correct a copy-and-pasto (check for the same device type twice in
an if statement) in the last commit. From Brad.


# 1.285 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.284 07-Oct-2009 sthen

The BCM5703 ASIC ID is actually shared with the BCM5702 ASIC so
indicate so in the text strings. From Brad.


# 1.283 02-Oct-2009 sthen

Remove BCM57720 as it's not going to be released. From a Broadcom
commit to the Linux driver via Brad.


# 1.282 30-Sep-2009 sthen

- Sync the BCM5785G PCI id for bge(4) and add BCM5785F / BCM57788.

PCI ids from the Linux tg3 driver via Brad.


# 1.281 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


# 1.280 09-Aug-2009 deraadt

MCLGETI() will now allocate a mbuf header if it is not provided, thus
reducing the amount of splnet/splx dancing required.. especially in the
worst case (of m_cldrop)
ok dlg kettenis damien


# 1.279 08-Aug-2009 naddy

bring comments in line with reality; from Brad


# 1.278 06-Aug-2009 sthen

Backout r1.274, william@ has tracked down watchdog timeouts with
his BCM5703 A2 to this commit.

Original commit message was: "Set the DMA read watermark to 4 on the
BCM5703 chipset in PCI-X mode. This is needed to prevent some TX
timeouts. From Brad. Tested by myself on BCM5703 B0 on PCI-X 64/66".


# 1.277 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.276 19-Jun-2009 naddy

branches: 1.276.4;
Allow bge(4) to recognize the revisions of the 57780 ASICs. From Brad.


# 1.275 11-Jun-2009 sthen

Limit the BCM5701 B5 chipset to 32-bit mode as a workaround for a
bug which causes data corruption in combination with certain
bridges. Tested on BCM5701 B5 (0x105).

From FreeBSD via Brad. http://www.freebsd.org/cgi/query-pr.cgi?pr=128833


# 1.274 11-Jun-2009 sthen

Set the DMA read watermark to 4 on the BCM5703 chipset in PCI-X mode.
This is needed to prevent some TX timeouts. From Brad. Tested by myself
on BCM5703 B0 on PCI-X 64/66


# 1.273 06-Jun-2009 sthen

remove unused variable prevlen and a second initialization of ifp.
adjusted from a diff from chl@; ok naddy, Brad agrees.


# 1.272 05-Jun-2009 ray

%zu is not meant for size_t in the kernel. Change to %lu.

OK miod


# 1.271 04-Jun-2009 naddy

enable IPv6 receive TCP/UDP checksum offload for the 5755 and later chips;
from Brad


# 1.270 04-Jun-2009 naddy

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


# 1.269 03-Jun-2009 naddy

rename some macros for more consistent naming; from Brad


# 1.268 03-Jun-2009 naddy

set IFF_ALLMULTI properly also when in promiscuous mode and some
cosmetic tweaking; from Brad


# 1.267 03-Jun-2009 naddy

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


# 1.266 02-Jun-2009 naddy

minor tidying; from Brad; ok sthen@


# 1.265 02-Jun-2009 sthen

"Add a macro to define the newer generation of bge(4) chipsets. Simplifies
things a bit a and helps with adding support for more newer chipsets
with the same common features.

From the Linux tg3 driver."

From Brad; binaries are not identical; the if statement is changed
slightly, but no functional change. Looks fine to naddy@.


# 1.264 24-May-2009 naddy

Support hardware checksumming, from FreeBSD.
Enable for IP/UDP/TCP receipt and IP transmit.
Keep disabled for UDP/TCP transmit because it breaks with pf(4) rdr.

ok sthen@


# 1.263 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.262 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.261 27-Jan-2009 dlg

make drivers tell the mclgeti allocator what their maximum ring size is
to prevent the hwm growing beyond that. this allows the livelock mitigation
to do something where the hwm used to grow beyond twice the rx rings size.

ok kettenis@ claudio@


# 1.260 23-Dec-2008 dlg

sizeof(bge_devices) / sizeof(bge_devices[0]) -> nitems(bge_devices)


# 1.259 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.258 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.257 28-Nov-2008 brad

Eliminate the redundant bits of code for MTU and multicast handling
from the individual drivers now that ether_ioctl() handles this.

Shrinks the i386 kernels by..
RAMDISK - 2176 bytes
RAMDISKB - 1504 bytes
RAMDISKC - 736 bytes

Tested by naddy@/okan@/sthen@/brad@/todd@/jmc@ and lots of users.
Build tested on almost all archs by todd@/brad@

ok naddy@


# 1.256 22-Nov-2008 dlg

perform bus_dmamap_syncs on the rx mbufs. this is obviously maintained by
monkeys.

found by toby's bounce buffers.
ok krw deraadt uwe fwk matthieu, drahn, mbalmer, robert, yuo, ratchov,
claudio, rainer, art.


# 1.255 09-Nov-2008 naddy

Introduce bpf_mtap_ether(), which for the benefit of bpf listeners
creates the VLAN encapsulation from the tag stored in the mbuf
header. Idea from FreeBSD, input from claudio@ and canacar@.

Switch all hardware VLAN enabled drivers to the new function.

ok claudio@


# 1.254 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.253 08-Nov-2008 deraadt

When initializing the standard RX ring, do not allocate mbufs clusters for the
whole ring.


# 1.252 08-Nov-2008 brad

Clean up some of the comments.


# 1.251 08-Nov-2008 brad

When initializing the standard RX ring, allocate mbufs clusters for the
whole ring.


# 1.250 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>


# 1.249 19-Oct-2008 brad

Re-add support for RX VLAN tag stripping.

Tested by naddy@


# 1.248 16-Oct-2008 naddy

Switch the existing TX VLAN hardware support over to having the
tag in the header. Convert TX tagging in the drivers.

Help and ok brad@


# 1.247 14-Oct-2008 naddy

Change m_devget()'s outdated and unused "offset" argument: It is
now the offset into the first mbuf of the target chain before copying
the source data over. From FreeBSD.

Convert drivers' use of m_devget(). Mostly from thib@.

Update mbuf(9) man page.

ok claudio@, thib@


# 1.246 02-Oct-2008 brad

First step towards cleaning up the Ethernet driver ioctl handling.
Move calling ether_ioctl() from the top of the ioctl function, which
at the moment does absolutely nothing, to the default switch case.
Thus allowing drivers to define their own ioctl handlers and then
falling back on ether_ioctl(). The only functional change this results
in at the moment is having all Ethernet drivers returning the proper
errno of ENOTTY instead of EINVAL/ENXIO when encountering unknown
ioctl's.

Shrinks the i386 kernels by..
RAMDISK - 1024 bytes
RAMDISKB - 1120 bytes
RAMDISKC - 832 bytes

Tested by martin@/jsing@/todd@/brad@
Build tested on almost all archs by todd@/brad@

ok jsing@


# 1.245 23-Sep-2008 brad

Rewrite two small sections of code in bge_blockinit() to simplify the
code. No functional change.

ok krw@


# 1.244 18-Sep-2008 naddy

Introduce the infrastructure required to support hardware VLAN tag
stripping: Add a field to the mbuf pkthdr to hold the tag and an
mbuf flag that tells if the tag is valid. Inspired by FreeBSD.

Struct packing suggested by kettenis@. csum_flags is now 16 bits.
Adapt to this in the drivers.

ok reyk@, henning@


# 1.243 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


# 1.242 08-Sep-2008 brad

Fix a link state issue reported by reyk@

In some situations we were not clearing pending link state attentions.
Because of this we were not getting further interrupts for link state
changes, thus never went into iface UP state.

Force an interrupt at the end of bge_ifmedia_upd so we will call
bge_link_upd, clear the link state attention and get further
interrupts.

From FreeBSD

ok reyk@


# 1.241 26-Aug-2008 kettenis

Better strategy to single out onboard bge(4)'s on sparc64 machines.

ok deraadt@


# 1.240 24-Aug-2008 deraadt

Tadpole Viper onboard ethernet has no eeprom either, but the PROM entry
has subsystem ids set to the same as the regular ids, so the heuristic does
not work. So look for the TAD,Viper machine name. When we get our hand on
a Bullfrog (with a PCI slot) we will need to revisit this.
ok kettenis


# 1.239 24-Aug-2008 deraadt

proper indent


Revision tags: OPENBSD_4_4_BASE
# 1.238 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.237 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.236 07-Jun-2008 brad

Add baudrate handling for fiber boards using the TBI interface.

ok deraadt@


# 1.235 24-May-2008 brad

And another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.234 23-May-2008 kettenis

Another Fujitsu Gigabit Etherenet card that is a bge(4) in disguise.


# 1.233 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


# 1.232 21-May-2008 kettenis

Fujitsu PRIMEPOWER250/450 secondary LAN is a BCM5703C in disguise.


# 1.231 14-May-2008 brad

Add the Altima AC1003 PCI id.

ok dlg@


# 1.230 12-May-2008 brad

Call mii_pollstat() instead of bge_tick() in bge_link_upd() so that link
state transitions are noticed and the appropriate routing socket messages
are generated.

ok kettenis@ krw@


# 1.229 11-May-2008 brad

Remove special casing of the BCM5700 B2 chipset so that this revision also
uses MII interrupts to detect link state transitions as is done for all of
the other BCM5700 revisions, without this change link state transitions
are not being detected at all.

ok kettenis@


# 1.228 11-May-2008 brad

Revert the last commit as this is not the proper way of fixing the issue.

ok krw@


# 1.227 09-May-2008 krw

Attempt to fix link status change handling so that the proper RTM_IFINFO
messages are generated when links go down or come up. Works on available
devices, put in tree to encourage wide testing. Enables latest dhclient
changes to work their magic on bge.

Feedback from brad@

ok deraadt@ beck@ reyk@


# 1.226 20-Apr-2008 brad

rev 1.35 added special register settings for BCM5704 chipsets when
in TBI mode for fiber adapters which causes problems for some systems.
Add code to detect when the special settings are necessary which helps
with some blade systems.

From FreeBSD

ok dlg@


# 1.225 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.224 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@


# 1.223 21-Mar-2008 brad

Pass the MIIF_HAVEFIBER flag along to mii_attach() for MII based fiber
adapters.

Tested by brad@ and johan@ to ensure flow control is still working for
copper adapters.


Revision tags: OPENBSD_4_3_BASE
# 1.222 20-Feb-2008 brad

branches: 1.222.2;
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.221 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.220 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.219 17-Feb-2008 brad

- Correct clearing of the IFF_OACTIVE flag by ensuring the flag is
only cleared if there is enough slack space since bge_encap() will
return anyway and IFF_OACTIVE will be set again.
- Only reset the watchdog timer when all packets have been processed.
- Have bge_start() do a fast return if the adapter is not running or
the IFF_OACTIVE flag is set.

Tested by brad@, chl@, krw@, landry@, sthen@ and Johan Mson Lindman.

ok dlg@


# 1.218 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.217 31-Jan-2008 brad

recognize the BCM5755 C0 ASIC revision.

tested by Rodolfo Gouveia and marco@

ok kettenis@ marco@ dlg@


# 1.216 17-Nov-2007 brad

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

ok dlg@


# 1.215 13-Oct-2007 kettenis

Add support for BCM5906.

ok deraadt@


# 1.214 09-Oct-2007 ray

Use %zu for printing size_t values.

OK dlg.


Revision tags: OPENBSD_4_2_BASE
# 1.213 21-Jun-2007 dlg

rework how the IFF_PROMISC and IFF_ALLMULTI flags are dealt with, and how
the multicast filter is programmed.

IFF_ALLMULTI is for use by the driver and only the driver, meaning that we
have to clear it when its not needed anymore.

now that the ethernet layer counts the number of multicast address ranges
we can check that early to determine if ALLMULTI is needed, rather than
doing the stupid goto allmulti dance as we iterate over the multicast
address list.

the imperfect multicast filter is a 16 byte wide bitfield, so we can use
the "setbit" macro to build it in memory, and then write it to the hardware
as a bus_space region. this simplifies the code a lot and avoids confusing
bitshifts on u_int32_ts to get the bits in the right place.

tested by krw on amd64, naddy on alpha, deraadt on sparc64, and beck on
various bits.
ok beck


# 1.212 03-May-2007 tom

The ring replenish threshold change needed to work around a hardware
problem also appears to be required on the BCM5754/5787 in the Dell
PowerEdge SC440 and OptiPlex GX745. dlg identified the problem and
came up with the fix.

Tested by dlg@, ckuethe@, reyk@; thanks.

ok dlg@ beck@ reyk@


# 1.211 02-May-2007 dlg

the 5754 and 5787 share the same ASIC ID, make the crazy strings list both
so its obvious to people working on the code


# 1.210 02-May-2007 dlg

do { } while (0) for the debug macros


# 1.209 03-Apr-2007 kettenis

On sparc64, prefer the local-mac-address provided by the PROM. Makes sure the
MAC address on the builtin ports of the Sun Fire V215 match what is used by
the PROM.

ok deraadt@


# 1.208 19-Mar-2007 krw

Fix some code relative to chips that don't currently work (BCM5722 &
BCM5756). They still don't work but when they do they won't use an
inappropriate Jitter bug workaround. No effect on other chips.

From Michael Chan of Broadcom, via Linux tg3 via Brad.

ok reyk@


Revision tags: OPENBSD_4_1_BASE
# 1.207 16-Feb-2007 krw

bge_newbuf_std() should return ENOBUFS on failure, as that's what
callers check for. One return accidentally changed to ENOMEM when
r1.133 reverted r1.85. Nuke superfluous blank line.

From brad@, tested by myself and Johan M:son Lindman.


# 1.206 10-Feb-2007 krw

Add more chipset revision ids.

From scottl via FreeBSD and brad@.


# 1.205 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.204 19-Jan-2007 krw

Workarounds for DMA HW errata on pci express chips. Based on FreeBSD
changes but with the more conservative (i.e. specific) chip matching
logic of Linux's tg3. No change except to pci express chips.

From Brad.

Tested by brad & thib@ (BCM5750) and pedro la peu (BCM5752).


# 1.203 10-Jan-2007 kettenis

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


# 1.202 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.201 17-Dec-2006 krw

Add/modify some comments. From Brad.


# 1.200 08-Dec-2006 gwk

Add the Broadcom BCM5787F PCI id.
Add D-Link DGE-560SX and another Marvell Yukon (unknown model) PCI ids.
From the Linux sky2 driver via brad@


# 1.199 04-Dec-2006 reyk

report full/half duplex state for non-MII interfaces

ok brad@


# 1.198 26-Nov-2006 brad

revert the Jumbo diff that was commited as part of a wireles drivers commit.


# 1.197 26-Nov-2006 deraadt

do not have each net80211 driver define its own rates structures. if they use
the standard rates, use some defined by net80211 itself. kernel shrinks a bit
ok jsg mglocker


# 1.196 20-Nov-2006 brad

set the IFCAP_VLAN_HWTAGGING capabilities flag.


# 1.195 28-Oct-2006 brad

M_TRAILINGSPACE(m) returns 0 if M_READONLY(m) is true,
so no need to call both.

From tsutsui@NetBSD


# 1.194 26-Oct-2006 brad

Fix this by commiting the proper revision of the bge_encap() diff.


# 1.193 26-Oct-2006 brad

bge_encap():
- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested by brad@ sturm@ wilfried@


# 1.192 25-Oct-2006 brad

replace a few more instances of hand rolled code with the
LIST_FOREACH macro.


# 1.191 22-Oct-2006 brad

recognize the BCM5715 A3 chipset.


# 1.190 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.189 15-Oct-2006 brad

recognize the BCM5787 A2 chipset.


# 1.188 10-Oct-2006 brad

revert the firmware synchronization change in rev 1.178, this is the cause
of the first port of a dual port MAC to not work.


# 1.187 09-Oct-2006 deraadt

The mickey (/brad) jumbo allocation avoidance patch triggers the same
ami bug "on a particular machine" as the uvm anon change that needed
to be backed out on jul 13.

at least now you are getting close to knowing whether this is a uvm
bug or an ami bug or somewhere else; something starves or cuts memory
up badly enough to cause a big problem.


# 1.186 07-Oct-2006 brad

add a no Ethernet@Wirespeed flag.


# 1.185 07-Oct-2006 brad

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


# 1.184 01-Oct-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.183 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.182 26-Sep-2006 brad

update the comment for bge_chipinit().


# 1.181 26-Sep-2006 mickey

do not alloc jumbo buffers (3.5m per iface) and also do not allow card to receive large frames until mtu is set to higher value (later piece from brad); brad@ ok


# 1.180 17-Sep-2006 brad

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


# 1.179 17-Sep-2006 brad

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


# 1.178 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>.


# 1.177 17-Sep-2006 brad

defer establishing the interrupt until later during attach, to let the
driver finish initializing. fixes a panic in bge_intr() upon bootup on
some systems running non-MP kernels.

Issue reported/fix tested by jolan@, also mentioned in PR 5114 though the
issue is intermisttent on the IBM e326m.


Revision tags: OPENBSD_4_0_BASE
# 1.176 16-Sep-2006 kettenis

Get subvendor from the PROM instead of the PCI configuration space, since the
latter gets reset if you netboot from an interface.
ok miod@, brad@, deraadt@


# 1.175 30-Aug-2006 kettenis

Try to read station address from the chip first, then try the EEPROM (if we
think it is there). On sparc64 try to read the local-mac-address property
from Open Firmware and as a last resort use the idprom property.
Hopefully fixes reading the station address on the Blade 1500.

ok deraadt@


# 1.174 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.173 28-Aug-2006 kettenis

Get MAC address from the OpenFirmware local-mac-address property on sparc64.
Needed to support onboard bge(4)'s on Sun machines which don't seem to be
fitted with the EEPROM that normally contains the MAC address.

ok brad@


# 1.172 28-Aug-2006 brad

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

requested by deraadt@


# 1.171 28-Aug-2006 brad

add a BGE_JUMBO flag.


# 1.170 28-Aug-2006 brad

Set the BGE_NO3LED flag to properly adjust the PHY LED mode if attaching
to either a BCM5700 or BCM5701 chip and have the Dell PCI vendor subid.
The appropriate code has been in brgphy for 2 years, now the bge(4) driver
will use it.

Also found in the Broadcom bcm5700 and Linux tg3 drivers.


# 1.169 27-Aug-2006 brad

it works a little better like this.


# 1.168 27-Aug-2006 brad

pack several boolean fields into the existing bge_flags field.


# 1.167 04-Aug-2006 brad

move the promiscuous mode handling code into bge_setpromisc() and simplify
the interface flags ioctl handler.


# 1.166 01-Jul-2006 brad

recognize the 5750 C2.


# 1.165 29-Jun-2006 brad

do not return from the reset function if there was a timeout
with the firmware.


# 1.164 27-Jun-2006 brad

don't set BGE_DEBUG by default, reduces the bloat a bit. noticed by deraadt.
no one noticed this has been here since rev 1.1.


# 1.163 27-Jun-2006 brad

Disable Jumbos on the 5714 family of chips for now. The bge driver assumes
that all chips which have Jumbo capability have a separate Jumbo receive ring.
It seems as if the 5714 family has done away with the separate receive ring,
according to the Linux driver.


# 1.162 22-Jun-2006 brad

recognize the BCM5703 B0.


# 1.161 21-Jun-2006 brad

remove some unused code.

ok reyk@


# 1.160 21-Jun-2006 brad

add the BCM5786 PCI id.

From the Linux tg3 driver.


# 1.159 20-Jun-2006 brad

have bge_start() check for an empty send queue instead.


# 1.158 20-Jun-2006 brad

- check for revision B2 intead of B1 in one more spot.
- fix no link check in bge_start().


# 1.157 20-Jun-2006 brad

add the BCM5755 and BCM5787 ASICs to the appropriate macros.


# 1.156 19-Jun-2006 brad

add the new ASIC revs to the bge_majorrevs table.


# 1.155 19-Jun-2006 brad

add new PCI ids.


# 1.154 17-Jun-2006 brad

add sys/timeout.h


# 1.153 15-Jun-2006 brad

make these tables look a little bit nicer.


# 1.152 11-Jun-2006 brad

the link state detection code should be checking for revision B2 instead
of B1 to account for the differences with the revision defines used in
OpenBSD's if_bgereg.h vs FreeBSD's.


# 1.151 02-Jun-2006 beck

Deja-vu - again I make bge stop claiming all interrupts for it's own.

This appears to have been due to driver changes and the fact that
the status word seems to not be cleared. linux may have the same bug.
freebsd does clear the status word with and atomic read and clear
ops. we instead do best effort here to check for the interrupt being
ours by reading the status from the status block to a local copy,
then clearing the status word once we enter the interrupt handler
and using the local copy for checking link status

ok jason@


# 1.150 31-May-2006 brad

xcs -> xsc


# 1.149 28-May-2006 brad

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

ok reyk@


# 1.148 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.147 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.146 20-May-2006 brad

remove commented out and unused capabilities flags.


# 1.145 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.144 08-May-2006 brad

KNF


# 1.143 30-Apr-2006 brad

style


# 1.142 24-Apr-2006 brad

add a missing return here.


# 1.141 21-Apr-2006 brad

recognize the BCM5752 A2


# 1.140 05-Apr-2006 brad

add a power hook for bge(4).

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


# 1.139 29-Mar-2006 brad

check for IFF_RUNNING being set before calling bge_init().


# 1.138 25-Mar-2006 djm

allow bpf(4) to ignore packets based on their direction (inbound or
outbound), using a new BIOCSDIRFILT ioctl;
guidance, feedback and ok canacar@


# 1.137 16-Mar-2006 brad

if the link is down with a card using a fibre interface then show a
media status of none.


# 1.136 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.135 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.134 13-Feb-2006 brad

Due to an oversight on my part I forgot to remove clearing of the
BGE_PCIDMARWCTL_MINDMA flag from the PCI DMA control register
on newer bge chipsets when I put in the new PCI DMA control register
settings.

Thanks to Daniel Ouellet for testing with a BCM5780 and to Dimitry Andric
for testing with a BCM5750.


# 1.133 13-Feb-2006 brad

revert rev 1.85. The mbuf needs to be re-mapped in the case of an error.

ok damien@


# 1.132 11-Feb-2006 brad

recognize another 5714 family chipset.


# 1.131 09-Feb-2006 brad

cleaning.


# 1.130 09-Feb-2006 brad

adjust timeouts a bit.

Based on the Broadcom Linux driver.


# 1.129 08-Feb-2006 brad

fix MTU check.

From damien@


# 1.128 06-Feb-2006 brad

Make sure to call bge_setmulti() as we're enabling or disabling promiscuous
mode so as to receive all multicast packets too.


# 1.127 02-Feb-2006 brad

Call bge_setmulti() if IFF_ALLMULTI is set.

From ru FreeBSD


# 1.126 02-Feb-2006 brad

Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process.

From oleg FreeBSD


# 1.125 02-Feb-2006 brad

Use alternate PCI DMA control register settings for PCI Express-based
Broadcom Gigabit Ethernet interfaces.

From jonathan NetBSD and based on the Broadcom Linux driver.

Tested by a few end-users.


# 1.124 01-Feb-2006 brad

rearrange code section for enabling the read DMA state machine
to allow enabling the long burst FIFO on PCI Express cards though
its currently disabled at the moment.

From jonathan NetBSD and based on the Broadcom Linux driver.


# 1.123 01-Feb-2006 brad

one less magic value.


# 1.122 01-Feb-2006 brad

Set up the PCI DMA control register properly for the 5714 family,
only tested on the BCM5780 so far as found in the ServerWorks
HT-2000 chipset. bge goes from slow throughput and constant
watchdog resets to no watchdog's and decent throughput and what
appears to be stable operation.

From jonathan NetBSD and based on the Broadcom Linux driver.

Thanks to Daniel Ouellet for testing on an IBM e326m


# 1.121 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.120 28-Dec-2005 brad

clear IFF_RUNNING here to get a full re-init.


# 1.119 28-Dec-2005 brad

using the PCI capability register to check for PCI-X mode doesn't get the expected
result as this is set whether the board is in a PCI-X slot or not. The chip
can tell us if we're on a conventional PCI bus.


# 1.118 28-Dec-2005 brad

Fix bge_eeprom_getbyte() to return 1 when timeout happens.
Previously it always returned 0 which means success regardless of
EEPROM status.

While here, add a check whether EEPROM read is successful.

From yongari FreeBSD


# 1.117 28-Dec-2005 brad

eliminate the last few quirk flags.


# 1.116 12-Dec-2005 brad

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


# 1.115 11-Dec-2005 brad

recognize BCM5750 C1 on Ted's Fujitsu Lifebook S7000


# 1.114 10-Dec-2005 brad

re-add bge_shutdown() but also register the function with
shutdownhook_establish().


# 1.113 09-Dec-2005 brad

remove unused function bge_shutdown().


# 1.112 09-Dec-2005 brad

some cleaning and fixing of comments.


# 1.111 08-Dec-2005 brad

- Enable the buffer manager on 5705 and newer ASICs.
- Enable the memory arbiter on 5705 and newer ASICs with 5714 family
specific trick from Broadcom's Linux driver.

Tested by Chuck McCollum and Ray Kohler on 575x ASICs.


# 1.110 08-Dec-2005 brad

This makes bge(4) only look for a PHY at id 1 as done by Broadcom's
Linux driver and FreeBSD. This reverts a change I made based on
NetBSD's bge(4) driver when adding the quirk table flags. Eliminate
the BGE_QUIRK_ONLY_PHY_1 quirk flag.

ok dlg@ krw@


# 1.109 08-Dec-2005 brad

eliminate the BGE_QUIRK_FEWER_MBUFS quirk flag and assume lower mbufs on
all 5704's. also remove a bit of code duplication in this section of code.

ok krw@


# 1.108 08-Dec-2005 brad

add BCM5903M PCI id and recognize BCM5714 and BCM5715 ASICs.

From Broadcom's Linux driver


# 1.107 29-Nov-2005 brad

Put this back in...

Use pci_get_capability() to check if were on a PCI Express card or not.

Tested by deraadt@, marco@ and a few end-users who reported issues.


# 1.106 28-Nov-2005 brad

back out the last 2 commits to bge(4) for now.


# 1.105 27-Nov-2005 brad

Use pci_get_capability() to check if were on a PCI Express card or not.


# 1.104 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.103 25-Nov-2005 brad

fix BCM5714 PCI id name and add 5714S, 5715 and 5715S.


# 1.102 25-Nov-2005 brad

Use BGE_IS_5705_OR_BEYOND macro to check for the existence or non-existence
of 5705 or derived ASICs and remove the BGE_QUIRK_5705_CORE flag.


# 1.101 25-Nov-2005 brad

remove prototype for a non-existent function bge_free_jumbo_mem.


# 1.100 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE in one more spot.


# 1.99 25-Nov-2005 brad

use 5780 here instead of 5714.


# 1.98 25-Nov-2005 brad

don't bother setting error in bge_attach() when its not actually
being used for anything.


# 1.97 25-Nov-2005 brad

Use BGE_IS_575X_PLUS macro when checking whether to use the PCI Express test or not.


# 1.96 25-Nov-2005 brad

Use BGE_IS_JUMBO_CAPABLE macro to figure out whether we
want Jumbos or not. Instead of just assuming that all 5705
derived cores do not support Jumbos. All of Broadcom's new
Gig chips do not support Jumbos with the exception of the
BCM5714 found embedded in the ServerWorks HT-2000 chipset
using the BCM5780 ASIC.


# 1.95 24-Nov-2005 brad

add a few macros allowing selection of certain generations of
the Broadcom ASICs.


# 1.94 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.93 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.92 14-Nov-2005 mickey

bus_size_t is a more proper type for a register offset [against bh]


# 1.91 21-Oct-2005 brad

tidy up dmesg printing.


# 1.90 14-Oct-2005 brad

only print warning message in bge_stop_block() if debug is enabled.


# 1.89 14-Oct-2005 brad

sprinkle some ANSI and KNF and remove an empty useless function.


# 1.88 14-Oct-2005 brad

shuffle these structs up to the top.


# 1.87 10-Oct-2005 brad

splimp -> splnet


# 1.86 09-Oct-2005 brad

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


# 1.85 09-Oct-2005 brad

- move bus_dmamap_load_mbuf() to where it should be in bge_newbuf_std()
- add comments mentioning where we're re-using mbufs


# 1.84 06-Oct-2005 brad

change "pcistate failed to revert" test message to a debug printf.


# 1.83 06-Oct-2005 brad

add Apple BCM5701


# 1.82 08-Sep-2005 brad

- Removes spl durring attach
- Use pci_mapreg_map()
- Ensure bge_attach() always cleans up properly upon failure

ok krw@ sturm@


Revision tags: OPENBSD_3_8_BASE
# 1.81 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.80 27-Aug-2005 brad

recognize 5752 A1 ASIC rev.

Noticed by niklas@ on some newer hardware

ok deraadt@


# 1.79 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


# 1.78 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.77 20-Jul-2005 brad

remove some unused code.


# 1.76 16-Jul-2005 brad

remove braces here too


# 1.75 14-Jul-2005 jsg

More bge ids, found in Broadcom's Linux driver. ok brad@


# 1.74 09-Jul-2005 brad

remove braces here


# 1.73 07-Jul-2005 brad

check ETHERMIN and stop calling em_init_locked() from SIOCSIFMTU ioctl.


# 1.72 06-Jul-2005 brad

allow bge(4) to receive Jumbos by default.

ok krw@


# 1.71 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.70 01-Jul-2005 brad

revert rev 1.59


# 1.69 29-Jun-2005 brad

volatile here


# 1.68 29-Jun-2005 brad

rev 1.25

* Add workaround for revision Bx bcm5700: chip bugs in decoding
of PCI register writes may leave the hardware in (partial) powersave state,
such that writes to "indirect" registers do not work.
Explicitly force chip into D0 state at attach time.

From NetBSD


# 1.67 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.66 26-Jun-2005 brad

remove unused code in bge_intr()


# 1.65 26-Jun-2005 brad

- clear IFF_RUNNING & IFF_OACTIVE in dc_stop() before de-allocating resources.
- remove unused FreeBSD specific code


# 1.64 17-Jun-2005 brad

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


# 1.63 15-Jun-2005 camield

Disable hardware vlan decapsulation.

ok brad henning jason


# 1.62 07-Jun-2005 brad

put the whole thing in this time.

add support for the BCM5714.


# 1.61 07-Jun-2005 deraadt

undo busted diff. why AGAIN brad????


# 1.60 07-Jun-2005 brad

add support for the BCM5714.

From FreeBSD


# 1.59 21-May-2005 brad

backout part of rev 1.35, which breaks some 5704-based fibre interfaces on
some IBM/Intel blade servers.

From FreeBSD


# 1.58 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


# 1.57 04-Apr-2005 beck

Fix interrupt sharing on bge, by checking the same way the linux
driver does. ok deraadt@, testing and ok krw@, markus@


# 1.56 01-Apr-2005 brad

0 -> prodidx. breakage for 5700 Bx workaround introduced in rev 1.21

Noticed/tested by aaron@


# 1.55 27-Mar-2005 krw

Fix possible double alignment, and a memory leak in error path. Mostly
from FreeBSD.

ok brad@.


Revision tags: OPENBSD_3_7_BASE
# 1.54 07-Mar-2005 brad

print ASIC ID in hex too incase only the "superclass" of the ASIC is
recognized.


# 1.53 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.52 04-Mar-2005 krw

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


# 1.51 17-Jan-2005 brad

add BGE_QUIRK_FEWER_MBUFS to 5704 fallback case.


# 1.50 01-Jan-2005 krw

Add BGE_QUIRK_ONLY_PHY_1 to BCM5701_B2. From NetBSD PR #23778, as
pointed out by Theo 2003/12/13.

ok brad@.


# 1.49 30-Dec-2004 krw

Don't zero error value, return it.

ok brad@.


# 1.48 26-Dec-2004 brad

add BGE_QUIRK_PCIX_DMA_ALIGN_BUG for BCM5701 A0


# 1.47 24-Dec-2004 deraadt

brad should compile before commiting


# 1.46 24-Dec-2004 brad

init Jumbo RX ring by default.

ok krw@


# 1.45 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.44 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.43 12-Dec-2004 brad

use quirk flags where appropriate.

Based on NetBSD driver

ok krw@


# 1.42 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.41 11-Dec-2004 brad

rev 1.11

When stopping the various functional blocks of the chip, clear the
bit and then read it back in a loop (with appropriate delays) waiting
for it to read back clear.

This fixes a problem where the bus would hang when bringing down
the interface or changing interface flags on a system with a
sufficiently fast CPU (e.g. 2GHz P4 Xeon).

From NetBSD

ok krw@


# 1.40 10-Dec-2004 brad

rev 1.5

Put some delay in the loops that poll for MII transaction
completion. Without this, reading the PHY can hang the bus
on a sufficiently fast CPU.

From NetBSD


# 1.39 10-Dec-2004 krw

1) Don't manually fiddle with dma address of jumbo buffer after m_adj().

2) Create tx_map's large enough to map jumbo buffers.

3) Set length of jumbo frame to BGE_JLEN rather than ETHER_MAX_DIX_LEN.

4) Activate jumbo rx ring when MTU changed. (From FreeBSD).

Makes jumbo frames work on bge.

ok brad@.


# 1.38 10-Dec-2004 brad

more Broadcom ids taken from the Linux driver.


# 1.37 24-Nov-2004 brad

use ETHER_MAX_LEN


# 1.36 16-Nov-2004 brad

allow for the reception of VLAN sized frames.

From FreeBSD

ok deraadt@


# 1.35 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.34 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.33 28-Sep-2004 brad

Use ETHER_MAX_DIX_LEN/ETHER_MIN_LEN


# 1.32 23-Sep-2004 brad

don't need to set ifp->if_mtu or ifp->if_output in each driver,
{ether,atm,fddi}_ifattach already does this.

ok mcbride@ markus@ henning@


# 1.31 16-Sep-2004 mcbride

If we can't allocate new jumbo storage, try to copy the packet into a
new mbuf chain with m_devget() before recycling the jumbo storage.
Frome if_sk.c

ok deraadt@


Revision tags: OPENBSD_3_6_BASE
# 1.30 19-Aug-2004 mcbride

Don't complain about lack of available jumbo buffers when processing incoming
packets unless we're debugging.


# 1.29 17-Aug-2004 deraadt

printf repair


# 1.28 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.27 29-May-2004 naddy

- Properly support multicast reception.
- Use ether_crc32_le() instead of equivalent hand-rolled CRC routine.

ok mcbride@


# 1.26 25-May-2004 mcbride

Use the correct value when checking whether a loop timed out.

ok krw@


# 1.25 12-Apr-2004 brad

Enable the memory arbiter before turning off the PXE restart. This
prevents NMI's from happening when resetting the chip on some
hardware.

From: FreeBSD

ok deraadt@


# 1.24 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.23 27-Feb-2004 niklas

Add support for BCM5788


# 1.22 26-Oct-2003 jmc

typos from Jared Yanovich;


# 1.21 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.20 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.19 11-Feb-2003 mickey

be consistant on Hz vs hz


# 1.18 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.17 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


# 1.16 26-Nov-2002 nate

use pci_matchbyid


# 1.15 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_2_BASE UBC_SYNC_B
# 1.14 23-Sep-2002 nate

Don't print extra junk to the console


# 1.13 14-Jun-2002 todd

spelling; from Brian Poole <raj@cerias.purdue.edu>


# 1.12 29-Apr-2002 nate

re-do the way the bus_dma is done for transmit.
Loop over the dm_segs instead of looping over the mbuf chain.
This fixes some problems seen where IP fragments can contain bogus data


# 1.11 26-Apr-2002 nate

be more terse with output


# 1.10 26-Apr-2002 nate

Only call bpf_mtap if we have bpf in the kernel


Revision tags: OPENBSD_3_1_BASE
# 1.9 08-Apr-2002 nate

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


# 1.8 14-Mar-2002 millert

First round of __P removal in sys


# 1.7 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.6 15-Feb-2002 nordin

Don't cast nonexistent return value from splx to (void). ok art@


# 1.5 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


# 1.4 24-Dec-2001 mickey

fix // comment, kill some dangling spaces


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

branches: 1.3.4; 1.3.6;
Make bge use busdma


# 1.2 09-Oct-2001 nate

Don't enable BGE_CHECKSUM yet, since it doesn't work.
It shouldn't have been enabled in the first place.


# 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