Commit Graph

450 Commits

Author SHA1 Message Date
Pyun YongHyeon
333704a37f style. 2010-07-13 19:39:51 +00:00
Pyun YongHyeon
797ab05ef6 Make bge_stop_fw() static.
While I'm here use ANSI function definitions.
2010-07-13 19:33:46 +00:00
Pyun YongHyeon
864104fe59 Zero entire status block and add missing bus_dmamap_sync(9). 2010-07-06 18:17:31 +00:00
Pyun YongHyeon
55a24a0597 It seems read DMA mode register requires both IPv4 TSO and IPv6 TSO
configuration to get IPv4 TSO work on BCM57780. While I'm here
apply the same fix to BCM5785 which shares similar hardware feature
of BCM57780. This change makes TSO work on BCM57780.

Tested by:	Tong Liu <nemoliu <> gmail dot com>
2010-07-06 02:07:59 +00:00
Pyun YongHyeon
77982948d1 Remove unused macros.
Reviewed by:	bde
2010-06-08 17:28:28 +00:00
Pyun YongHyeon
e0b7b101ce Fix a bug introduced in r199011. When bge(4) reuses loaded RX
buffers it should also reinitialize RX descriptors otherwise some
stale data could be passed to controller. This could end up with
mbuf double free or unexpected NULL pointer dereference in upper
stack. To fix the issue, save loaded buffer's length and
reinitialize RX descriptors with the saved value whenever bge(4)
reuses the loaded RX buffers.
While I'm here, increase the number of RX buffers to 512 from 256.
This simplifies RX buffer handling as well as giving more RX
buffers. Controller supports just fixed number of RX buffers
(i.e. 512) and bge(4) used to rely on hope that our CPU is fast
enough to keep up with the controller. With this change, bge(4)
will use 1MB for RX buffers but I don't think it would cause
problems in these days.

Reported by:	marcel
Tested by:	marcel
2010-06-05 23:29:24 +00:00
Marius Strobl
2d857b9b19 For the on-board interfaces found in Fujitsu SPARC64 machines obtain the
MAC address via OFW as well.
2010-04-26 18:56:06 +00:00
Pyun YongHyeon
d2b6e9a0bc Use pci_get_max_read_req() and pci_set_max_read_req() to set maximim
read request size.
2010-03-25 17:17:35 +00:00
Pyun YongHyeon
f584dfd113 Revert r205090.
It's hard to know when the mail box register write will get flushed to
the hardware and it may take longer.

Pointed out by:	scottl
2010-03-16 17:45:16 +00:00
Pyun YongHyeon
5e243d9a49 Reorder interrupt handler a bit such that producer/consumer
index of status block is read first before acknowledging the
interrupts. Otherwise bge(4) may get stale status block as
acknowledging an interrupt may yield another status block update.

Reviewed by:	marius
2010-03-12 18:18:04 +00:00
Pyun YongHyeon
fa8b4d63db Fix typo in r204978.
Pointed out by:	marius
2010-03-10 21:37:19 +00:00
Pyun YongHyeon
d896b3fe8d Fix typo in r204975.
Pointed out by:	marius
2010-03-10 20:55:55 +00:00
Pyun YongHyeon
cbb2b2fe3e Set maximum read byte count to 2048 for PCI-X BCM5703/5704 devices.
Also disable relaxed ordering as recommended by data sheet for
PCI-X devices. For PCI-X BCM5704, set maximum outstanding split
transactions to 0 as indicated by data sheet.
For BCM5703 in PCI-X mode, DMA read watermark should be less than
or equal to maximum read byte count configuration. Enforce this
limitation in DMA read watermark configuration.
2010-03-10 20:54:08 +00:00
Pyun YongHyeon
fbc374af79 Enable hardware fixes for BCM5704 B0 as recommended by data sheet. 2010-03-10 20:22:57 +00:00
Pyun YongHyeon
be95548d86 Disable TSO on BCM5755M controller until I understand better for
the issue. I still have no idea why TSO does not work on this
controller. davidch@ also confirmed there is no known TSO related
issues for this controller.
2010-02-26 22:29:42 +00:00
Pyun YongHyeon
5b355c4fb1 Remove Tx mbuf parsing code for VLAN in TSO path. Controller does
not support TSO over VLAN if VLAN hardware tagging is disabled so
there is no need to check VLAN here.
While I'm here make sure to pullup IP/TCP headers in the first
buffer.
2010-02-22 21:03:15 +00:00
Pyun YongHyeon
04bde8528b Add TSO support on VLAN. Controller requires VLAN hardware tagging
to make TSO work on VLAN. So if VLAN hardware tagging is disabled
explicitly clear TSO on VLAN. While I'm here remove duplicated
VLAN_CAPABILITIES call.
2010-02-20 23:21:06 +00:00
Pyun YongHyeon
4150ce6f17 Move device specific flag configuration to attach routine.
The softc obtained in device probe wouldn't be the same one used in
device attach. Drivers should not assume any values stored in softc
structure in probe routine will be available for its attach routine.
2010-02-09 19:12:06 +00:00
Pyun YongHyeon
9a6e301de2 PCI express device status register has W1C feature. Writing 0 has
no effect. Make sure to clear error bits by writing 1. [1]
While I'm here use predefined value instead of hardcodig magic
vlaue.

Submitted by:	msaitoh at NetBSD [1]
2010-02-01 20:58:45 +00:00
Pyun YongHyeon
d67eba2f3f Use new handshake command for BCM5750 or new controllers. 2010-01-22 18:46:37 +00:00
Pyun YongHyeon
899d684659 Fix a long standing ASF heartbeat sending bug. The initial
implementation of heartbeat interval was 2 but there was typo which
caused the heartbeat is sent approximately every 5 seconds. This
caused unintended controller reset by firmware because firmware
thought OS was crashed.

Submitted by:	Floris Bos < info <> je-eigen-domein dot nl >
Tested by:	Andrzej Tobola < ato <> iem dot pw dot edu dot pl >
2010-01-22 18:35:50 +00:00
Pyun YongHyeon
261f04d654 Don't free mbuf chains when bge(4) fails to collapse the mbuf
chains. This part of code is to enhance performance so failing the
collapsing should not free TX frames. Otherwise bge(4) will
unnecessarily drop frames which in turn can freeze the network
connection.

Reported by:	Igor Sysoev (is <> rambler-co dot ru)
Tested by:	Igor Sysoev (is <> rambler-co dot ru)
2010-01-15 17:55:18 +00:00
Pyun YongHyeon
ea3b412711 For controllers that has dual mode PHY(copper or fiber) interfaces
over GMII, make sure to enable GMII. With this change brgphy(4) is
used to handle the dual mode PHY. Since we still don't have a sane
way to pass PHY specific information to mii(4) layer special
handling is needed in brgphy(4) to determine which mode of PHY was
configured in parent interface.
This change make BCM5715S work.

Tested by:	olli
Obtained from:	OpenBSD
MFC after:	1 week
2010-01-14 19:08:43 +00:00
Xin LI
f7d1b2eb75 o Add PCI ID for BCM 5756.
o Don't enable BGE_FLAG_BER_BUG on both 5722 and 5756, and based
   on their PCI IDs rather than their chip IDs.

Reported by:	several PC-BSD users via kmoore
Reviewed by:	yongari, imp, jhb, davidch
Sponsored by:	iXsystems, Inc.
MFC after:	2 weeks
2010-01-13 22:39:39 +00:00
Pyun YongHyeon
4f4a16e152 Fix regression introduced in r198318. BCM5754/BCM5754M uses the
same ASIC ID of BCM5758 such that r198318 incorecctly enabled TSO
on BCM5754.BCM5754M controllers. BCM5754/BCM5754M needs a special
firmware to enable TSO and bge(4) does not support firmware based
TSO.

Reported by:	ed
Tested by:	ed
2010-01-03 21:49:24 +00:00
Pyun YongHyeon
beaa2ae169 Create sysctl node(dev.bge.%d.focred_collapse) instead of
hw.bge.forced_collapse. hw.bge.forced_collapse affects all bge(4)
controllers on system which may not desirable behavior of the
sysctl node. Also allow the sysctl node could be modified at any
time.

Reviewed by:	bde (initial version)
2009-12-08 17:54:23 +00:00
Pyun YongHyeon
9766cbd144 Partially revert r200228. For mini RCB case, bge(4) still have to
disable mini ring withtout regard to mini ring support.

Reported by:	marcel
Tested by:	marcel
2009-12-08 03:24:29 +00:00
Pyun YongHyeon
2a141b9412 Don't access jumbo frame related registers if controller lacks the
feature. These registers are reserved on controllers that have no
support for jumbo frame.
Only BCM5700 has mini ring so do not poke mini ring related
registers if controller is not BCM5700.

