History log of /openbsd-current/sys/dev/ic/rtl81x9reg.h
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.105 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.104 03-Jun-2022 dlg

expose hardware counters as kstats.

some of them are 16 bit, so check frequently.

now i can see what packets my apu1 is dropping in hardware.

ok claudio@


Revision tags: OPENBSD_7_1_BASE
# 1.103 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.102 07-May-2021 jsg

add support for RTL8168FP/RTL8111FP/RTL8117 to re(4)

from Stephen Taylor who tested on a ThinkCenter M75n Nano IoT
with RTL8111FP-CG


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.101 11-Apr-2018 patrick

Some (probably newer) re(4) cards don't have the 32-bit memory BAR that
we try to map first. Instead there's a 64-bit memory BAR in the follow-
ing BAR. Since on the MACCHIATObin we currently do not support the IO
space, we have to use the 64-bit memory BAR. Thus, try to map the 64-
bit BAR before falling back to the 32-bit BAR and the IO bar.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.


# 1.104 03-Jun-2022 dlg

expose hardware counters as kstats.

some of them are 16 bit, so check frequently.

now i can see what packets my apu1 is dropping in hardware.

ok claudio@


Revision tags: OPENBSD_7_1_BASE
# 1.103 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.102 07-May-2021 jsg

add support for RTL8168FP/RTL8111FP/RTL8117 to re(4)

from Stephen Taylor who tested on a ThinkCenter M75n Nano IoT
with RTL8111FP-CG


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.101 11-Apr-2018 patrick

Some (probably newer) re(4) cards don't have the 32-bit memory BAR that
we try to map first. Instead there's a 64-bit memory BAR in the follow-
ing BAR. Since on the MACCHIATObin we currently do not support the IO
space, we have to use the 64-bit memory BAR. Thus, try to map the 64-
bit BAR before falling back to the 32-bit BAR and the IO bar.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.


# 1.103 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_7_0_BASE
# 1.102 07-May-2021 jsg

add support for RTL8168FP/RTL8111FP/RTL8117 to re(4)

from Stephen Taylor who tested on a ThinkCenter M75n Nano IoT
with RTL8111FP-CG


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.101 11-Apr-2018 patrick

Some (probably newer) re(4) cards don't have the 32-bit memory BAR that
we try to map first. Instead there's a 64-bit memory BAR in the follow-
ing BAR. Since on the MACCHIATObin we currently do not support the IO
space, we have to use the 64-bit memory BAR. Thus, try to map the 64-
bit BAR before falling back to the 32-bit BAR and the IO bar.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.


# 1.102 07-May-2021 jsg

add support for RTL8168FP/RTL8111FP/RTL8117 to re(4)

from Stephen Taylor who tested on a ThinkCenter M75n Nano IoT
with RTL8111FP-CG


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.101 11-Apr-2018 patrick

Some (probably newer) re(4) cards don't have the 32-bit memory BAR that
we try to map first. Instead there's a 64-bit memory BAR in the follow-
ing BAR. Since on the MACCHIATObin we currently do not support the IO
space, we have to use the 64-bit memory BAR. Thus, try to map the 64-
bit BAR before falling back to the 32-bit BAR and the IO bar.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.


# 1.101 11-Apr-2018 patrick

Some (probably newer) re(4) cards don't have the 32-bit memory BAR that
we try to map first. Instead there's a 64-bit memory BAR in the follow-
ing BAR. Since on the MACCHIATObin we currently do not support the IO
space, we have to use the 64-bit memory BAR. Thus, try to map the 64-
bit BAR before falling back to the 32-bit BAR and the IO bar.

ok deraadt@ kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.100 16-Nov-2016 dlg

move toward having the a tx packet descriptor per tx ring entry.

previously you could have 64 packets on a ring with up to 1024
descriptors. this mismatch makes the accounting for free space
complicated and allows for a data race with OACTIVE being set.
it will also let us push more packets.


# 1.99 16-Nov-2016 dlg

serialise posts to the txstart register.

without this it is possible for re_txeof to let the chip look at
and complete tx descriptors that re_start has written to the ring
but not accounted for in the software producer index. in this
situation no future interrupts may be generated for packets on the
ring, and tx will stall.

the serialisation is implemented by only doing the writes from tasks
via ifq_serialize.

this is part of a bigger diff that fixes lockups reported by haesbaert.