Reviewed by:	marius
2009-12-07 19:26:54 +00:00
Pyun YongHyeon
6fe124d275 Remove PHY isolate/power down code in bge_stop(). The isolation
handler in brgphy(4) does not exist and brgphy(4) just resets the
PHY and returns EINVAL as it has no isolation handler. I also agree
on Marius's opinion that stop handler of every NIC driver seems to
be the wrong place for implementing PHY isolate/power down.
If we need PHY isolate/power down it should be implemented in
brgphy(4) and users should administratively down the PHY.

Reviewed by:	marius
2009-12-07 19:18:23 +00:00
Pyun YongHyeon
d94f2b8506 Add workaround to overcome hardware limitation which allows only a
single outstanding DMA read operation. Most controllers targeted to
client with PCIe bus interface(e.g. BCM5761) may have this
limitation. All controllers for servers does not have this
limitation.
Collapsing mbuf chains to reduce number of memory reads before
transmitting was most effective way to workaround this. I got about
940Mbps from 850Mbps with mbuf collapsing on BCM5761. However it
takes a lot of CPU cycles to collapse mbuf chains so add tunable to
control the number of allowed TX buffers before collapsing. The
default value is 0 which effectively disables the forced collapsing.
For most cases 2 would yield best performance(about 930Mbps)
without much sacrificing CPU cycles.
Note the collapsing is only activated when the controller is on
PCIe bus and the frame does not need TSO operation. TSO does not
seem to suffer from the hardware limitation because the payload
size is much bigger than normal IP datagram.
Thanks to davidch@ who told me the limitation of client controllers
and actually gave possible workarounds to mitigate the limitation.

Reviewed by:	davidch, marius
2009-12-03 23:57:06 +00:00
Pyun YongHyeon
6a15578d8a Fix typo which inversed the logic which in turn disabled MSI.
Pointy hat to:  yongari
2009-11-25 17:51:14 +00:00
Pyun YongHyeon
7e6acdf12b Make sure one shot MSI is enabled.
Submitted by:	marius
2009-11-25 17:30:38 +00:00
Pyun YongHyeon
fd4d32feb2 BGE_FLAG_40BIT_BUG should be set before creating DMA tags.
Pointy hat to:  yongari
2009-11-24 17:46:58 +00:00
Pyun YongHyeon
30f57f615b Reduce status block size DMAed by controller. bge(4) uses single
Tx/Rx/Rx return ring such that large part of status block was not
used at all. All bge(4) controllers except BCM5700 AX/BX has a
feature to control the size of status block. So use minimum status
block size allowed in controller. This reduces number of DMAed
status block size to 32 bytes from 80 bytes.
2009-11-22 21:45:55 +00:00
Pyun YongHyeon
2e1d4df419 Add missing function prototype in r199671. 2009-11-22 21:20:26 +00:00
Pyun YongHyeon
ca3f1187f1 Implement TSO for BCM5755 or newer controllers. Some controllers
seem to require a special firmware to use TSO. But the firmware is
not available to FreeBSD and Linux claims that the TSO performed by
the firmware is slower than hardware based TSO. Moreover the
firmware based TSO has one known bug which can't handle TSO if
ethernet header + IP/TCP header is greater than 80 bytes. The
workaround for the TSO bug exist but it seems it's too expensive
than not using TSO at all. Some hardwares also have the TSO bug so
limit the TSO to the controllers that are not affected TSO issues
(e.g. 5755 or higher).
While I'm here set VLAN tag bit to all descriptors that belengs to
a frame instead of the first descriptor of a frame. The datasheet
is not clear how to handle VLAN tag bit but it worked either way in
my testing. This makes it simplify TSO configuration a little bit.

Big thanks to davidch@ who sent me detailed TSO information.
Without this I was not able to implement it.

Tested by:	current
2009-11-22 21:16:30 +00:00
Pyun YongHyeon
f681b29a6d Fix two long standing bugs on bge(4). Most pre BCM5755 controllers
have a DMA bug when buffer address crosses a multiple of the 4GB
boundary(e.g. 4GB, 8GB, 12GB etc). Limit DMA address to be within
4GB address for these controllers. The second DMA bug limits DMA
address to be within 40bit address space. This bug applies to
BCM5714 and BCM5715 and 5708(bce(4) controller). This is not
actually a MAC controller bug but an issue with the embedded PCIe
to PCI-X bridge in the device. So for BCM5714/BCM5715 controllers
also limit the DMA address to be within 40bit address space.
Special thanks to davidch@ who gave me detailed errata information.
I think this change will fix long standing bge(4) instability
issues on systems with more than 4GB memory.

Reviewed by:	davidch
2009-11-22 20:50:27 +00:00
Pyun YongHyeon
dfe0df9a76 For MSI case, interrupt is not shared and we don't need to force
PCI flush to get correct status block update. Add an optimized
interrupt handler that is activated for MSI case. Actual interrupt
handling is done by taskqueue such that the handler does not
require driver lock for Rx path. The MSI capable bge(4) controllers
automatically disables further interrupt once it enters interrupt
state so we don't need PIO access to disable interrupt in interrupt
handler.
2009-11-22 20:31:40 +00:00
Pyun YongHyeon
b9c05fa593 Cache Rx producer/Tx consumer index as soon as we know status block
update and then clear status block. Previously it used to access
these index without synchronization which may cause problems when
bounce buffers are used. Also add missing bus_dmamap_sync(9) in
polling handler. Since we now update status block in driver, adjust
bus_dmamap_sync(9) for status block.
2009-11-22 20:02:13 +00:00
Pyun YongHyeon
167fdb62e3 Rearrange bge_start_locked to see we can send more frames by
checking IFF_DRV_RUNNING and IFF_DRV_OACTIVE flags. Also if we
have less than 16 free send BDs set IFF_DRV_OACTIVE and try it
later. Previously bge(4) used to reserve 16 free send BDs after
loading dma maps but hardware just need one reserved send BD. If
prouder index has the same value of consumer index it means the Tx
queue is empty.
While I'm here check IFQ_DRV_IS_EMPTY first to save one lock
operation.
2009-11-22 19:44:11 +00:00
Pyun YongHyeon
d77e9fa7be Controller does not write Rx descriptors, remove BUS_DMASYNC_PREREAD. 2009-11-22 19:17:32 +00:00
Pyun YongHyeon
0aaf10578c Use capability pointer to access PCIe registers rather than
directly access them at fixed address. While I'm here don't touch
other bits of PCIe device control register except max payload size.

Reviewed by:	marius
2009-11-22 19:11:34 +00:00
Pyun YongHyeon
d648358b0b Due to newly added PCIe capabilities fallback code for finding the
PCIe capability did not work right on recent controllers. Remove
FreeBSD 6.x support code.

Reviewed by:	marius
2009-11-22 18:47:56 +00:00
Pyun YongHyeon
1b90d0bd3e Fix typo introduced in r199011.
Pointed out by:	marius
2009-11-22 18:34:15 +00:00
Pyun YongHyeon
1715ec0d32 Remove extra white space. 2009-11-22 18:30:19 +00:00
Pyun YongHyeon
5c1da2fac0 Controller does not update Tx descriptors(send BDs) after sending
frames so remove unnecessary BUS_DMASYNC_PREREAD and
BUS_DMASYNC_POSTREAD of bus_dmamap_sync(9).
2009-11-10 20:29:20 +00:00
Pyun YongHyeon
e6bf277eff Zero out Tx/Rx descriptors before using them. Also add missing
bus_dmamap_sync(9) after Tx descriptor initialization.
2009-11-09 23:09:18 +00:00
Pyun YongHyeon
aa94f33338 Add missing bus_dmamap_sync(9) before issuing kick command. 2009-11-09 22:58:30 +00:00
Pyun YongHyeon
4d3a629c65 Correct disabling checksum offloading for BCM5700 B0. 2009-11-09 00:16:50 +00:00
Pyun YongHyeon
f5a034f95a Partially revert r199035.
Revision 1.158 says only lower ten bits of
BGE_RXLP_LOCSTAT_IFIN_DROPS register is valid. For BCM5761 case it
seems the controller maintains 16bits value for the register.
However 16bits are still too small to count all dropped packets
happened in a second. To get a correct counter we have to read the
register in bge_rxeof() which would be too expensive.

Pointed out by:	bde
2009-11-08 19:59:54 +00:00
Pyun YongHyeon
e238d4ead1 Count number of inbound packets which were chosen to be discarded
as input errors. Also count out of receive BDs as input errors.
2009-11-08 01:30:35 +00:00
Pyun YongHyeon
25dc84f22f Don't count input errors twice, we always read input errors from
MAC in bge_tick. Previously it used to show more number of input
errors. I noticed actual input errors were less than 8% even for
64 bytes UDP frames generated by netperf.
Since we always access BGE_RXLP_LOCSTAT_IFIN_DROPS register in
bge_tick, remove useless code protected by #ifdef notyet.
2009-11-08 01:13:38 +00:00
Pyun YongHyeon
61ccb9da43 Tell upper layer we support long frames. ether_ifattach()
initializes it to ETHER_HDR_LEN so we have to override it after
calling ether_ifattch().
While I'm here remove setting if_mtu value, it's initialized in
ether_ifattach().
2009-11-07 20:37:38 +00:00
Pyun YongHyeon
03e78bd096 Fix I mssied in r199011. Rx ring index also should be updated.
If we fill Rx ring full instead of half we can simplify this logic
but this requires more experimentation.
2009-11-07 02:10:59 +00:00
Pyun YongHyeon
943787f3a7 Reimplement Rx buffer allocation to handle dma map load failure.
Introduce two spare dma maps for standard buffer and jumbo buffer
respectively. If loading a dma map failed reuse previously loaded
dma map. This should fix unloaded dma map is used in case of dma
map load failure. Also don't blindly unload dma map and defer
dma map sync and unloading operation until we know dma map for new
buffer is successfully loaded. This change saves unnecessary dma
load/unload operation. Previously bge(4) tried to reuse mbuf
with unloaded dma map which is really bad thing in bus_dma(9)
perspective.
While I'm here update if_iqdrops if we can't allocate Rx buffers.
2009-11-07 01:01:33 +00:00
Pyun YongHyeon
c215fd771d Do bus_dmamap_sync call only if frame size is greater than
standard buffer size. If controller is not capable of handling
jumbo frame, interface MTU couldn't be larger than standard MTU
which in turn the received should be fit in standard buffer. This
fixes bus_dmamap_sync call for jumbo ring is called even if
interface is configured to use standard MTU.
Also if total frame size could be fit into standard buffer don't
use jumbo buffers.
2009-11-06 23:49:20 +00:00
Pyun YongHyeon
a669a81f0b bge(4) already switched to use UMA backed page allocator and local
memory allocator for jumbo frame was removed long time ago. Remove
no more used macros.
2009-11-06 22:37:29 +00:00
Pyun YongHyeon
c3bbfed430 Correct MSI mode register bits. 2009-11-06 01:11:59 +00:00
Pyun YongHyeon
3ee5d7da8e Make bge_newbuf_std()/bge_newbuf_jumbo() returns actual error code
for buffer allocation. If driver know we are out of Rx buffers let
controller stop. This should fix panic when interface is run even
if it had no configured Rx buffers.
2009-11-04 21:06:54 +00:00
Pyun YongHyeon
0ac56796f7 Remove common DMA tag used for TX/RX mbufs and create Tx DMA tag
and Rx DMA tag separately. Previously it used a common mbuf DMA tag
for both Tx and Rx path but Rx buffer(standard ring case) should
have a single DMA segment and maximum buffer size of the segment
should be less than or equal to MCLBYTES. This change also make it
possible to add TSO with minor changes.
2009-11-04 20:57:52 +00:00
Pyun YongHyeon
a23634a177 Covert bge_newbuf_std to use bus_dmamap_load_mbuf_sg(9). Note,
bge_newbuf_std still has a bug for handling dma map load failure
under high network load. Just reusing mbuf is not enough as driver
already unloaded the dma map of the mbuf. Graceful recovery needs
more work.
Ideally we can just update dma address part of a Rx descriptor
because the controller never overwrite the Rx descriptor. This
requires some Rx initialization code changes and it would be done
later after fixing other incorrect bus_dma(9) usages.
2009-11-04 20:40:38 +00:00
Pyun YongHyeon
a41504a9b1 Use correct dma tag for jumbo buffer. 2009-11-04 20:19:21 +00:00
Stanislav Sedov
15eda8010b - On entrance to the rx_eof sync RX rings maps with POSTWRITE flag
instead of POSTREAD: the hardware do not touch this memory (CPU
  updates it).  It is already synchronized as PREWRITE after the
  processing is done.

- Synchronize RX return ring memory in rx_eof.  This is needed
  as the deviced updates this memory when receives packets.

- Decouple the synchronization of BGE status block in the interrupt
  service routine: perfrom PREREAD synchronization only all accesses
  to this block are finished.  This seems to be more natural.

Reviewed by:	yongari, marius
MFC after:	2 weeks
2009-10-21 11:50:18 +00:00
Bjoern A. Zeeb
44b636910b Immediately after clearing a pending callout that didn't make it due
to the lock we hold, disable interrupts, and announce to the firmware
that we are shutting down. Especially do this before disabling blocks.

This makes some types of machines with asf enabled no longer hang upon
boot, when we start configuring the interface.

PR:			i386/96382, kern/100410, kern/122252, kern/116328
Reported by:		erwin
Hardware provided by:	TDC A/S
Reviewed by:		stas
Tested by:		stas
2009-10-13 20:22:12 +00:00
Stanislav Sedov
3889907fb2 - Give a name to the host coalescing bug fix WDMA mode register bit instead
of using hardcoded value in the code.
Obtained from:	OpenBSD
2009-10-07 14:29:48 +00:00
Stanislav Sedov
a57795536a - Add support for new BGE chips (5761, 5784 and 57780). These chips uses new
BGE_PCI_PRODID_ASICREV register to store the chip identifier and its revision.
- Add new grouping macro for 7575+ chips (BGE_IS_5755_PLUS).
- Add IDs for Fujitsu-branded Broadcom adapters.

PR:             kern/127587
Tested by:      Thomas Quinot <thomas@quinot.org> (BCM7561 A0)
MFC after:	2 weeks
Obtained from:  OpenBSD
2009-10-07 13:12:43 +00:00
Stanislav Sedov
7f21e273a8 - Do not try to reevaluate 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 operation has not been
  performed.  This fixes the bug when bge(4) drops packets
  under high load.

Discussed with:	yongari, marius
Approved by:	re (kib)
MFC after:	1 week
2009-08-18 21:07:39 +00:00
Robert Watson
eb956cd041 Use if_maddr_rlock()/if_maddr_runlock() rather than IF_ADDR_LOCK()/
IF_ADDR_UNLOCK() across network device drivers when accessing the
per-interface multicast address list, if_multiaddrs.  This will
allow us to change the locking strategy without affecting our driver
programming interface or binary interface.

For two wireless drivers, remove unnecessary locking, since they
don't actually access the multicast address list.

Approved by:	re (kib)
MFC after:	6 weeks
2009-06-26 11:45:06 +00:00
Attilio Rao
8cf7d13d7a Fix return values appropriately.
Tested by:	zec
2009-05-30 17:56:19 +00:00
Attilio Rao
d4da719cf6 s/rk_npkts/rx_npkts
Reported by:	zec
2009-05-30 17:25:14 +00:00
Attilio Rao
1abcdbd127 When user_frac in the polling subsystem is low it is going to busy the
CPU for too long period than necessary.  Additively, interfaces are kept
polled (in the tick) even if no more packets are available.
In order to avoid such situations a new generic mechanism can be
implemented in proactive way, keeping track of the time spent on any
packet and fragmenting the time for any tick, stopping the processing
as soon as possible.

In order to implement such mechanism, the polling handler needs to
change, returning the number of packets processed.
While the intended logic is not part of this patch, the polling KPI is
broken by this commit, adding an int return value and the new flag
IFCAP_POLLING_NOCOUNT (which will signal that the return value is
meaningless for the installed handler and checking should be skipped).

Bump __FreeBSD_version in order to signal such situation.

Reviewed by:	emaste
Sponsored by:	Sandvine Incorporated
2009-05-30 15:14:44 +00:00
Xin LI
9fe569d8f9 Some comment/space changes (FALLTHRU -> FALLTHROUGH, space after while). 2009-05-14 22:36:56 +00:00
Xin LI
25e13e6895 Try to workaround a race where bge_stop() may sneak in when bge_rxeof()
drops and re-grabs the softc mutex in the middle, resulting in kernel
trap 12.  This may happen when a lot of traffic is being hammered on
one bge(4) interface while the system is shutting down.

Reported by:	Alexander Sack <pisymbol gmail com>
PR:		kern/134548
MFC After:	2 weeks
2009-05-14 22:33:37 +00:00
Marius Strobl
c9ffd9f058 - Ensure that INTx isn't disabled, as these chips apparently have a
quirk requiring it to be enabled even when using MSI. This makes
  the latter work again after r189285.