Revision tags: OPENBSD_6_0_BASE
# 1.98 20-Apr-2016 sthen

If RTL8111E on PC Engines APU is detected, configure NIC LEDs to display link.
Normally this would be setup in the vendor-programmed eeprom, but in this case
it hasn't been done and the rather unfortunate default results in *only* a
normally-off light for network activity, nothing for ethernet link, so it's
too easy to mistake the machine for being powered down. hw.vendor/hw.machine
idea from naddy@, testing jasper@, ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.97 28-Dec-2015 jmatthew

Rework re_start and re_txeof to only check the producer/consumer ring
positions when deciding how much work to do, and to adjust rl_tx_free with
atomic operations; split the flag that indicates whether we're using
timer based interrupts or not out into a separate field so it can be
changed from interrupt context without needing a lock; take the kernel
lock when calling re_init and re_start from interrupt context; add an
interrupt barrier in re_stop; and finally mark the interrupt handler
as mpsafe.

started by Jim Smith a while ago, mostly finished up at n2k15
tested by dlg@, chris@ and Dimitris Papastamos on various hardware
ok dlg@


# 1.96 02-Nov-2015 dlg

later variants of these chips can support bigger rx and tx rings. this
diff expands them so devices that need more packets per interrupt can
use them.

this is all from brad@
tested by jim smith and benjamin perrault on APUs
tested by me on 8139s (which dont support bit rings) on landisk, and
8169s


# 1.95 04-Sep-2015 jsg

add support for RTL8168H

tedu tested an almost identical diff from brad that set the same flags.


Revision tags: OPENBSD_5_8_BASE
# 1.94 09-Apr-2015 dlg

to quote jim smith:

> fix a regression on re chips which have
> 7k jumbo support (RL_JUMBO_MTU_7K) as reported by daniel jakots
> and emilio perea. the regression was caused because RL_JUMBO_FRAMELEN
> was changed to 9k and i missed fixing up the RL_JUMBO_MTU_7K macro.

nice of him to fix the thing he broke ;)
ok sthen@


# 1.93 20-Mar-2015 dlg

add support for jumbos on re(4).

this uses hints from the freebsd driver, but the implementation
differs.

freebsd manages two lists of rx descriptors. one for "normal" packets
and the other for jumbos. this continues to use a single list and
uses a per softc variable and MCLGETI to always allocate what the
chip is capable and uses it unconditionally.

other than that, we just need to enable some bits in some registers
to be able to do jumbos.

this relies on the previous commit to properly deal with checksum
offload for packets of different sizes.

from jim smith
ok sthen@


Revision tags: OPENBSD_5_7_BASE
# 1.92 08-Mar-2015 tobiasu

Revert patch responsible for locking up machines with
"Realtek 8168" rev 0x01: RTL8168 2 (0x3800).
You will never guess who commited it without OK ;)

ok deraadt



revision 1.45
date: 2015/01/26 09:58:47; author: brad; state: Exp; lines: +22 -2; commitid: AppNYocFYbD7Hqgj;
Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.

revision 1.46
date: 2015/02/19 04:58:34; author: dlg; state: Exp; lines: +2 -2; commitid: GSWXECXQW0LeGFmq;
when reading the max packet size in the pcie device config and
status register, correctly mask things so we're left with the mps
field instead of everything but the mps field.

tested by bcallah@ and jim smith


# 1.91 26-Jan-2015 brad

Set PCIe max read request size to 2K to help with TX performance.

From FreeBSD

Tested with 8168C, 8168D and 8168G.


# 1.90 20-Jan-2015 brad

Remove use of the link change interrupt handling, not all controllers
support this interrupt. Link state changes are noticed via the PHY
status change callback or via the timeout for re_tick().

From FreeBSD


# 1.89 08-Jan-2015 brad

Use the correct config registers for the RTL8139 family. Unlike the RTL8169
and RTL8168 family, the RTL8139 has different register map for config registers.

From FreeBSD

WoL bits reviewed and tested by stsp@


# 1.88 24-Nov-2014 brad

use the correct capitalization for Realtek.


# 1.87 19-Nov-2014 brad

Add support for stopping the operation of the chipset within re_stop()
for newer generations of chipsets.

From FreeBSD

Tested with 8169, 8168C, 8168D, 8168G and by stsp@ with WOL.


# 1.86 06-Sep-2014 brad

Various changes to the re(4) feature flags..