- Remove a comment which no longer applies since r190194.
2009-03-23 14:36:50 +00:00
Marius Strobl
4f09c4c7e5 - In bge_ifmedia_upd_locked() take advantrage of LIST_FOREACH().
- If boot verbose, print asicrev, chiprev and bus type on attach.
- For PCI Express devices:
  1) Adjust max read request size to 4Kbytes
  2) Turn on FIFO_LONG_BURST in RDMA during bge_blockinit()
  Though 1) does not seem to have much to do with the poor TX performance
  observed on PCI Express bge(4), 2) does fix the problem. [1]
- Nuke the RX CPU self-diag, which prevents working cards from working
  (Linux tg3 does not have this diag neither does OpenBSD's bge(4)).
  The increasing of the firmware handshaking timeout to 20000 retries
  done as part of the original commit isn't merged as way already have a
  way higher BGE_TIMEOUT of 100000.

PR:		119361 [1]
Obtained from:	tg3 via DragonflyBSD [1], DragonflyBSD
2009-03-21 00:23:07 +00:00
Marius Strobl
4012d104cd Don't reset the PHY probe retry counter within the loop so
it will eventually terminate as intended.

Submitted by:	Helen Zhang
2009-02-10 21:54:23 +00:00
Warner Losh
b6c974e8da device_shutdown returns an int. 2009-02-05 18:43:13 +00:00
Marius Strobl
90447aad0a - Limit BCM5701 B5 to 32-bit mode as a workaround for a bug which
causes data corruption in combination with certain bridges.
  Information about this problem was kindly provided by davidch. [1]
- As BGE_FLAG_PCIX is meant to indicate that the controller is in
  PCI-X mode, revert to the pre __FreeBSD_version 602101 method of
  reading the bus mode register rather than checking the mere
  existence of a PCI-X capability, which is also there when the
  NIC f.e. is put into a 32-bit slot causing it not to be in PCI-X
  mode. Setting BGE_FLAG_PCIX inappropriately could cause the NIC
  to be tuned incorrectly.

PR:		128833 [1]
Reviewed by:	jhb
MFC after:	3 days
2008-12-09 21:34:22 +00:00
Marius Strobl
a8376f70e7 Do as the Linux tg3 driver does and enable MSI support also
for the BCM5714 revision A0 when in a multi-port configuration
and unconditionally for the remainder of the class of BCM575X
and beyond chips.
This was prodded by mav and is based on a suggestion and a
patch submitted by jhb.

Reviewed by:	jhb
MFC after:	2 months
2008-10-27 22:10:01 +00:00
Marius Strobl
c00cf72245 Use bus_{read,write}_4(9) instead of bus_space_{read,write}_4(9)
in order to get rid of the bus space handle and tag in the softc.

MFC after:	1 month
2008-10-14 20:28:42 +00:00
Marius Strobl
852c67f994 - Don't read the identifier string from the VPD if there's no chip
containing an Ethernet address fitted as this is yet another thing
  that fails in that case in order to avoid the one second delay
  until pci_read_vpd_reg() times out.
- Const'ify the bge_devs array.
2008-09-22 20:55:19 +00:00
Oleg Bulyzhin
82b67c0132 bge_tick(): do not touch PHY if link is up. This should solve problem with
extra input errors for some BCM57XX chips.

PR:		kern/122295
2008-09-08 18:10:15 +00:00
Marius Strobl
5fea260f19 Improve the integration of BCM5906[M] support:
- Rename BGE_FLAG_EEPROM to BGE_FLAG_EADDR to underline it's absence means
  "there's no chip containing an Ethernet address fitted to the BGE chip
  so we have to get it from the firmware instead" rather than "there's no
  EEPROM, but maybe NVRAM or something else".
- Don't treat BCM5906[M] generally like chips w/o BGE_FLAG_EADDR set, just
  in the two cases really necessary. This gets us line with the original
  patch for DragonFlyBSD.
- For sparc64 restore the intended behavior of obtaining the Ethernet
  address from the firmware in case BGE_FLAG_EADDR is not set, even for
  BCM5906[M].
- Fix some style(9) bugs introduced with rev. 1.208 of if_bge.c

Approved by:		jhb
Additional testing by:	Thomas Nystroem (BCM5906)
2008-05-14 21:00:27 +00:00
Bjoern A. Zeeb
4f0794ff96 Use a better approach to force the interrupt which should work for
all cards/modes.
In addition to the intr forcing added with rev. 1.205 adopt the other
places to use the same logic.

We need to exclude a few chips/revisions (5700, 5788) from using the
enhanced version and fall back to the old way as that is the only
method they support.

Tested by:	phk
Suggested by:	davidch, Broadcom (thanks a lot for the help!)
MFC after:	16 days
2008-05-05 18:42:17 +00:00
Bjoern A. Zeeb
63ccfe30a1 Use the correct bit when trying to force an interrupt through the HCC reg.
It's not a problem as this is a #ifdef notyet.
2008-05-01 13:10:03 +00:00
John Baldwin
38cc658ff6 Add support for the BCM5906[M] adapters. These adapters only support
10/100 operation and place the mailbox registers at a different offset.
They also do not have an EEPROM, so the MAC address must be read from
NVRAM instead.

MFC after:	1 month
PR:		kern/118975
Submitted by:	benjsc, Thomas Nyström  thn at saeab dot se
Submitted by:	sephe (original patch for DragonflyBSD)
2008-04-29 19:47:13 +00:00
Marius Strobl
44f8f2fc05 Remove some remnant alpha hacks.
Approved by:	PCI-maintainers (imp, jhb)
2008-04-26 14:13:48 +00:00
Marius Strobl
4eee14cb27 - Use more appropriate maxsize, nsegments and maxsegsize parameters
when creating the parent bus DMA tag. While at it correct the style
  and a nearby comment.
- Take advantage of m_collapse(9) for performance reasons.

MFC after:	2 weeks
2008-04-26 10:54:17 +00:00
Bjoern A. Zeeb
902827f6f3 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 and thus could not transmit.

The only way out of this was an incoming packet generating an rx interrupt
and making us call into bge_link_upd.

Up to rev. 1.101, in bge_start_locked, we only returned instantly
if there was 'no link AND nothing queued for tx'. So with a packet queued
for tx, we hit the register scrubbing at the end of bge_start_locked
and were out fine. We simply lost a packet or two but got the interrupts
need to get into UP state.
With rev. 1.102 this was turned into 'if there is no link OR there is
nothing to send' (correct behaviour) and as long as there is no link
we never hit the register scrubbing and consequently never got the link UP.

What we do now is force an interrupt at the end of bge_ifmedia_upd_locked
so we will call bge_link_upd, clear the link state attention and get
further interrupts.
This helps to get the iface UP on an idle network or at least to get
it UP faster not depending on an rx intr anymore.
In case you could not get a DHCP lease or it took very long,
it was because of this.

It is unknown which chips are affected by this. ASIC rev. 0x2003 was the
most popular trouble candidate.
At least the fiber cards should have been working fine.

Which register to scrub is currently under discussion. The comitted
solution was tested and found to work for a lot of setups. It might
not help with MSI.
The reason why we end up in such a situation is entirely unknown.

PR:		kern/111804
Tested by:	phk, scottl at Y!
MFC after:	14 days
2008-04-08 11:51:17 +00:00
John Baldwin
4fcf220b00 Don't enable the workaround for the jitter bug on the 5722.
Obtained from:	Linux tg3 driver
2008-03-11 15:05:54 +00:00
John Baldwin
8c9056b50b Style tweak to the 5722 chipid to match the rest of this file. 2008-03-06 21:48:34 +00:00
John Baldwin
bcc20328f5 Flesh out support for the BCM5722 by recognizing the phy on the 5722 and
the specific ASIC revision.

MFC after:	1 week
Obtained from:	OpenBSD (mii/phy bits)
2008-03-06 21:42:48 +00:00
Jung-uk Kim
86543395c1 Add a flag for Ethernet@WireSpeed capability and correct chip revisions.
The idea was taken from OpenBSD and cross-referenced with Linux driver.
2008-01-18 22:09:50 +00:00
Jung-uk Kim
e4be3198af Fix mbuf pool watermark configuration (mismerged from OpenBSD in 1.132).
Submitted by:	sephe
MFC after:	3 days
2008-01-18 20:33:21 +00:00
Remko Lodder
effef9789a Add support for the BMC5722.
Reported by:		Chris Shenton <chris at shenton dot org> on current@
Approved by:		imp (mentor)
2007-12-25 19:51:18 +00:00
Jung-uk Kim
d949071d71 Do not report MAC, TX, and RX stats via sysctl(8) with BCM5705+.
The register layout is little different from memory-mapped stats
in the previous generation chips.  In fact, it is bad because
registers in this range are cleared after reading them.

Reviewed by:	scottl
MFC after:	3 days
2007-11-16 16:39:27 +00:00
Marius Strobl
55aaf894e8 Make the PCI code aware of PCI domains (aka PCI segments) so we can
support machines having multiple independently numbered PCI domains
and don't support reenumeration without ambiguity amongst the
devices as seen by the OS and represented by PCI location strings.
This includes introducing a function pci_find_dbsf(9) which works
like pci_find_bsf(9) but additionally takes a domain number argument
and limiting pci_find_bsf(9) to only search devices in domain 0 (the
only domain in single-domain systems). Bge(4) and ofw_pcibus(4) are
changed to use pci_find_dbsf(9) instead of pci_find_bsf(9) in order
to no longer report false positives when searching for siblings and
dupe devices in the same domain respectively.
Along with this change the sole host-PCI bridge driver converted to
actually make use of PCI domain support is uninorth(4), the others
continue to use domain 0 only for now and need to be converted as
appropriate later on.
Note that this means that the format of the location strings as used
by pciconf(8) has been changed and that consumers of <sys/pciio.h>
potentially need to be recompiled.

Suggested by:	jhb
Reviewed by:	grehan, jhb, marcel
Approved by:	re (kensmith), jhb (PCI maintainer hat)
2007-09-30 11:05:18 +00:00
David Malone
041b706b2f Despite several examples in the kernel, the third argument of
sysctl_handle_int is not sizeof the int type you want to export.
The type must always be an int or an unsigned int.

Remove the instances where a sizeof(variable) is passed to stop
people accidently cut and pasting these examples.

In a few places this was sysctl_handle_int was being used on 64 bit
types, which would truncate the value to be exported.  In these
cases use sysctl_handle_quad to export them and change the format
to Q so that sysctl(1) can still print them.
2007-06-04 18:25:08 +00:00
Yaroslav Tykhiy
cb2eacc7dd Add on/off controls for VLAN_MTU and VLAN_HWTAGGING to bge(4). 2007-06-01 02:02:39 +00:00
Jung-uk Kim
e629eb82ba Remove an empty line. 2007-05-22 20:24:07 +00:00
Jung-uk Kim
0f89fde22c Remove BCM5704S specific tunable (hw.bge.fake_autoneg) and
auto-detect the condition.
2007-05-22 19:35:34 +00:00
Jung-uk Kim
186f842beb Rearrange DMA read/write control register settings based on document snippet
provided by davidch via glebius.

PR:		kern/96806
2007-05-22 19:22:58 +00:00
Jung-uk Kim
410c2bebd2 Remove stale alpha support code. 2007-05-22 19:11:39 +00:00
Jung-uk Kim
d5d2385773 Fix time out check in EEPROM read and move delays to give some settle time.
Submitted by:	mjacob
2007-05-22 18:51:05 +00:00
Jung-uk Kim
ca0ba1d16f Add delays in MI communication register R/W loops. 2007-05-22 18:16:23 +00:00
Jung-uk Kim
fe09b799f1 Reflect MFC of pci_find_extcap().
MFC after:	3 days
2007-05-01 19:18:12 +00:00
Marius Strobl
08013fd336 - Add support/quirks for the on-board BGEs found in Sun Blade 1500
Blade 2500, Fire V210 and probably some other sparc64 machines.
  These chips are typically not fitted with an EEPROM which means
  that we have to obtain the MAC address via OFW and that some chip
  tests will just always fail.
  These changes are based on the respective code found in OpenBSD
  with some additional info obtained from OpenSolaris and some style
  suggestions by jkim@. They also have the desired side-effect of
  respecting the 'local-mac-address?' system configuration variable
  for the affected BGEs.
- In bge_attach() factor out calling bge_release_resources() before
  going to the fail label into the fail label as well as replace a
  magic 6 with ETHER_ADDR_LEN.

Reviewed by:	yongari (before style changes), jkim
2007-04-30 21:55:27 +00:00
Jung-uk Kim
0a55a034ba Enable MSI support on RELENG_6.
MFC after:	3 days
2007-04-02 19:09:06 +00:00
Scott Long
06e83c7e86 Fix some OID names and minor style as per feedback from various people.
Also, apparently quad support is broken in the sysctl infrastructure, so don't
pretend that it works.

Submitted by: ru, bde
2007-03-13 00:41:55 +00:00
Scott Long
763757b2a4 Add MAC, RX, and TX stats reporting via sysctl. 2007-03-12 09:25:57 +00:00
Jung-uk Kim
0c4a1ef8dc Add more chipset revision IDs.
Obtained from:	OpenBSD
2007-03-09 01:30:23 +00:00
Jung-uk Kim
39153c5a23 Use correct bits to stop firmware when ASF mode is enabled. 2007-03-08 00:49:26 +00:00
Jung-uk Kim
0c8aa4eacd Fix more style(9) bugs.
- Remove some excessive parentheses around shift operators.
- Use macro instead of magic number where it is applicable.
- Change lower-case hexdecimals to upper cases to match wpaul's style.
- Revert some unnecessary line wraps and changes from the previous commit.

Pointed out by:	bde
2007-03-08 00:29:18 +00:00
Jung-uk Kim
6098821ce7 Fix style(9) and consistency. 2007-03-06 20:14:48 +00:00
Jung-uk Kim
4e35d186f1 Pollute bge(4) with #if's and #ifdef's to make MFC easier.
MFC after:	3 days
2007-03-06 19:15:16 +00:00
Paolo Pisati
ef544f6312 o break newbus api: add a new argument of type driver_filter_t to
bus_setup_intr()

o add an int return code to all fast handlers

o retire INTR_FAST/IH_FAST

For more info: http://docs.freebsd.org/cgi/getmsg.cgi?fetch=465712+0+current/freebsd-current

Reviewed by: many
Approved by: re@
2007-02-23 12:19:07 +00:00
Jung-uk Kim
464223f762 Use bge_writereg_ind() to do global reset as we did before 1.159 for certain
chipsets.  It was causing 'firmware handshake timed out' errors for some
chips.

Discussed with:	scottl
2007-02-14 19:44:15 +00:00
Jung-uk Kim
8117907083 Fix two typos in comments. 2007-02-14 19:01:33 +00:00
Jung-uk Kim
1ec4c3a889 Add BCM5701 A0/B0 CRC bug workaround. Magic values taken from Linux driver. 2007-02-12 23:58:52 +00:00
Jung-uk Kim
797b2220ae Fix style(9).
Pointed out by:	many
2007-02-12 23:33:05 +00:00
Jung-uk Kim
08bf8bb7c1 Add PHY DSP code for BCM5755M.
Obtained from:	OpenBSD
2007-02-12 22:51:25 +00:00
Jung-uk Kim
5ee49a3a58 - Fix BCM5754 support found in Dell PowerEdge SC440.
- Move some PHY bug detections from brgphy.c to if_bge.c.
- Do not penalize working PHYs.
- Re-arrange bge_flags roughly by their categories.
- Fix minor style(9) nits.

PR:		kern/107257
Obtained from:	OpenBSD
Tested by:	Mike Hibler <mike at flux dot utah dot edu>
2007-01-15 21:43:43 +00:00
John Polstra
0fb18ca82e Correct the comment describing the BGE_PCISTATE_PCI_BUSSPEED bit.
It had the sense of the bit reversed.
2007-01-11 01:43:24 +00:00
Bruce Evans
b64728e55e After rev.1.169, the "interrupt" coalescing parameters are not used in
bge_intr().  Some of them are used in bge_poll().  Simplify by only
initializing these for polling mode and not toggling them when switching
modes.  This also fixes missing synchronization with the coalescing
engine in the toggling.
2006-12-26 18:33:55 +00:00
John Polstra
bf6ef57a40 Re-enable MSI support for those chips on which it is believed to work
properly.
2006-12-22 02:59:58 +00:00
John Polstra
65b8185c34 Correct the BGE_CHIPID_BCM5750_B0 constant.
MFC after:	1 week
2006-12-22 01:10:36 +00:00
Bruce Evans
5b01e77c64 In bge_txeof(), cancel the watchdog timeout if all descriptors have
been handled instead of when at least one descriptor was just handled.
For bge, it is normal to get a txeof when only a small fraction of the
queued tx descriptors have been handled, so the bug broke the watchdog
in a usual case.
2006-12-20 12:03:21 +00:00
Bruce Evans
b848e03260 Avoid a race and a pessimization in bge_intr():
- moved the synchronizing bus read to after the bus write for the first
  interrupt ack so that it actually synchronizes everything necessary.

  We were acking not only the status update that triggered the interrupt
  together with any status updates that occurred before we got around
  to the bus write for the ack, but also any status updates that occur
  after we do the bus write but before the write reaches the device.
  The corresponding race for the second interrupt ack resulted in
  sometimes returning from the interrupt handler with acked but
  unserviced interrupt events.  Such events then remain unserviced
  until further events cause another interrupt or the watchdog times
  out.

  The race was often lost on my 5705, apparently since my 5705 has broken
  event coalescing which causes a status update for almost every packet,
  so another status update is quite likely to occur while the interrupt
  handler is running.  Watchdog timeouts weren't very noticeable,
  apparently because bge_txeof() has one of the usual bugs resetting the
  watchdog.

- don't disable device interrupts while bge_intr() is running.  Doing this
  just had the side effects of:
  - entering a device mode in which different coalescing parameters apply.
    Different coalescing parameters can be used to either inhibit or
    enhance the chance of getting another status update while in the
    interrupt handler.  This feature is useless with the current
    organization of the interrupt handler but might be useful with a
    taskqueue handler.
  - giving a race for ack+reenable/return.  This cannot be handled
    by simply rearranging the order of bus accesses like the race for
    ack+keepenable/entry.  It is necessary to sync the ack and then
    check for new events.
  - taking longer, especially with the extra code to avoid the race on
    ack+reenable/return.

Reviewed by:	ru, gleb, scottl
2006-12-20 11:14:45 +00:00
Jung-uk Kim
45ee6ab350 Partially back out rev. 1.148 and use new ETHER_BPF_MTAP() macro for VLAN.
Remaining changes are cosmetic.
2006-12-20 01:12:07 +00:00
Oleg Bulyzhin
5dda808582 - Add missing callout_drain() call.
- Synchronize bge_tick() with callout_reset/callout_stop() calls.
- Avoid using bge_tick() inside bge_link_upd(), use mii_pollstat() instead.

MFC after:	2 month
2006-12-19 08:57:46 +00:00
Jung-uk Kim
7c929cf95b - Remove stale VPD support and its comment and get device name from VPD API.
- Do not repeatedly read vendor/device IDs while probing.
- Remove redundant bzero(3) for softc.  device_get_softc(9) does it for free[1].

Reviewed by:	glebius
Suggested by:	glebius[1]
2006-12-18 16:40:04 +00:00
John Polstra
20aa3e4827 Disable bge MSI support for now. A couple of people warned me that there
are problems with it on several revisions of this chip.  I'll
re-enable it after I've sorted out which chip revisions work and which
don't.
2006-12-15 00:27:06 +00:00
John Polstra
724bd93939 Add MSI support to the bge driver. I tested this on a Dell SC1435
running an i386 kernel, and it worked fine.
2006-12-14 23:10:12 +00:00
Scott Long
9ba784dbaf Fix recent style problems and expand a comment.
Submitted by: Bruce Evans
2006-12-13 21:13:09 +00:00
Scott Long
5345bad07f Use the BGE_IS_* macros consistently. Also add a couple of missing
cases to the debug_info function.
2006-12-13 21:03:55 +00:00
Scott Long
088766f15c Remove a redundant write of the firmware reset magic number. It looks to
have been added erroneously, and it causes problems on some chips.  A larger
change is needed to do this write at a more appropriate place, but that
change requires reworking the ASF logic.  That will be worked on in the
future.

Submitted by: Bruce Evans
2006-12-13 20:51:51 +00:00
Jung-uk Kim
8634dfff05 Use one counter instead of four to make up TX collision stats as BCM5705+.
It reduces chance of errors from multiple counter wraps at the same time.
2006-12-13 17:28:51 +00:00
Scott Long
6f8718a3bf Fix support for certain 575x/578x chips. This consists of the following:
- Use the appropriate register writing method when reseting the chip
- Program the descriptor DMA engine correctly.
- More reliably detect certain chips and their features.

Also add some low-level debugging tools to help future work on this driver.

Submitted by: David Christenson (proof of concept changes)
Sponsored by: www.UIA.net
2006-12-12 05:11:12 +00:00
Jung-uk Kim
6b037352d0 - Correct collision counter for BCM5705+. This register is read/clear.
- Correct RX packet drop counter for BCM5705+.  This register is read/clear
and it wraps very quickly under heavy packet drops because only the lower
ten bits are valid according to the documentation.  However, it seems few
more bits are actually valid and the rest bits are always zeros[1].
Therefore, we don't mask them off here.  To get accurate packet drop count,
we need to check the register from bge_rxeof().  It is commented out for now,
not to penalize normal operation.  Actual performance impact should be
measured later.
- Correct integer casting from u_long to uint32_t.  Casting is not really
needed for all supported platforms but we better do this correctly[2].

Tested by:	bde[1]
Suggested by:	bde[2]
2006-12-11 18:00:34 +00:00
Jung-uk Kim
7ee00338c5 - Add BGE_FLAG_JUMBO flag which idicates jumbo frame capability. Some day we
may be able to support jumbo frames for BCM5714 and BCM5780.
- Rename BGE_IS_5705_OR_BEYOND() to BGE_IS_5705_PLUS() for consistency.
2006-12-04 22:12:21 +00:00
Jung-uk Kim
0dae9719c3 Use bge_flags to save chipset family and remove dead code while I am here. 2006-12-04 19:50:49 +00:00
Gleb Smirnoff
426742bf4d Fix my error in rev. 1.152
Submitted by:	oleg
2006-12-04 14:35:17 +00:00
Jung-uk Kim
d2d67b956c Fix white spaces. 2006-12-01 01:37:45 +00:00
Jung-uk Kim
7e6e2507b6 Simplify statistics updates, remove redundant register reads, and add
discarded RX packets to input error for BCM5705 or newer chipset as the others.
Unfortunately we cannot do the same for output errors because ifOutDiscards
equivalent register does not exist.  While I am here, replace misleading and
wrong BGE_RX_STATS/BGE_TX_STATS with BGE_MAC_STATS.  They were reversed but
worked accidently.
2006-12-01 01:08:52 +00:00
Gleb Smirnoff
b74e67fbfb - Instead of if_watchdog/if_timer interface use our own timer
that piggybacks on bge_tick() callout.
- Lock bge_tick() using callout_init_mtx().
2006-11-30 13:40:39 +00:00
Scott Long
706620f05b There is no reason to have a PAGE_SIZE alignment enforced on all DMA by the
parent tag.
2006-10-19 08:03:22 +00:00
Gleb Smirnoff
9a3fc40a26 Remove 3Com 985 deviceid that is really ti(4).
Submitted by:	erwin
2006-10-03 09:31:49 +00:00
Scott Long
f1a7e6d559 Allow the ASF feature to be disabled via a tunable. On one of my systems,
bringing up the bge interface results in a complete system freeze when
this feature is enabled.  Leave it enabled by default.
2006-09-23 18:55:49 +00:00
Jung-uk Kim
3e9b1bcabf Do not strip VLAN tag in promiscuous mode. 2006-09-18 22:18:21 +00:00
Jung-uk Kim
f9004b6d2d Simplify promiscuous mode check and make ALLMULTI independent from it. 2006-09-18 20:54:40 +00:00
Andre Oppermann
78ba57b9e1 Move ethernet VLAN tags from mtags to its own mbuf packet header field
m_pkthdr.ether_vlan.  The presence of the M_VLANTAG flag on the mbuf
signifies the presence and validity of its content.

Drivers that support hardware VLAN tag stripping fill in the received
VLAN tag (containing both vlan and priority information) into the
ether_vtag mbuf packet header field:

	m->m_pkthdr.ether_vtag = vlan_id;	/* ntohs()? */
	m->m_flags |= M_VLANTAG;

to mark the packet m with the specified VLAN tag.

On output the driver should check the mbuf for the M_VLANTAG flag to
see if a VLAN tag is present and valid:

	if (m->m_flags & M_VLANTAG) {
		... = m->m_pkthdr.ether_vtag;	/* htons()? */
		... pass tag to hardware ...
	}

VLAN tags are stored in host byte order.  Byte swapping may be necessary.

(Note: This driver conversion was mechanic and did not add or remove any
byte swapping in the drivers.)

Remove zone_mtag_vlan UMA zone and MTAG_VLAN definition.  No more tag
memory allocation have to be done.

Reviewed by:	thompsa, yar
Sponsored by:	TCP/IP Optimization Fundraise 2005
2006-09-17 13:33:30 +00:00
Gleb Smirnoff
6b9f5c941c - Consistently use if_printf() only in interface methods: if_start(),
if_watchdog, etc., or in functions used only in these methods.
  In all other functions in the driver use device_printf().
- Use __func__ instead of typing function name.

Submitted by:	Alex Lyashkov <umka sevcity.net>
2006-09-15 15:16:12 +00:00
Doug Ambrisko
8cb1383cb1 Add support to bge(4) to not break IPMI support when the driver attaches
to it.  Try to co-operate with the IPMI/ASF firmware accessing the PHY.
One we get link we don't mess with the PHY.  If we do then over time
the NIC will go off line.  It would be nice if we could tell if IPMI
was enabled on the chip but I can't figure out a reliable way to do
that.  The scheme I tried worked on a Dell PE850 but not on an HP machine.
So we assume any NIC that has ASF capability needs to deal with it.

The code was inspired by the support in Linux from kernel.org and Broadcom.
Broadcom did give me some info. but it is rather limited and is mostly
just what is in the Linux driver.  Thanks to the numerous people that
helped debug the many prior versions and that I didn't break other
bge(4) HW.

Reviewed by:	several people
Tested by:	even more
2006-09-09 03:36:57 +00:00
John-Mark Gurney
378f231e7d add a newbus method for obtaining the bus's bus_dma_tag_t... This is
required by arches like sparc64 (not yet implemented) and sun4v where there
are seperate IOMMU's for each PCI bus...  For all other arches, it will
end up returning NULL, which makes it a no-op...

Convert a few drivers (the ones we've been working w/ on sun4v) to the
new convection...  Eventually all drivers will need to replace the parent
tag of NULL, w/ bus_get_dma_tag(dev), though dev is usually different for
each driver, and will require hand inspection...

Reviewed by:	scottl (earlier version)
2006-09-03 00:27:42 +00:00
David Christensen
21c9e4077a /tmp/cvsleYf6y 2006-09-01 22:30:56 +00:00
Oleg Bulyzhin
67d5e043d2 Properly lock ifmedia callbacks. This should prevent concurrent access to PHY.
Following issues should be resolved:
- random watchdog timeouts (caused by concurrent phy access)
- some link state issues
- non working TX if media type was set explicitly

PR:		kern/98738
Approved by:	glebius (mentor)
MFC after:	2 weeks
2006-08-24 14:41:16 +00:00
Gleb Smirnoff
652ae483f8 Pack several boolean fields into single bge_flags field. 2006-08-23 11:32:54 +00:00
Gleb Smirnoff
6909dc43c5 bge_cksum_pad() can modify the mbuf, thus call it before bus_dmamap_load().
Submitted by:	yongari
2006-08-18 13:53:53 +00:00
Gleb Smirnoff
676ad2c9ef Rewrite bge_encap() so that it takes mbuf ** argument. In this case if
m_defrag(9) changes pointer we can show this to our caller.

Reviewed by:	yongari
2006-08-17 09:53:04 +00:00
Gleb Smirnoff
42787b76b6 Recognize the 5750 C2.
Obtained from:	OpenBSD (brad)
2006-08-07 12:51:50 +00:00
Gleb Smirnoff
d848592e1c Since 5714 family doesn't have Jumbo ring, we do not support
Jumbos on them, yet. The 5780 is equivalent to the 5714.

Submitted by:	brad@OpenBSD, davidch
2006-06-29 06:38:21 +00:00
Gleb Smirnoff
9e86676bd1 - Recognize more device IDs adding support for BCM5754, BCM5755,
BCM5787 based NICs.
- Recognize BCM5703 B0 ASIC.
- Rewrite the jumbo capability matching macro, so that chips known
  to work are listed there. [*]

[*] I'm still not sure about this. Probably more corrections
    will be done to this macro after discussion with davidch@
    and brad@OpenBSD.

Obtained from:	OpenBSD (brad)
2006-06-28 09:12:29 +00:00
Gleb Smirnoff
4c0da0ff4f Possess some work from OpenBSD, with some local additions.
- Add more device IDs, ASIC revisions and chip IDs.
- Rewrite a bit code that picks the description for device.
- Introduce several macros to shorten quirks for bugs and
  features.[*]
- Use some magic values, that OpenBSD has successfully
  possessed from Linux (Broadcom supplied) driver.
- Remove disabled code that tried to access VPD.

[*] The macro that matches Jumbo capable NICs is
    rewritten to preserve our current behavior. I
    need clarify whether our or theirs is correct.

PR:		68351 (and may be others)
Obtained from:	OpenBSD, brad@ mostly
2006-06-15 14:31:49 +00:00
Gleb Smirnoff
953c72a48f Whitespace. 2006-06-08 10:19:16 +00:00
Gleb Smirnoff
a6c2137176 u_intXX -> uintXX 2006-06-08 09:35:02 +00:00
Gleb Smirnoff
3f74909a86 - style(9) cleanup.
- Fix comments and printf()s about allocating jumbo buffers.
2006-06-07 21:03:20 +00:00
Poul-Henning Kamp
c40da00ca3 Since DELAY() was moved, most <machine/clock.h> #includes have been
unnecessary.
2006-05-16 14:37:58 +00:00
Matt Jacob
fe401a7a9a If one removes the option from conf/options, one should
remove the include of the derived file opt_bge.h as well.
2006-04-25 17:54:42 +00:00
Michael Reifenberger
c4529f4161 make BGE_FAKE_AUTONEG a tunable.
This allows one to change the behavior of the driver pre-boot.

NOTE: This patch was made for DragonFly BSD by Sepherosa Ziehau.

PR:		kern/94833
Submitted by:	Devon H. O'Dell
Obtained from:	DragonFly
MFC after:	1 month
2006-04-25 15:56:52 +00:00
Scott Long
f30cbfc63b Fix the interrupt handler to do the mandatory PCI flush before looking at
DMA memory.  The could contribute towards missed link state changes under
heavy bus load.
2006-04-15 08:13:06 +00:00
Pawel Jakub Dawidek
4a531e8dae Correct an obvious typo.
MFC after:	1 week
2006-04-12 12:12:44 +00:00
Gleb Smirnoff
a9620ec4be Remove dead code.
Submitted by:	oleg
2006-03-17 09:17:36 +00:00
Oleg Bulyzhin
1493e8838e 1) Ignore link events for MII/GMII cards if MI auto-polling disabled. This
should fix strange link state behaviour reported for bcm5721 & bcm5704c
2) Clear bge_link flag in bge_stop()
3) Force link state check after bge_ifmedia_upd(). Otherwise we can miss link
   event if PHY changes it's state fast enough.

Tested by:	phk (bcm5704c)
Approved by:	glebius (mentor)
MFC after:	1 week
2006-02-17 14:33:35 +00:00
Oleg Bulyzhin
ee7ef91c36 Enable 'complete' rx checksum offloading (i.e. let chip calculate checksums
with pseudo header for tcp/udp packets). This could save one in_pseudo() call
per incoming tcp/udp packet.

Approved by:	glebius (mentor)
MFC after:	3 weeks
2006-02-02 09:58:31 +00:00
Oleg Bulyzhin
cfcb50259d Optimize bge_rxeof() & bge_txeof(): return immediately if there are no packets
to process. It could give us [significant?] perfomance increase if there is big
difference between RX/TX flows.

Submitted by:	Mihail Balikov <mihail.balikov AT interbgc DOT com>
Approved by:	glebius (mentor)
MFC after:	3 days
2006-02-01 15:16:03 +00:00
Oleg Bulyzhin
366454f2fd Since bge_rxeof() & bge_txeof() depends on status block data it should be
synchronized on every call of bge_poll_locked().

Suggested by:	Mihail Balikov <mihail.balikov AT interbgc DOT com>
Approved by:	glebius (mentor)
MFC after:	3 days
2006-02-01 14:41:08 +00:00
Oleg Bulyzhin
7b97099d42 1) Fix link state detection for cards operating in TBI mode (fiber ones)
2) add missing bus_dmamap_sync() call in bge_intr()