Changed RL_FLAG_MACLDPS to RL_FLAG_MACRESET.
Removed RL_FLAG_INVMAR and RL_FLAG_NOJUMBO.
Added RL_FLAG_FASTETHER, RL_FLAG_CMDSTOP_WAIT_TXQ, RL_FLAG_JUMBOV2, RL_FLAG_WOL_MANLINK,
RL_FLAG_WAIT_TXPOLL, RL_FLAG_WOLRXENB.

Also set in the softc the maximum MTU for the various generations of chips.

Input from and Ok jsg@


Revision tags: OPENBSD_5_6_BASE
# 1.85 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.84 23-Apr-2014 jsg

rename some hardware revisions to match FreeBSD


# 1.83 23-Apr-2014 jsg

add support for RTL8168EP
From Edward O'Callaghan via FreeBSD


# 1.82 23-Apr-2014 jsg

While we always mask the revision with 0x7c800000 linux uses a table
that masks with either 0x7c800000 or 0x7cf00000 depending on the chip.

Some of the hardware revisions I previously added can't be matched with
the current mask, these are already handled by other revision defines
so remove them.

When masking the revision defines with 0x7c800000:

RL_HWREV_8106E_SPIN1 is the same as RL_HWREV_8106E
RL_HWREV_8168G_SPIN1 is the same as RL_HWREV_8168G
RL_HWREV_8168G_SPIN2 is the same as RL_HWREV_8168GU


# 1.81 23-Apr-2014 jsg

Add support for RTL8168GU
from Rafael Neves


# 1.80 13-Mar-2014 brad

Missed removing some bits with rev 1.147.

ok sthen@


# 1.79 08-Mar-2014 brad

Add the RX earlyoff support for older chips (8168{E-VL,EP, F}) and RXDV GATED
bits for the 8168G controller. This fixes operation of the 8168G controllers.
This makes reception of packets work with the 8168G controllers in the Shuttle
DS47 and other systems.

From FreeBSD, based on the Realtek Linux driver.

ok sthen@ giovani@


Revision tags: OPENBSD_5_5_BASE
# 1.78 18-Nov-2013 brad

Enable MSI on the remaining chipsets.

ok naddy@ sthen@


# 1.77 11-Oct-2013 jsg

Add initial RTL8106E and RTL8168G/8111G support.
An earlier version didn't seem to work on a machine bmercer@
had access to a few months ago but this seems to work
with the onboard Ethernet in an ASUS Z87 board RD Thrush has.


Revision tags: OPENBSD_5_4_BASE
# 1.76 17-Mar-2013 brad

- Remove the reserved number of TX descriptors. No limitation is mentioned in
the 8139C+/8169/8110/8168/8101/8111 datasheets and it seems to work ok
without reserving the descriptors.
- Change allowable number of TX DMA segments to 32.

From FreeBSD

ok chris@


Revision tags: OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.75 08-Apr-2012 jsg

additional adapter types from FreeBSD


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.74 14-Apr-2011 jsg

Add several additional adapter types and correct definition of
RTL8103E, from FreeBSD.

ok sthen@


# 1.73 13-Mar-2011 stsp

Wake On LAN support for re(4).
ok deraadt


Revision tags: OPENBSD_4_9_BASE
# 1.72 28-Nov-2010 kettenis

Bring back MCLGETI; a fix for the issue that was the reason for its previous
backout will be committed shortly.

ok sthen@


# 1.71 12-Nov-2010 sthen

revert MCLGETI for re(4) for now, it is causing hangs (in some cases
temporary, in others apparently permanent) with high rates of input
packets.

ok deraadt@


# 1.70 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.69 27-Aug-2010 deraadt

Move the activate function from pci to the the main driver, so that the
powerhook can use it
ok kettenis


Revision tags: OPENBSD_4_8_BASE
# 1.68 28-Jun-2010 sthen

Add initial support for RTL8168E, brokenness reported by Joe Gidi.
With help from Brad, ok jsg@, closes system/6402


Revision tags: OPENBSD_4_7_BASE
# 1.67 10-Aug-2009 deraadt

More cases of shutdown hooks not needed after card is already stopped. In
these cases the xxstop function is a bit more complicated and has a flag of
some sort, but the use of that flag does not matter; DMA is already ceased
ok dlg


# 1.66 23-Jul-2009 kettenis

Switch re(4) over to MCLGETI.

ok deraadt@


# 1.65 11-Jul-2009 sthen