Tested by:	Husnu Demir <hdemir AT metu DOT edu DOT tr>
Approved by:	glebius (mentor)
MFC after:	3 days
2006-02-01 14:26:35 +00:00
Ruslan Ermilov
d183af7f3f Setting IFF_ALLMULTI on a running interface didn't call bge_setmulti()
as intended, resulting in a non-working multicast routing.  Fix it.

MFC after:	3 days
2006-02-01 10:11:24 +00:00
Gleb Smirnoff
479b23b772 This driver can do hardware VLAN tagging + checksum offloading.
In collaboration with:	Mihail Balikov <mihail.balikov interbgc.com>
2006-01-30 13:45:55 +00:00
Gleb Smirnoff
c3a5675226 Use m_getcl() instead of getting mbuf, and then getting a cluster. 2006-01-23 15:57:02 +00:00
Gleb Smirnoff
78178cd132 Check for BGE_RXBDFLAG_IP_CSUM flag before marking mbuf as with valid
checksum. This fixes operation of PPPoE and other non-IP Ethernet
protocols.
2006-01-21 09:54:32 +00:00
Gleb Smirnoff
4e7ba1ab94 Be ready to a case when not a constant number of segments is returned
by bus_dmamap_load_mbuf_sg() on jumbo buffer allocation.