- Add some new feature flags
- Add defines for newer chipsets

From FreeBSD via Brad. No functional change, needed for future work.
ok naddy@.


# 1.64 10-Jul-2009 sthen

Swap the hardware revision IDs for 8169S and 8110S. Agrees with the
labelling on naddy@'s PCI cards. From Brad.


Revision tags: OPENBSD_4_6_BASE
# 1.63 03-Jul-2009 deraadt

Support RTL8103E and RTL8168DP which are starting to show up, from brad.
OK from kettenis and sthen after the diff was minimized to have no
potential impact on other chips.


# 1.62 03-Jun-2009 sthen

from Brad; I've read and tested it, also reads ok to dlg@.

- Further simplify the re(4) receive filter handling and
have everything taken care of in re_iff(), eliminating
a bit of code from re_init().
- Remove unused if_flags field.


# 1.61 02-Jun-2009 jsg

make rl at pci detachable; untested.


Revision tags: OPENBSD_4_5_BASE
# 1.60 12-Feb-2009 martynas

don't access undocumented register 0x82 for <= MAC06, since newer
realteks start to behave badly if we do. this should fix the widely
reported re(4) issue. makes my RTL8101E usable, fixes Thomas'
RTL8168C, and PR6023. tested by many
this is a more conservative version of my diff from kettenis@ (does
not clear PHY register 0x0b)
ok kettenis@


# 1.59 30-Nov-2008 brad

Add initial 8168D/8111D support.


# 1.58 08-Nov-2008 brad

Reduce the delay's a bit in the miibus read/write routines.

Based on the Linux r8169 driver.

Tested on PCI/CardBus and PCIe adapters.


# 1.57 08-Nov-2008 brad

Reduce the number of TX descriptors to 512, such a large number is not
necessary without TSO.


# 1.56 11-Oct-2008 brad

Use hardware timer to simulate interrupt moderation. Old devices will no
longer be livelocked when they are receiving on GigE line. Newer devices
also gain well controlled interrupt rate.

If hardware supports interrupt moderation (e.g. 8168B, 8168C), you could
also use hardware based interrupt moderation, however, due to lack of
necessary information it does not work as reliably as simulated interrupt
moderation. It is _not_ recommended currently.

By default, PCIe devices' simulated interrupt moderation timer is set to
75us, while PCI devices' is set to 125us.

From sephe@DragonFly


# 1.55 06-Oct-2008 brad

Detect and store the PCI/PCIe bus speed.

From DragonFly


# 1.54 05-Oct-2008 brad

Add a flag to indicate a 64-bit PCI bus is present.


# 1.53 05-Oct-2008 brad

Detect if the adapter is a PCIe adapter and set the RL_FLAG_PCIE flag
if so.


# 1.52 27-Aug-2008 brad

Remove a redundant define for RL_CFG2 and remove an incorrect comment.


# 1.51 13-Aug-2008 brad

Add more Config mode registers.

From FreeBSD


# 1.50 11-Aug-2008 brad

Add support for TX/RX checksum offload for newer re(4) chipsets.

Tested by naddy@

From FreeBSD


Revision tags: OPENBSD_4_4_BASE
# 1.49 15-Jul-2008 jsg

Adapt some code from the FreeBSD driver required to make
newer PCI Express adapters (ie 8168C*/8102*) work.

V2 Checksum offload format in RTL8102 devices not yet supported.

No objections from brad@. Thanks to everyone who tested.


# 1.48 13-Jul-2008 jsg

Add some additional hardware revisions from FreeBSD needed for
upcoming changes and sort list.


# 1.47 20-Apr-2008 brad

Move the threshold fix from the re(4) code back into the header as
it was going to be before the release. No functional change.

prodded by kettenis@ ok dlg@


# 1.46 20-Apr-2008 brad

- Recognize the 8168C chipset.
- Add some more defines for the 8168C chipset.

From NetBSD

ok dlg@


# 1.45 20-Apr-2008 brad

- Add some more defines.
- Use one of the new defines in the re(4) code to remove a magic number.
- Correct a comment.
- Fix a typo.

Most of this is from NetBSD.

ok dlg@


# 1.44 20-Apr-2008 brad

Remove unused flags.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.43 17-Feb-2008 brad

Simplify the hw revision handling by removing the use of the
rl_type softc field and only relying on the sc_hwrev softc
field thoughout the driver.

Tested by a number of users from tech@

ok dlg@


# 1.42 16-Jan-2008 brad

- Store the hw revision into a new softc field in re_attach() and reference
the softc field wherever it is necessary.
- Use a switch case in re_setmulti() to make things a bit easier to read.

ok henning@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.41 07-Aug-2007 jsg

Correct value for power state D1.
While this duplicates the values specified in the PCI headers
and is currently unused, correcting this arguably makes more
sense than breaking diffability with FreeBSD.

Invalid value pointed out by Maxim Bourmistrov <maxim@unixconn.com>

API change discussed with deraadt@


# 1.40 16-Jul-2007 millert

The logic determining the value of rl_eewidth for the 9346 and 9356
eeproms was backwards. This resulted in a bogus MAC address being
read from the eeprom on certain cards. From FreeBSD. OK pvalchev@


# 1.39 06-Jun-2007 pvalchev

add another revision "RTL8168 3"; from NetBSD via Brad


# 1.38 06-Jun-2007 pvalchev

- Recognize the 8110SCe 8169 revision in re(4)
- Rename the existing 8110SC revision to 8110SCd to be consistent
info from the linux driver via Brad


# 1.37 08-May-2007 deraadt

rl_detach() is only used for cardbus case


Revision tags: OPENBSD_4_1_BASE
# 1.36 12-Dec-2006 reyk

add a workaround for hardware ip4csum-tx bug on re(4) chips. the
hardware checksum could be mangled with 28 byte or less IP packets.

>From tsutsui@NetBSD
Tested by otto@ brad@ and Han Boetes <han at mijncomputer dot nl>
Tested by maja@ with the 8139C+ chipset
Tested on amd64/i386/sparc64

ok mglocker@ brad@ otto@


# 1.35 01-Dec-2006 todd

rename 8100E id to spin 1 and add the 8100E second spin chip id
chip id from Linux r8169 driver
from brad@


# 1.34 26-Nov-2006 jsg

correct hardware revision mask.


# 1.33 24-Nov-2006 brad

replace a magic number (reserved TX descs?) with macro

From tsutsui@NetBSD


# 1.32 18-Nov-2006 brad

- set descriptor DMA addresses before enabling TX and RX
- set RL_EARLY_TX_THRESH before starting TX and RX
- clear a TX timeout only if all queued packets are handled
- declare struct rl_txq separately
- minor style tweaks in re_txeof()

From tsutsui@NetBSD

Tested by brad@, maja@ and kettenis@
Tested on amd64/armish/i386/sparc64


# 1.31 01-Nov-2006 brad

Put common data for each RX DMA descriptor into a new rxsoft structure.

From tsutsui@NetBSD

Tested by brad@ otto@
Tested on amd64/i386/sparc64


# 1.30 31-Oct-2006 brad

- Rename a variable to clarify meaning of index.
- Rename RL_[TR]X_DESC_INC() macro to RL_NEXT_[TR]X_DESC() and
change them to return rvalues to avoid possible side effects.
- Also define RL_NEXT_TXQ() for rl_txq index and use it as well.

From tsutsui@NetBSD


# 1.29 31-Oct-2006 brad

- Make DMA descripter members volatile
- Remove usage of BUS_DMA_ALLOCNOW with bus_dmamap_create
- Use BUS_DMA_COHERENT on mapping DMA memory for TX/RX descriptors
- Adjust m_data and m_len directly rather than calling m_adj
- Proper use of bus_dmamap_sync against DMA descriptors

From tsutsui@NetBSD

Tested by kettenis@ brad@ otto@
Tested on armish/amd64/i386/sparc64


Revision tags: OPENBSD_4_0_BASE
# 1.28 16-Aug-2006 brad

Not a bug, but change the ID strings for devices with hardware rev
0x30000000 and 0x38000000 to both be 8168B/8111B. According to RealTek,
they're both the same device, but 0x30000000 is an earlier silicon spin.

From wpaul@FreeBSD


# 1.27 05-Aug-2006 brad

- move the promiscuous mode handling code into re_setpromisc().
- have the NIC track the state and only set the promisc filter
if IFF_PROMISC is adjusted, otherwise only init the NIC if it
is not already running.


# 1.26 05-Aug-2006 brad

- restructure the TX descriptor handling code to decouple the
number of TX descriptors, the number of RX descriptors, and
the number of mbufs.
- bump the number of TX descriptors for the rtl8169 chipset.