Reviewed by:	scottl, gallatin
2006-01-18 14:31:21 +00:00
Oleg Bulyzhin
6fb34dd2ed - 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).

Approved by:	glebius (mentor)
MFC after:	1 week
2006-01-17 23:01:58 +00:00
Scott Long
59caf6ec50 Don't base the number of jumbo segments on page size, instead base it on the
fact that jumbo desriptors are defined to have 3 segments.

Found by: Coverity Prevent(tm)
2006-01-14 17:42:22 +00:00
Oleg Bulyzhin
1f313773f3 1) move all link state detection code from bge_tick_locked() to bge_link_upd()
2) use more robust way of link state handling for BCM5700 rev.B2 chip
3) workaround bug of some BCM570x chips which cause spurious "link up" messages
4) fix bug: some BCM570x chips was unable to detect link state changes after
   ifconfig down/up sequence until any 'non-link related' interrupt generated.
   (this happened due to pending internal link state attention which blocked
   interrupt generation)

Approved by:	glebius (mentor)
MFC after:	1 week
2006-01-13 08:59:40 +00:00
Pyun YongHyeon
fe806fda54 Use device_printf() and if_printf() rather than printf() and axe
bge_unit from the softc.

Requested by:	marius
2005-12-23 02:04:41 +00:00
Gleb Smirnoff
d375e52490 - All bge(4) supported hardware is known to support RX/TX checksum offloading,
except for BGE_CHIPID_BCM5700_B0, which is buggy.
- All bge(4) supported hardware, has a bug that produces incorrect checksums
  on Ethernet runts. However, in case of a transmitted packet, the latter can
  be padded with zeroes, and the checksum would be correct. (Probably chip
  includes the pad data into checksum). In case of receive, we just don't
  trust checksum data in received runts.

Obtained from:	NetBSD (jonathan) via Mihail Balikov
2005-12-22 15:14:42 +00:00
Pyun YongHyeon
f6789fba46 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.

Submitted by:   jkim
2005-12-22 02:03:57 +00:00
Pyun YongHyeon
e65bed95af Add bge(4) support for big-endian architectures(part 2/2).
- removed unused funtion bge_handle_events().
 - removed bus_dmamap_destroy(9) calls for DMA maps created by
   bus_dmamem_alloc(9). This should fix panics seen on sparc64
   in device detach.
 - added check for parent DMA tag creation.
 - switched to use __NO_STRICT_ALIGNMENT as bge(4) supports all
   architectures.
 - added missing bus_dmamap_sync(9) in bge_txeof().
 - added missing bus_dmamap_sync(9) in bge_encap().
 - corrected memory synchronization operation on status block.
   As the driver just read status block that was DMAed by NIC it
   should use BUS_DMASYNC_POSTREAD. Likewise the driver does not
   need to write status block back, so remove unnecessary
   bus_dmamap_sync(9) calls in bge_intr().
 - corrected memory synchronization operation on RX return ring.
   The driver only read the block so remove unnecessary
   bus_dmamap_sync(9) in bge_rxeof().
 - force bus_dmamap_sync(9) for only modified descriptors. Blindly
   synching all desciptor rings would reduce performance.
 - call bus_dmamap_sync(9) for DMA maps that were modified in bge_rxeof().

Reviewed by:	jkim(initial version)
Tested by:	glebius(i386), jkim(amd64 initial version)
2005-12-22 01:44:27 +00:00
Gleb Smirnoff
14bbd30f2e Since BGE_MBX_TX_HOST_PROD0_LO register is write-only to software,
we can cache its value in the softc. Eliminates one PCI register
write per call to bge_start().

A 1.8% speedup for UDP_RR test on my old box.

Obtained from:	NetBSD(jonathan) via delphij
2005-12-18 20:26:12 +00:00
Gleb Smirnoff
d147662cd3 - Fix VLAN_INPUT_TAG() macro, so that it doesn't touch mtag in
case if memory allocation failed.
- Remove fourth argument from VLAN_INPUT_TAG(), that was used
  incorrectly in almost all drivers. Indicate failure with
  mbuf value of NULL.

In collaboration with:	yongari, ru, sam
2005-12-18 18:24:27 +00:00
Gleb Smirnoff
7e27542a4a o Rewrite bge_encap() to use bus_dmamap_load_mbuf_sg(9), inlining the
callback function bge_dma_map_tx_desc() into the bge_encap() itself.
o If busdma returns EFBIG, try to m_defrag() the packet.

Reviewed by:	yongari
2005-12-15 09:45:53 +00:00
Pyun YongHyeon
e907febf6a Add bge(4) support for big-endian architectures(part 1/2).
- Give up endianess support and switch to native-endian format for
   accessing hardware structures. In fact embedded processor for
   BCM57xx is big-endian architure(MIPS) and it requires native-endian
   format for NIC structures.The NIC performs necessary byte/word
   swapping depending on programmed endian type.
 - With above changes all htole16/htole32 calls were gone.
 - Remove bge_vhandle member in softc and changed to use explicit
   register access. This may add additional performance penalty
   that than that of previous memory access. But most of the access
   is performed on initialization phase(e.g. RCB setup), it would be
   negligible.

Due to incorrect use of bus_dma(9) in bge(4) it still panics sparc64
system in device detach path. The issue would be fixed in next patch.

Reviewed by:	jkim (initial version)
Silence from:	ps
Tested by:	glebius
Obtained from:	NetBSD via OpenBSD
2005-12-15 05:48:49 +00:00
Marcel Moolenaar
2778b70e71 In bge_link_upd(), rewrite the logic so that status is assigned
on the code path it is used in a way that GCC understands. This
avoids breakage due to higher optimization levels.
2005-12-13 06:14:14 +00:00
Gleb Smirnoff
1be6acb7c0 A big rewrite of receive Jumbo frame handling. Remove the local Jumbo
cluster allocator, that wasn't MPSAFE. Instead, utilize our new generic
UMA jumbo cluster allocator. Since UMA gives us a 9k piece that is contigous
in virtual memory, but isn't contigous in physical memory we need to handle
a few segments. To deal with this we utilize Tigon chip feature - extended
RX descriptors, that can handle up to four DMA segments for one frame.

Details:

o Remove bge_alloc_jumbo_mem(), bge_free_jumbo_mem(),
  bge_jalloc(), bge_jfree() functions.
o Remove SLIST heads, bge_jumbo_tag, bge_jumbo_map from softc.
o Use extended RX BDs for Jumbo receive producer ring, and
  initialize it appropriately.
o New bge_newbuf_jumbo():
  - Allocate an mbuf with Jumbo cluster with help of m_cljget().
  - Load the cluster for DMA with help of bus_dmamap_load_mbuf_sg().
  - Assert that we got 3 segments in the DMA mapping.
  - Fill in these 3 segments into the extended RX descriptor.
2005-12-08 16:11:45 +00:00
Oleg Bulyzhin
dab5cd0588 1) fix tiny bug in bge_start_locked()
2) rework link state detection code & use it in POLLING mode
3) fix 2 bugs in link state detection code:
	a) driver unable to detect link loss on bcm5721
	b) on bcm570x chips (tested on bcm5700 bcm5701 bcm5702) driver fails
	   to detect link loss with probability 1/6 (solved in brgphy.c)

Devices working in TBI mode should not be affected by this change.

Approved by:	glebius (mentor)
MFC after:	1 month
2005-12-08 13:31:52 +00:00
Gleb Smirnoff
f7cea1494f If bus_dmamap_load() failed, we free the mbuf. We also need to clear
the pointer, to avoid double free on next bge_stop().
2005-11-30 12:37:07 +00:00
Gleb Smirnoff
560c167070 Recognize Broadcom BCM5752 chip, that can be found in HP DC7600.
PR:		kern/88940
Submitted by:	Alexander Hausner
2005-11-15 14:43:22 +00:00
Ruslan Ermilov
4a0d6638b3 - Store pointer to the link-level address right in "struct ifnet"
rather than in ifindex_table[]; all (except one) accesses are
  through ifp anyway.  IF_LLADDR() works faster, and all (except
  one) ifaddr_byindex() users were converted to use ifp->if_addr.

- Stop storing a (pointer to) Ethernet address in "struct arpcom",
  and drop the IFP2ENADDR() macro; all users have been converted
  to use IF_LLADDR() instead.
2005-11-11 16:04:59 +00:00
Gleb Smirnoff
7571918432 Introduce polling(4) capability for bge(4).
Submitted by:	Oleg Bulyzhin <oleg rinet.ru>
2005-10-22 14:31:01 +00:00