From yamt@NetBSD


# 1.25 03-Jul-2006 brad

- re_attach(): Use bus_dma* directly instead of calling re_allocmem().
- re_attach(): Free bus_dma* resources if attach fails.
- re_newbuf(): Remove unnecessary error check.
- re_encap(): Better error handling.
- re_start(): Drop the packet if there are not enough TX descriptors.

From NetBSD


# 1.24 01-Jul-2006 brad

fix the hw rev id for the 8168 and add the id for the 8111

From wpaul FreeBSD


# 1.23 27-Jun-2006 brad

new HW revs, EEPROM commands, softc fields, some macros and device ids.

From wpaul FreeBSD


# 1.22 27-Jun-2006 brad

- add fixup code in the RX path for strict alignment architectures.
- add a workaround for reception of Jumbo frames.
- don't try to adjust alignment on non-strict alignment architectures,
this resolves an issue with the PCI Express adapters.

From FreeBSD

ok drahn@


Revision tags: OPENBSD_3_9_BASE
# 1.21 17-Sep-2005 brad

add some Realtek chip ids


Revision tags: OPENBSD_3_8_BASE
# 1.20 03-Aug-2005 brad

This commit was derived from a commit to FreeBSD..

Use stream bus space accesses to program the ID (station address)
registers; otherwise, the byte order of the address is changed on
big-endian machines.

Though our bus_space API is different.

Tested by form at pdp-11 dotorg dot ru and robert@

ok mickey@ robert@


# 1.19 15-Apr-2005 brad

re-add RL_JUMBO_FRAMELEN/RL_JUMBO_MTU but this time use the right values


# 1.18 15-Apr-2005 brad

add another 8169 rev and remove vtophys() hack for alpha now that the driver
has been bus_dma-ified


Revision tags: OPENBSD_3_7_BASE
# 1.17 13-Oct-2004 miod

Let the generic rtl code work if the bus-dependent code has decided to attach;
this lets the 8138-based cardbus devices to really attach.

8138-specific mii differences will need to be investigated; right now,
recognizing the 8138 as either 8139 or non-8139 causes it to lose the link
after a while, but nothing ifconfig can not reset...

From a discussion with and tested by Beno�t Izac, who owns a 8138-based
cardbus device.


# 1.16 30-Sep-2004 jason

bus_dma-ify... thanks to robert, jgs, and grange for testing
still borked on sparc64, but hey, one step at a time


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

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


# 1.14 05-Aug-2004 deraadt

compile before you commit damnit


# 1.13 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.12 05-Jun-2004 pvalchev

add multicast support


# 1.11 05-Jun-2004 pvalchev

Add defines for RealTek 8139C+/8169/8169S/8110S; from FreeBSD


# 1.10 19-May-2004 brad

remove duplication, use ETHER_ALIGN from if_ether.h


# 1.9 07-Apr-2004 mickey

attach on abocom's 8139; from Kimmo Sinkko <kimmo@sinkko.org>


Revision tags: OPENBSD_3_5_BASE
# 1.8 01-Oct-2003 fgsch

it turned that only adding the cardbus part was not enough to have
D-Link DFE690 working. add the missing bits here.
from Joshua Johnson <joshua.johnson at charter dot net>.


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE UBC_SYNC_A UBC_SYNC_B
# 1.7 15-Oct-2002 mickey

re-init the hw on resume, from grendel@zeitbombe.org


Revision tags: OPENBSD_3_2_BASE
# 1.6 09-Jun-2002 todd

a step towards consistancy; in general:
'struct arpcom foo' -> 'struct arpcom sc_arpcom'
ok itojun@


# 1.5 08-Jun-2002 aaron

Add support for RealTek 8129/8139-based CardBus cards; mostly from NetBSD.
deraadt@, jasoni@ ok. Thanks to niklas@ for donating a card for testing.


Revision tags: OPENBSD_3_1_BASE
# 1.4 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.3 23-Jun-2001 fgsch

branches: 1.3.4;
More constants cleaning.


# 1.2 22-May-2001 mickey

support for D-Link DFE-530TX and DFE-530TX+; from Maxim Tsyplakov <tm@oganer.net>


Revision tags: OPENBSD_2_9_BASE
# 1.1 10-Apr-2001 aaron

branches: 1.1.4;
Split RealTek 8129/8139 driver into bus-dependent and bus-independent parts;
prep for an rl CardBus attachment.