History log of /freebsd-current/sys/dev/re/if_re.c
Revision Date Author Comments
# 88d2b69c 23-Nov-2023 Brad Smith <brad@comstyle.com>

re(4): Add support for 8168FP HW rev

MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D42671


# 3c871489 06-Oct-2023 Sk Razee <dragonflies@mailfence.com>

if_re: add Realtek Killer Ethernet E2600 IDs

PR: 274292
MFC after: 1 week
Reviewed by: kp
Event: Oslo Hackathon at Modirum


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 535946ce 20-Mar-2023 Zhenlei Huang <zlei@FreeBSD.org>

if_re: Drop redundant assignments for ifq_maxlen and ifq_drv_maxlen

Fixes: 4519a073c326b Mechanically convert if_re(4) to DrvAPI


# 55747938 27-Feb-2023 Evgeni Golov <evgeni@debian.org>

if_re: Generate an address if there is none in the EEPROM

There exists hardware that has no ethernet address burned into
the EEPROM. Loading if_re on such a HW brings the device up
with '00:00:00:00:00:00' as the address, and that doesn't get
you too far in a real network.

PR: 262406
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/670
Signed-off-by: Evgeni Golov <evgeni@debian.org>
Differential Revision: https://reviews.freebsd.org/D34485


# ad06fc32 31-Jan-2023 Justin Hibbits <jhibbits@FreeBSD.org>

re(4): Fix whitespace from IfAPI conversion

Fixes: 4519a073c326b
Sponsored by: Juniper Networks, Inc.


# 4519a073 25-Feb-2022 Justin Hibbits <jhibbits@FreeBSD.org>

Mechanically convert if_re(4) to DrvAPI

Reviewed By: kevlo
Sponsored by: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37790


# 30c024c5 06-May-2022 John Baldwin <jhb@FreeBSD.org>

re/rl: Remove unused devclass arguments to DRIVER_MODULE.


# 3e38757d 19-Apr-2022 John Baldwin <jhb@FreeBSD.org>

Remove unused miibus_devclass and miibus_fdt_devclass.


# a34d3ca6 23-Dec-2021 Jessica Clarke <jrtc27@FreeBSD.org>

re: Avoid subobject overread when setting IDRn

IDR0-IDR5 can be read byte-by-byte but must be written to as 4-byte
words. The current code to do this is rather clunky and ends up reading
past the end of the union's eaddr member due to MAC addresses only being
6 bytes. In practice this ends up being fine because the align_dummy
member will pad the union to a multiple of 4 bytes, but this is dodgy,
and on CHERI with subobject bounds enforcement enabled, as is done in
CheriBSD's pure-capability kernel, will trap.

Instead, make the buffer in use the right size, just use an array of
uint32_t's rather than a char buffer that's then cast to uint32_t * to
simplify it in the process, and zero-initialise it first to avoid
reading uninitialised data in the trailing bytes.

Found by: CHERI
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D33617


# 54bbcca4 10-Jan-2021 Vincenzo Maffione <vmaffione@FreeBSD.org>

re: netmap: enable/disable krings on interface reinit

This prevents krings from being used during an interface
reset, and notifies the active applications.
See also 1d238b07d5d4d9660ae0.

MFC after: 1 week


# ce3e137c 05-Oct-2020 Mark Johnston <markj@FreeBSD.org>

re(4): Add a 8168-compatible device ID

This is described in RealTek's driver as a "RTL8168 Series add-on card."

PR: 250037
Submitted by: Hiroshi HASEGAWA <hhase1973@gmail.com>
MFC after: 1 week


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# 6c3e93cb 11-Feb-2020 Gleb Smirnoff <glebius@FreeBSD.org>

Use NET_TASK_INIT() and NET_GROUPTASK_INIT() for drivers that process
incoming packets in taskqueue context.

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D23518


# 2f0e17b7 24-Jan-2020 Gleb Smirnoff <glebius@FreeBSD.org>

re(4) uses taskqueue to process input packets. Enter network epoch
in there.


# 307b050d 21-Oct-2019 Gleb Smirnoff <glebius@FreeBSD.org>

Convert to if_foreach_llmaddr() KPI.


# 7790c8c1 17-Oct-2019 Conrad Meyer <cem@FreeBSD.org>

Split out a more generic debugnet(4) from netdump(4)

Debugnet is a simplistic and specialized panic- or debug-time reliable
datagram transport. It can drive a single connection at a time and is
currently unidirectional (debug/panic machine transmit to remote server
only).

It is mostly a verbatim code lift from netdump(4). Netdump(4) remains
the only consumer (until the rest of this patch series lands).

The INET-specific logic has been extracted somewhat more thoroughly than
previously in netdump(4), into debugnet_inet.c. UDP-layer logic and up, as
much as possible as is protocol-independent, remains in debugnet.c. The
separation is not perfect and future improvement is welcome. Supporting
INET6 is a long-term goal.

Much of the diff is "gratuitous" renaming from 'netdump_' or 'nd_' to
'debugnet_' or 'dn_' -- sorry. I thought keeping the netdump name on the
generic module would be more confusing than the refactoring.

The only functional change here is the mbuf allocation / tracking. Instead
of initiating solely on netdump-configured interface(s) at dumpon(8)
configuration time, we watch for any debugnet-enabled NIC for link
activation and query it for mbuf parameters at that time. If they exceed
the existing high-water mark allocation, we re-allocate and track the new
high-water mark. Otherwise, we leave the pre-panic mbuf allocation alone.
In a future patch in this series, this will allow initiating netdump from
panic ddb(4) without pre-panic configuration.

No other functional change intended.

Reviewed by: markj (earlier version)
Some discussion with: emaste, jhb
Objection from: marius
Differential Revision: https://reviews.freebsd.org/D21421


# d7c5a620 18-May-2018 Matt Macy <mmacy@FreeBSD.org>

ifnet: Replace if_addr_lock rwlock with epoch + mutex

Run on LLNW canaries and tested by pho@

gallatin:
Using a 14-core, 28-HTT single socket E5-2697 v3 with a 40GbE MLX5
based ConnectX 4-LX NIC, I see an almost 12% improvement in received
packet rate, and a larger improvement in bytes delivered all the way
to userspace.

When the host receiving 64 streams of netperf -H $DUT -t UDP_STREAM -- -m 1,
I see, using nstat -I mce0 1 before the patch:

InMpps OMpps InGbs OGbs err TCP Est %CPU syscalls csw irq GBfree
4.98 0.00 4.42 0.00 4235592 33 83.80 4720653 2149771 1235 247.32
4.73 0.00 4.20 0.00 4025260 33 82.99 4724900 2139833 1204 247.32
4.72 0.00 4.20 0.00 4035252 33 82.14 4719162 2132023 1264 247.32
4.71 0.00 4.21 0.00 4073206 33 83.68 4744973 2123317 1347 247.32
4.72 0.00 4.21 0.00 4061118 33 80.82 4713615 2188091 1490 247.32
4.72 0.00 4.21 0.00 4051675 33 85.29 4727399 2109011 1205 247.32
4.73 0.00 4.21 0.00 4039056 33 84.65 4724735 2102603 1053 247.32

After the patch

InMpps OMpps InGbs OGbs err TCP Est %CPU syscalls csw irq GBfree
5.43 0.00 4.20 0.00 3313143 33 84.96 5434214 1900162 2656 245.51
5.43 0.00 4.20 0.00 3308527 33 85.24 5439695 1809382 2521 245.51
5.42 0.00 4.19 0.00 3316778 33 87.54 5416028 1805835 2256 245.51
5.42 0.00 4.19 0.00 3317673 33 90.44 5426044 1763056 2332 245.51
5.42 0.00 4.19 0.00 3314839 33 88.11 5435732 1792218 2499 245.52
5.44 0.00 4.19 0.00 3293228 33 91.84 5426301 1668597 2121 245.52

Similarly, netperf reports 230Mb/s before the patch, and 270Mb/s after the patch

Reviewed by: gallatin
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D15366


# 306c97e2 05-May-2018 Mark Johnston <markj@FreeBSD.org>

Add netdump support to re(4).

Tested with a RealTek 8101E adapter.

Reviewed by: sbruno
MFC after: 1 month
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D15260


# 2ff91c17 12-Apr-2018 Vincenzo Maffione <vmaffione@FreeBSD.org>

netmap: align codebase to the current upstream (commit id 3fb001303718146)

Changelist:
- Turn tx_rings and rx_rings arrays into arrays of pointers to kring
structs. This patch includes fixes for ixv, ixl, ix, re, cxgbe, iflib,
vtnet and ptnet drivers to cope with the change.
- Generalize the nm_config() callback to accept a struct containing many
parameters.
- Introduce NKR_FAKERING to support buffers sharing (used for netmap
pipes)
- Improved API for external VALE modules.
- Various bug fixes and improvements to the netmap memory allocator,
including support for externally (userspace) allocated memory.
- Refactoring of netmap pipes: now linked rings share the same netmap
buffers, with a separate set of kring pointers (rhead, rcur, rtail).
Buffer swapping does not need to happen anymore.
- Large refactoring of the control API towards an extensible solution;
the goal is to allow the addition of more commands and extension of
existing ones (with new options) without the need of hacks or the
risk of running out of configuration space.
A new NIOCCTRL ioctl has been added to handle all the requests of the
new control API, which cover all the functionalities so far supported.
The netmap API bumps from 11 to 12 with this patch. Full backward
compatibility is provided for the old control command (NIOCREGIF), by
means of a new netmap_legacy module. Many parts of the old netmap.h
header has now been moved to netmap_legacy.h (included by netmap.h).

Approved by: hrs (mentor)


# df57947f 18-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

spdx: initial adoption of licensing ID tags.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes: yes
Differential Revision: https://reviews.freebsd.org/D13133


# 3d810282 26-Oct-2016 Kevin Lo <kevlo@FreeBSD.org>

Disable CLKREQ for ASPM since re(4) doesn't implement link level power saving.

Reviewed by: yongari


# 938e9a89 21-Sep-2016 Kevin Lo <kevlo@FreeBSD.org>

Add support for the TP-Link TG-3468 v2.

This is an RTL8168 chip, which we already support so all we have to do is add
the vendor ID.

PR: 212876
Submitted by: Tobias Kortkamp <t@tobik.me>
MFC after: 3 days


# 73a1170a 19-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: use our nitems() macro when it is avaliable through param.h.

No functional change, only trivial cases are done in this sweep,
Drivers that can get further enhancements will be done independently.

Discussed in: freebsd-current


# cbc4d2db 01-Mar-2016 John Baldwin <jhb@FreeBSD.org>

Remove taskqueue_enqueue_fast().

taskqueue_enqueue() was changed to support both fast and non-fast
taskqueues 10 years ago in r154167. It has been a compat shim ever
since. It's time for the compat shim to go.

Submitted by: Howard Su <howard0su@gmail.com>
Reviewed by: sephe
Differential Revision: https://reviews.freebsd.org/D5131


# e9f8886e 16-Nov-2015 Marius Strobl <marius@FreeBSD.org>

With r290566 in place it turned out that WOL previously only worked by
accident with RTL8168G and later chips when the interface actually was
brought up. This is due to the fact that with these MAC variants, RXDV
gate needs be disabled for WOL to work. So do just that in re_setwol()
when IFCAP_WOL is requested.
Reported and tested by: dhw

MFC after: 3 days


# 14013280 08-Nov-2015 Marius Strobl <marius@FreeBSD.org>

- Although it doesn't make a whole lot of sense to enable RX and TX
before their initial configuration is done, it turns out that r281337
has the inverse effect on some older chips. Moreover, as with newer
chips before, two chips seemingly identical according to their MAC
revisions may behave differently in this regard, with most working
but a few not, making changes extremely hard to test.
Closer inspection of the corresponding Linux code suggests that RX
and TX should only be enabled after their initial configuration with
RTL8168G and later chips, i. e. RTL8106E{,US}, RTL8107E, as well as
RTL8168{EP,G,GU,H}, so limit the new code path to these. [1]
- Distinguish between RTL8168H and RTL8107E, with the latter being the
10/100-Mbit/s-only variant of the former.
- For MAC variants that can only do Fast Ethernet at a maximum, ensure
that we don't advertise Gigabit Ethernet speed.
- In re_stop(), do the inverse of re_init_locked() and enable RXDV
gate on RTL8168G and later chips again, matching what Linux does.

PR: 203422 [1]
MFC after: 1 week


# 96b2c26a 13-Sep-2015 Marius Strobl <marius@FreeBSD.org>

Add preliminary support for RTL8168H, tested by Sreenath Battalahalli.

MFC after: 1 week


# 847bf383 09-Jul-2015 Luigi Rizzo <luigi@FreeBSD.org>

Sync netmap sources with the version in our private tree.
This commit contains large contributions from Giuseppe Lettieri and
Stefano Garzarella, is partly supported by grants from Verisign and Cisco,
and brings in the following:

- fix zerocopy monitor ports and introduce copying monitor ports
(the latter are lower performance but give access to all traffic
in parallel with the application)

- exclusive open mode, useful to implement solutions that recover
from crashes of the main netmap client (suggested by Patrick Kelsey)

- revised memory allocator in preparation for the 'passthrough mode'
(ptnetmap) recently presented at bsdcan. ptnetmap is described in
S. Garzarella, G. Lettieri, L. Rizzo;
Virtual device passthrough for high speed VM networking,
ACM/IEEE ANCS 2015, Oakland (CA) May 2015
http://info.iet.unipi.it/~luigi/research.html

- fix rx CRC handing on ixl

- add module dependencies for netmap when building drivers as modules

- minor simplifications to device-specific routines (*txsync, *rxsync)

- general code cleanup (remove unused variables, introduce macros
to access rings and remove duplicate code,

Applications do not need to be recompiled, unless of course
they want to use the new features (monitors and exclusive open).

Those willing to try this code on stable/10 can just update the
sys/dev/netmap/*, sys/net/netmap* with the version in HEAD
and apply the small patches to individual device drivers.

MFC after: 1 month
Sponsored by: (partly) Verisign, Cisco


# 0f55f9d6 09-Apr-2015 Marius Strobl <marius@FreeBSD.org>

Don't enable RX and TX before their initial configuration is done, i. e.
after setting up interrupt moderation but before turning interrupts on.
This matches what Realtek's r8168 Linux driver does as of version 8.039.00
and fixes problems with certain incarnations of certain MAC revisions
like the interface requiring an extra up/down-cycle after boot to start
working or DMA configuration not being adhered to.

PR: 193743, 197535
MFC after: 1 week


# b8333e45 20-Oct-2014 Pyun YongHyeon <yongari@FreeBSD.org>

It seems multicast filtering of RTL8168F does not work. Workaround
the silicon bug by accepting any multicast packets.

PR: 193488
MFC After: 1 week


# b2d3d26f 19-Sep-2014 Gleb Smirnoff <glebius@FreeBSD.org>

Move rl(4) to dev/rl.


# c8dfaf38 18-Sep-2014 Gleb Smirnoff <glebius@FreeBSD.org>

Mechanically convert to if_inc_counter().


# 1bffa951 30-Aug-2014 Gleb Smirnoff <glebius@FreeBSD.org>

Use define from if_var.h to access a field inside struct if_data,
that resides in struct ifnet.

Sponsored by: Nginx, Inc.


# 068d8643 11-Jun-2014 John Baldwin <jhb@FreeBSD.org>

Fix various NIC drivers to properly cleanup static DMA resources.
In particular, don't check the value of the bus_dma map against NULL
to determine if either bus_dmamem_alloc() or bus_dmamap_load() succeeded.
Instead, assume that bus_dmamap_load() succeeeded (and thus that
bus_dmamap_unload() should be called) if the bus address for a resource
is non-zero, and assume that bus_dmamem_alloc() succeeded (and thus
that bus_dmamem_free() should be called) if the virtual address for a
resource is not NULL.

In many cases these bugs could result in leaks when a driver was detached.

Reviewed by: yongari
MFC after: 2 weeks


# 74a03446 12-May-2014 Pyun YongHyeon <yongari@FreeBSD.org>

Disable TX IP/TCP/UDP checksum offloading for RTL8168C/RTL8168CP.
Previously only TX IP checksum offloading was disabled but it's
reported that TX checksum offloading for UDP datagrams with IP
options also generates corrupted frames. Reporter's controller is
RTL8168CP but I guess RTL8168C also have the same issue since it
shall share the same core.

Reported and tested by: tuexen


# f1a5f291 05-Feb-2014 Marius Strobl <marius@FreeBSD.org>

- Implement the RX EARLYOFF and RXDV GATED bits as done by RealTek's Linux
driver as version 8.037.00 for RTL8168{E-VL,EP,F,G,GU} and RTL8111B. This
makes reception of packets work with the RTL8168G (HW rev. 0x4c000000) in
my Shuttle DS47.
- Consistently use RL_MSI_MESSAGES.
In joint forces with: yongari

MFC after: 5 days


# ce3ee1e7 01-Nov-2013 Luigi Rizzo <luigi@FreeBSD.org>

update to the latest netmap snapshot.
This includes the following:
- use separate memory regions for VALE ports
- locking fixes
- some simplifications in the NIC-specific routines
- performance improvements for the VALE switch
- some new features in the pkt-gen test program
- documentation updates

There are small API changes that require programs to be recompiled
(NETMAP_API has been bumped so you will detect old binaries at runtime).

In particular:
- struct netmap_slot now is 16 bytes to support an extra pointer,
which may save one data copy when using VALE ports or VMs;
- the struct netmap_if has two extra fields;

MFC after: 3 days


# c3767eab 28-Oct-2013 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8168EP.

Submitted by: Edward O'Callaghan (eocallaghan <> alterapraxis dot com)


# ab9f923e 28-Oct-2013 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8168G, RTL8168GU and RTL8411B.
RTL8168GU has two variants(GMII and MII) but it uses the same chip
revision id. Driver checks PCI device id of controller and
sets internal capability flag(i.e. jumbo frame and link speed down
in WOL).

H/W donated by: RealTek Semiconductor Corp.


# 76039bc8 26-Oct-2013 Gleb Smirnoff <glebius@FreeBSD.org>

The r48589 promised to remove implicit inclusion of if_var.h soon. Prepare
to this event, adding if_var.h to files that do need it. Also, include
all includes that now are included due to implicit pollution via if_var.h

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# 214c71f6 21-Oct-2013 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8106E PCIe FastEthernet.

H/W donated by: RealTek Semiconductor Corp.


# fd3ae0f5 21-Oct-2013 Pyun YongHyeon <yongari@FreeBSD.org>

Correct MAC revision bits. Previously it always cleared bit 20 and
bit 21.


# 2df05392 28-Jun-2013 Sergey Kandaurov <pluknet@FreeBSD.org>

Correct comment typos.


# d61ba752 30-Apr-2013 Luigi Rizzo <luigi@FreeBSD.org>

use netmap_rx_irq() / netmap_tx_irq() to handle interrupts in
netmap mode, removing the logic from individual drivers.

(note: if_lem.c not updated yet due to some other pending modifications)


# 3c2a957d 12-Mar-2013 Pyun YongHyeon <yongari@FreeBSD.org>

Disable TX IP header checksum offloading on RL_HWREV_8168CP. The
controller generates wrong checksummed frame if the IP packet has
IP options.

Submitted by: Alexander Bluhm via brad@openbsd


# c6499ecc 04-Dec-2012 Gleb Smirnoff <glebius@FreeBSD.org>

Mechanically substitute flags from historic mbuf allocator with
malloc(9) flags in sys/dev.


# 29658c96 05-Nov-2012 Dimitry Andric <dim@FreeBSD.org>

Remove duplicate const specifiers in many drivers (I hope I got all of
them, please let me know if not). Most of these are of the form:

static const struct bzzt_type {
[...list of members...]
} const bzzt_devs[] = {
[...list of initializers...]
};

The second const is unnecessary, as arrays cannot be modified anyway,
and if the elements are const, the whole thing is const automatically
(e.g. it is placed in .rodata).

I have verified this does not change the binary output of a full kernel
build (except for build timestamps embedded in the object files).

Reviewed by: yongari, marius
MFC after: 1 week


# e935190a 18-Sep-2012 Gavin Atkinson <gavin@FreeBSD.org>

Switch some PCI register reads from using magic numbers to using the names
defined in pcireg.h

MFC after: 1 week


# 389c8bd5 18-Sep-2012 Gavin Atkinson <gavin@FreeBSD.org>

Align the PCI Express #defines with the style used for the PCI-X
#defines. This also has the advantage that it makes the names more
compact, iand also allows us to correct the non-uniform naming of
the PCIM_LINK_* defines, making them all consistent amongst themselves.

This is a mostly mechanical rename:
s/PCIR_EXPRESS_/PCIER_/g
s/PCIM_EXP_/PCIEM_/g
s/PCIM_LINK_/PCIEM_LINK_/g

When this is MFC'd, #defines will be added for the old names to assist
out-of-tree drivers.

Discussed with: jhb
MFC after: 1 week


# 1221cc67 13-Aug-2012 Ed Maste <emaste@FreeBSD.org>

Use array notation for consistency.


# de8925a2 24-Jun-2012 Kevin Lo <kevlo@FreeBSD.org>

Fix size of the bcopy when extracting ethernet address

Obtained from: DragonFly


# 82242c11 11-May-2012 Kevin Lo <kevlo@FreeBSD.org>

Make sure we don't dereference a null pointer


# fca1e0ab 24-Apr-2012 Bjoern A. Zeeb <bz@FreeBSD.org>

Do not toggle IFCAP_TSO4 if we would also do TSO6. Given the driver does
not currently announce/support TSO6 that cannot happen. Clean it up anyway
for consistency.

Reviewed by: yongari
MFC after: 1 week


# fed3ed71 27-Feb-2012 Pyun YongHyeon <yongari@FreeBSD.org>

Prefer RL_GMEDIASTAT register to RGEPHY_MII_SSR register to
extract a link status of PHY when parent driver is re(4).
RGEPHY_MII_SSR register does not seem to report correct PHY status
on some integrated PHYs used with re(4).
Unfortunately, RealTek PHYs have no additional information to
differentiate integrated PHYs from external ones so relying on PHY
model number is not enough to know that. However, it seems
RGEPHY_MII_SSR register exists for external RealTek PHYs so
checking parent driver would be good indication to know which PHY
was used. In other words, for non-re(4) controllers, the PHY is
external one and its revision number is greater than or equal to 2.
This change fixes intermittent link UP/DOWN messages reported on
RTL8169 controller.

Also, mii_attach(9) is tried after setting interface name since
rgephy(4) have to know parent driver name.

PR: kern/165509


# 64ae02c3 27-Feb-2012 Luigi Rizzo <luigi@FreeBSD.org>

A bunch of netmap fixes:

USERSPACE:
1. add support for devices with different number of rx and tx queues;

2. add better support for zero-copy operation, adding an extra field
to the netmap ring to indicate how many buffers we have already processed
but not yet released (with help from Eddie Kohler);

3. The two changes above unfortunately require an API change, so while
at it add a version field and some spares to the ioctl() argument
to help detect mismatches.

4. update the manual page for the two changes above;

5. update sample applications in tools/tools/netmap

KERNEL:

1. simplify the internal structures moving the global wait queues
to the 'struct netmap_adapter';

2. simplify the functions that map kring<->nic ring indexes

3. normalize device-specific code, helps mainteinance;

4. start exploring the impact of micro-optimizations (prefetch etc.)
in the ixgbe driver.
Use 'legacy' descriptors on the tx ring and prefetch slots gives
about 20% speedup at 900 MHz. Another 7-10% would come from removing
the explict calls to bus_dmamap* in the core (they are effectively
NOPs in this case, but it takes expensive load of the per-buffer
dma maps to figure out that they are all NULL.

Rx performance not investigated.

I am postponing the MFC so i can import a few more improvements
before merging.


# e7e7593c 24-Feb-2012 Pyun YongHyeon <yongari@FreeBSD.org>

Use correct Config registers for RTL8139 family. Unlike RTL8168 and
RTL810x family , RTL8139 has different register map for Config
registers.

While here, follow the lead of re(4) in WOL configuration.
- Disable WOL_UCAST and WOL_MCAST capabilities by default.
- Config5 register write does not need to unlock EEPROM access
on RTL8139 family but unlocking EEPROM access does not affect
its operation and make it consistent with re(4).

Reported by: Matt Renzelmann mjr <> cs dot wisc dot edu


# df2dc2b3 13-Feb-2012 Pyun YongHyeon <yongari@FreeBSD.org>

For RTL8168/8111D controller, make sure to wake PHY from power down
mode. Otherwise, PHY access times out under certain conditions.


# bc6b129b 19-Jan-2012 Pyun YongHyeon <yongari@FreeBSD.org>

Fix a logic error which resulted in putting PHY into sleep when WOL
is active. If WOL is active driver should not put PHY into sleep.
This change makes WOL work on RTL8168E.


# 1f32d3b7 17-Jan-2012 Pyun YongHyeon <yongari@FreeBSD.org>

Free allocated jumbo buffers when controller is stopped.


# cba16362 17-Jan-2012 Pyun YongHyeon <yongari@FreeBSD.org>

Use a RX DMA tag to free loaded RX DMA maps.
Previously it used a TX DMA tag.


# 579a6e3c 05-Dec-2011 Luigi Rizzo <luigi@FreeBSD.org>

add netmap support for "em", "lem", "igb" and "re".

On my hardware, "em" in netmap mode does about 1.388 Mpps
on one card (on an Asus motherboard), and 1.1 Mpps on another
card (PCIe bus). Both seem to be NIC-limited, because
i have the same rate even with the CPU running at 150 MHz.

On the "re" driver the tx throughput is around 420-450 Kpps
on various (8111C and the like) chipsets. On the Rx side
performance seems much better, and i can receive the full
load generated by the "em" cards.

"igb" is untested as i don't have the hardware.


# 6830588d 23-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

To save more power, switch to 10/100Mbps link when controller is
put into suspend/shutdown. Old PCI controllers performed that
operation in firmware but for RTL8111C or newer controllers, it's
responsibility of driver. It's not clear whether the firmware of
RTL8111B still downgrades its speed to 10/100Mbps so leave it as it
was.


# eef0e496 23-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Make sure to stop TX MAC before freeing queued TX frames.
For RTL8111DP, check if the TX MAC is active by reading RL_GTXSTART
register. For RTL8402/8168E-VL/8168F/8411, wait until TX queue is
empty.


# fcb220ac 22-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Disable accepting frames in re_stop() to put RX MAC into idle state.
Because there is no reliable way to know whether RX MAC is in
stopped state, rejecting all frames would be the only way to
minimize possible races.
Otherwise it's possible to receive frames while stop command
execution is in progress and controller can DMA the frame to freed
RX buffer during that period.
This was observed on recent PCIe controllers(i.e. RTL8111F).

While this change may not be required on old controllers it
wouldn't make negative effects on old controllers. One side effect
of this change is disabling receive so driver reprograms RL_RXCFG
to receive WOL frames when it is put into suspend or shutdown.

This should address occasional 'memory modified free' errors seen
on recent RealTek controllers.


# 1662c49e 22-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Perform media change after setting IFF_DRV_RUNNING flag. Without it,
driver would ignore the first link state update if controller
already established a link such that it would have to take
additional link state handling in re_tick().


# 44f7cbf5 22-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Writing access to RL_CFG5 register also requires EEPROM write
access.
While I'm here, enable WOL through magic packet but disable waking
up system via unicast, multicast and broadcast frames. Otherwise,
multicast or unicast frame(e.g. ICMP echo request) can wake up
system which is not probably wanted behavior on most environments.
This was not known as problem because RL_CFG5 register access had
not effect until this change.
The capability to wake up system with unicast/multicast frames
are still set in driver, default off, so users who need that
feature can still activate it with ifconfig(8).


# 4b7ec270 22-Nov-2011 Marius Strobl <marius@FreeBSD.org>

- There's no need to overwrite the default device method with the default
one. Interestingly, these are actually the default for quite some time
(bus_generic_driver_added(9) since r52045 and bus_generic_print_child(9)
since r52045) but even recently added device drivers do this unnecessarily.
Discussed with: jhb, marcel
- While at it, use DEVMETHOD_END.
Discussed with: jhb
- Also while at it, use __FBSDID.


# d467ffaa 17-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8168/8111F PCIe Gigabit ethernet.

H/W donated by: RealTek Semiconductor Corp.


# 6b0a8e04 17-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for second generation RTL8105E PCIe
FastEthernet.

H/W donated by: RealTek Semiconductor Corp.


# 017f1c8d 16-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Disable PCIe ASPM (Active State Power Management) for all
controllers.
More and more RealTek controllers started to implement EEE feature.
Vendor driver seems to load a kind of firmware for EEE with
additional PHY fixups. It is known that the EEE feature may need
ASPM support. Unfortunately there is no documentation for EEE of
the controller so enabling ASPM may cause more problems.


# 600af6c2 16-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add missing driver lock in SIOCSIFCAP handler.


# d56f7f52 16-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8411 PCIe Gigabit ethernet with
integrated card reader.

H/W donated by: RealTek Semiconductor Corp.


# a9e3362a 16-Nov-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for RTL8402 PCIe FastEthernet with
integrated card reader.

H/W donated by: RealTek Semiconductor Corp.


# b3030306 02-Nov-2011 Marius Strobl <marius@FreeBSD.org>

Sprinkle some const.


# 57c81d92 17-Oct-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Close a race where SIOCGIFMEDIA ioctl get inconsistent link status.
Because driver is accessing a common MII structure in
mii_pollstat(), updating user supplied structure should be done
before dropping a driver lock.

Reported by: Karim (fodillemlinkarimi <> gmail dot com)


# caa19d50 29-Jul-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add new device id of D-Link DGE-530T Rev. C controller. DGE-503T
Rev A1 and B1 is supported by sk(4) but the DGE-530T Rev. C
controller is re-branded RealTek 8169 controller.

PR: kern/159116
Approved by: re (kib)


# 3b0a4aef 23-Mar-2011 John Baldwin <jhb@FreeBSD.org>

Do a sweep of the tree replacing calls to pci_find_extcap() with calls to
pci_find_cap() instead.


# 39e69201 16-Feb-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add initial support for RTL8401E PCIe Fast Ethernet.

PR: 154789


# bc2a1002 04-Feb-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Disable TX IP checksum offloading for RTL8168C controllers. The
controller in question generates frames with bad IP checksum value
if packets contain IP options. For instance, packets generated by
ping(8) with record route option have wrong IP checksum value. The
controller correctly computes checksum for normal TCP/UDP packets
though.
There are two known RTL8168/8111C variants in market and the issue
I observed happened on RL_HWREV_8168C_SPIN2. I'm not sure
RL_HWREV_8168C also has the same issue but it would be better to
assume it has the same issue since they shall share same core.
RTL8102E which is supposed to be released at the time of
RTL8168/8111C announcement does not have the issue.

Tested by: Konstantin V. Krotov ( kkv <> insysnet dot ru )


# 54899a96 26-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add support for RTL8105E PCIe Fast Ethernet controller. It seems
the controller has a kind of embedded controller/memory and vendor
applies a large set of magic code via undocumented PHY registers in
device initialization stage. I guess it's a firmware image for the
embedded controller in RTL8105E since the code is too big compared
to other DSP fixups. However I have no idea what that magic code
does and what's purpose of the embedded controller. Fortunately
driver seems to still work without loading the firmware.

While I'm here change device description of RTL810xE controller.

H/W donated by: Realtek Semiconductor Corp.


# 502be0f7 26-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Do not use interrupt taskqueue on controllers with MSI/MSI-X
capability. One of reason using interrupt taskqueue in re(4) was
to reduce number of TX/RX interrupts under load because re(4)
controllers have no good TX/RX interrupt moderation mechanism.
Basic TX interrupt moderation is done by hardware for most
controllers but RX interrupt moderation through undocumented
register showed poor RX performance so it was disabled in r215025.
Using taskqueue to handle RX interrupt greatly reduced number of
interrupts but re(4) consumed all available CPU cycles to run the
taskqueue under high TX/RX network load. This can happen even with
RTL810x fast ethernet controller and I believe this is not
acceptable for most systems.

To mitigate the issue, use one-shot timer register to moderate RX
interrupts. The timer register provides programmable one-shot timer
and can be used to suppress interrupt generation. The timer runs at
125MHZ on PCIe controllers so the minimum time allowed for the
timer is 8ns. Data sheet says the register is 32 bits but
experimentation shows only lower 13 bits are valid so maximum time
that can be programmed is 65.528us. This yields theoretical maximum
number of RX interrupts that could be generated per second is about
15260. Combined with TX completion interrupts re(4) shall generate
less than 20k interrupts. This number is still slightly high
compared to other intelligent ethernet controllers but system is
very responsive even under high network load.

Introduce sysctl variable dev.re.%d.int_rx_mod that controls amount
of time to delay RX interrupt processing in units of us. Value 0
completely disables RX interrupt moderation. To provide old
behavior for controllers that have MSI/MSI-X capability, introduce
a new tunable hw.re.intr_filter. If the tunable is set to non-zero
value, driver will use interrupt taskqueue. The default value of
the tunable is 0. This tunable has no effect on controllers that
has no MSI/MSI-X capability or if MSI/MSI-X is explicitly disabled
by administrator.

While I'm here cleanup interrupt setup/teardown since re(4) uses
single MSI/MSI-X message at this moment.


# d180a66f 25-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Remove TX taskqueue and directly invoke re_start in interrupt task.


# 4a58fd45 25-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Prefer MSI-X to MSI on controllers that support MSI-X. All
recent PCIe controllers(RTL8102E or later and RTL8168/8111C or
later) supports either 2 or 4 MSI-X messages. Unfortunately vendor
did not publicly release RSS related information yet. However
switching to MSI-X is one-step forward to support RSS.


# f9ad4da7 25-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Disable TSO for all Realtek controllers. Experimentation showed
RTL8111C generated corrupted frames where TCP option header was
broken. All other sample controllers I have did not show such
problem so it could be RTL8111C specific issue. Because there are
too many variants it's hard to tell how many controllers have such
issue. Just disable TSO by default but have user override it.


# 7be4de2d 23-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Apply TX interrupt moderation to all RTL810xE PCIe Fast Ethernet
controllers. Experimentation with RTL8102E, RTL8103E and RTL8105E
showed dramatic decrement of TX completion interrupts under high TX
load(e.g. from 147k interrupts/second to 10k interrupts/second)
With this change, TX interrupt moderation is applied to all
controllers except RTL8139C+.


# ef278cb4 17-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Change model names of controller RTL_HWREV_8168_SPIN[123] to real ones.
s/RL_HWREV_8168_SPIN1/RL_HWREV_8168B_SPIN1/g
s/RL_HWREV_8168_SPIN2/RL_HWREV_8168B_SPIN2/g
s/RL_HWREV_8168_SPIN3/RL_HWREV_8168B_SPIN3/g
No functional changes.


# 81eee0eb 16-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Implement initial jumbo frame support for RTL8168/8111 C/D/E PCIe
GbE controllers. It seems these controllers no longer support
multi-fragmented RX buffers such that driver have to allocate
physically contiguous buffers.

o Retire RL_FLAG_NOJUMBO flag and introduce RL_FLAG_JUMBOV2 to
mark controllers that use new jumbo frame scheme.
o Configure PCIe max read request size to 4096 for standard frames
and reduce it to 512 for jumbo frames.
o TSO/checksum offloading is not supported for jumbo frames on
these controllers. Reflect it to ioctl handler and driver
initialization.
o Remove unused rl_stats_no_timeout in softc.
o Embed a pointer to structure rl_hwrev into softc to keep track
of controller MTU limitation and remove rl_hwrev in softc since
that information is available through a pointer to structure
rl_hwrev.

Special thanks to Realtek for donating sample hardwares which made
this possible.

H/W donated by: Realtek Semiconductor Corp.


# f0431c5b 16-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Add initial support for RTL8168E/8111E-VL PCIe GbE.

H/W donated by: Realtek Semiconductor Corp.


# 4a814a5e 13-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

If driver is not able to allocate RX buffer, do not start driver.
While I'm here move RX buffer allocation and descriptor
initialization up to not touch hardware registers in case of RX
buffer allocation failure.


# 9e18005d 13-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Make sure to check validity of dma maps before destroying.


# 93252626 13-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

re_reset() should be called only after setting device specific
features.


# d3b181ae 13-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Allow TX/RX checksum offloading to be configured independently.


# 89feeee4 11-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

For re(4) controllers that uses new jumbo frame scheme(RTL8168C/D/E),
limit maximum RX buffer size to RE_RX_DESC_BUFLEN instead of
blindly configuring it to 16KB. Due to lack of documentation, re(4)
didn't allow jumbo frame on these controllers. However it seems
controller is confused with jumbo frame such that it can DMA the
received frame to wrong address instead of splitting it into
multiple RX buffers. Of course, this caused panic.

Since re(4) does not support jumbo frames on these controllers,
make controller drop frame that is longer than RE_RX_DESC_BUFLEN
sized frame. Fortunately RTL810x controllers, which do not support
jumbo frame, have no such issues but this change also limited
maximum RX buffer size allowed to RTL810x controllers. Allowing
16KB RX buffer for controllers that have no such capability is
meaningless.

MFC after: 3 days


# 16a4824b 10-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

When driver is not running, do not send DUMP command to controller
and just show old (cached) values. Controller will not respond to
the command unless MAC is enabled so DUMP request for down
interface caused request timeout.


# d6d7d923 10-Jan-2011 Pyun YongHyeon <yongari@FreeBSD.org>

Implement TSO on RealTek RTL8168/8111 C or later controllers.
RealTek changed TX descriptor format for later controllers so these
controllers require MSS configuration in different location of TX
descriptor. TSO is enabled by default for controllers that use new
descriptor format.
For old controllers, TSO is still disabled by default due to broken
frames under certain conditions but users can enable it.
Special thanks to Hayes Wang at RealTek.

MFC after: 2 weeks


# 64436f6e 14-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Add flow control for all re(4) controllers. re(4) controllers do
not provide any MAC configuration interface for resolved flow
control parameters. There is even no register that configures water
mark which will control generation of pause frames.
However enabling flow control surely enhanced performance a lot.


# 5e6906ee 08-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Only moderate TX completion interrupts. Relying on taskqueue to
suppress RX interrupts seems to give better RX performance than
RX interrupt moderation.


# 483cc440 08-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Follow the lead of vendor's interrupt moderation mechanism.
It seems RTL8169/RTL8168/RTL810xE has a kind of interrupt
moderation mechanism but it is not documented at all. The magic
value dramatically reduced number of interrupts without noticeable
performance drops so apply it to all RTL8169/RTL8169 controllers.
Vendor's FreeBSD driver also applies it to RTL810xE controllers but
their Linux driver explicitly cleared the register, so do not
enable interrupt moderation for RTL810xE controllers.

While I'm here sort 8169 specific registers.

Obtained from: RealTek FreeBSD driver


# 2bc085c6 08-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Reduce spin wait time consumed in GMII register access routine.
There were a couple of attempts in the past to reduce it since it
took more than 1ms. Because mii_tick() periodically polls link
status, waiting more than 1ms for each GMII register access was
overkill. Unfortunately all previous attempts were failed with
various ways on different controllers.
This time, add additional 20us dealy at the end of GMII register
access which seems to requirement of all RealTek controllers to
issue next GMII register access request. This is the same way what
Linux does.


# 0534aae0 05-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Add simple MAC statistics counter reading support. Unfortunately
useful counters like rl_missed_pkts is 16 bits quantity which is
too small to hold meaningful information happened in a second. This
means driver should frequently read these counters in order not to
lose accuracy and that approach is too inefficient in driver's
view. Moreover it seems there is no way to trigger an interrupt to
detect counter near-full or wraparound event as well as lacking
clearing the MAC counters. Another limitation of reading the
counters from RealTek controllers is lack of interrupt firing at
the end of DMA cycle of MAC counter read request such that driver
have to poll the end of the DMA which is a time consuming process
as well as inefficient. The more severe issue of the MAC counter
read request is it takes too long to complete the DMA. All these
limitation made maintaining MAC counters in driver impractical. For
now, just provide simple sysctl interface to trigger reading the
MAC counters. These counters could be used to track down driver
issues. Users can read MAC counters maintained in controller with
the following command.
#sysctl dev.re.0.stats=1

While I'm here add check for validity of dma map and allocated
memory before unloading/freeing them.

Tested by: rmacklem


# 63472df7 05-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

style(9).


# 4baa0310 05-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Remove extra white spaces.


# 66366ca4 05-Nov-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Enable 64bit DMA addressing for RTL810xE/RTL8168/RTL8111 PCIe
controllers. Some old PCI controllers may work with DAC but it was
known to be buggy so 64bit DMA addressing is used only on PCIe
controllers.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 8e5d93db 15-Oct-2010 Marius Strobl <marius@FreeBSD.org>

Convert the PHY drivers to honor the mii_flags passed down and convert
the NIC drivers as well as the PHY drivers to take advantage of the
mii_attach() introduced in r213878 to get rid of certain hacks. For
the most part these were:
- Artificially limiting miibus_{read,write}reg methods to certain PHY
addresses; we now let mii_attach() only probe the PHY at the desired
address(es) instead.
- PHY drivers setting MIIF_* flags based on the NIC driver they hang
off from, partly even based on grabbing and using the softc of the
parent; we now pass these flags down from the NIC to the PHY drivers
via mii_attach(). This got us rid of all such hacks except those of
brgphy() in combination with bce(4) and bge(4), which is way beyond
what can be expressed with simple flags.

While at it, I took the opportunity to change the NIC drivers to pass
up the error returned by mii_attach() (previously by mii_phy_probe())
and unify the error message used in this case where and as appropriate
as mii_attach() actually can fail for a number of reasons, not just
because of no PHY(s) being present at the expected address(es).

Reviewed by: jhb, yongari


# afe8083a 12-May-2010 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r207763:
Don't change PCIe maximum read request size to 2048 on RTL810x
controllers. It caused device timeouts.

Reported by: McLone < mclone <> gmail dot com >
Tested by: McLone < mclone <> gmail dot com >


# 485d41c0 07-May-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Don't change PCIe maximum read request size to 2048 on RTL810x
controllers. It caused device timeouts.

Reported by: McLone < mclone <> gmail dot com >
Tested by: McLone < mclone <> gmail dot com >
MFC after: 5 days


# 8451de87 13-Apr-2010 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r206433:
Add preliminary support for 8168E/8111E PCIe controller.
While I'm here simplify device description string.

Tested by: Michael Beckmann < michael <> apfel dot de >


# d0c45156 09-Apr-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Add preliminary support for 8168E/8111E PCIe controller.
While I'm here simplify device description string.

Tested by: Michael Beckmann < michael <> apfel dot de >
MFC after: 5 days


# d95d4a83 23-Mar-2010 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r204155,204219:
r204155:
Increase PCIe maximuim read request size to 2048. Because re(4) uses
Tx DMA burst size 2048, I beleive PCIe maximum read request size
also should match to the value of Tx DMA burst size. With this
change I can get more than 800Mbps for TCP bulk transfers.
Previously I was not able to get more than 700Mbps. If I enable TSO
it now shows 927Mbps.

r204219:
Add TSO on VLANs. Because re(4) has a TSO limitation for jumbo
frame, make sure to update VLAN capabilities whenever jumbo frame
is configured.
While I'm here rearrange interface capabilities configuration. The
controller requires VLAN hardware tagging to make TSO work on VLANs
so explicitly check this requirement.


# ecafbbb5 22-Feb-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Add TSO on VLANs. Because re(4) has a TSO limitation for jumbo
frame, make sure to update VLAN capabilities whenever jumbo frame
is configured.
While I'm here rearrange interface capabilities configuration. The
controller requires VLAN hardware tagging to make TSO work on VLANs
so explicitly check this requirement.


# 02d77e45 20-Feb-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Increase PCIe maximuim read request size to 2048. Because re(4) uses
Tx DMA burst size 2048, I beleive PCIe maximum read request size
also should match to the value of Tx DMA burst size. With this
change I can get more than 800Mbps for TCP bulk transfers.
Previously I was not able to get more than 700Mbps. If I enable TSO
it now shows 927Mbps.


# 0fb14c6f 01-Feb-2010 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r203082:
Add initial support for RTL8103E PCIe fastethernet.

PR: kern/142974


# 8281a098 27-Jan-2010 Pyun YongHyeon <yongari@FreeBSD.org>

Add initial support for RTL8103E PCIe fastethernet.

PR: kern/142974


# 9b96de94 03-Dec-2009 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r199565:
Move interface reinitialization down after disabling WOL in resume
path.


# 86032a41 03-Dec-2009 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r199564:
Minimize interface reinitialization by checking IFF_DRV_RUNNING
flag. This fixes unnecessary interface UP/DOWNs during getting an
IP address via DHCP.


# 2ff1d992 29-Nov-2009 Pyun YongHyeon <yongari@FreeBSD.org>

MFC 198814.
Add a check to know whether driver is still running after
reacquiring driver lock in Rx handler. re(4) drops a driver lock
before passing received frame to upper stack and reacquire the
lock. During the time window ioctl calls could be executed and if
the ioctl was interface down request, driver will stop the
controller and free allocated mbufs. After that when driver comes
back to Rx handler again it does not know what was happend so it
could access free mbufs which in turn cause panic.

Reported by: Norbert Papke < npapk <> acm dot org >
Tested by: Norbert Papke < npapk <> acm dot org >


# 01d1a6c3 19-Nov-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Move interface reinitialization down after disabling WOL in resume
path.


# 8476c243 19-Nov-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Minimize interface reinitialization by checking IFF_DRV_RUNNING
flag. This fixes unnecessary interface UP/DOWNs during getting an
IP address via DHCP.

Tested by: Warren Block ( wblock<> wonkity dot com )


# 5b6d1d9d 02-Nov-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Add a check to know whether driver is still running after
reacquiring driver lock in Rx handler. re(4) drops a driver lock
before passing received frame to upper stack and reacquire the
lock. During the time window ioctl calls could be executed and if
the ioctl was interface down request, driver will stop the
controller and free allocated mbufs. After that when driver comes
back to Rx handler again it does not know what was happend so it
could access free mbufs which in turn cause panic.

Reported by: Norbert Papke < npapk <> acm dot org >
Tested by: Norbert Papke < npapk <> acm dot org >


# 83b5def4 28-Aug-2009 Pyun YongHyeon <yongari@FreeBSD.org>

MFC r196516:
Add RTL8168DP/RTL8111DP device id. While I'm here append "8111D" to
the description of RTL8168D as RL_HWREV_8168D can be either
RTL8168D or RTL8111D.

PR: kern/137672
Approved by: re (kib)


# 5fa06abe 24-Aug-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Add RTL8168DP/RTL8111DP device id. While I'm here append "8111D" to
the description of RTL8168D as RL_HWREV_8168D can be either
RTL8168D or RTL8111D.

PR: kern/137672
MFC after: 3 days


# 3d22427c 13-Jul-2009 Tai-hwa Liang <avatar@FreeBSD.org>

Adding hardware ID for RTL810x PCIe found on HP Pavilion DV2-1022AX.

Reviewed by: yongari
Approved by: re (kib, kensmith)


# eb956cd0 26-Jun-2009 Robert Watson <rwatson@FreeBSD.org>

Use if_maddr_rlock()/if_maddr_runlock() rather than IF_ADDR_LOCK()/
IF_ADDR_UNLOCK() across network device drivers when accessing the
per-interface multicast address list, if_multiaddrs. This will
allow us to change the locking strategy without affecting our driver
programming interface or binary interface.

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

Approved by: re (kib)
MFC after: 6 weeks


# 1abcdbd1 30-May-2009 Attilio Rao <attilio@FreeBSD.org>

When user_frac in the polling subsystem is low it is going to busy the
CPU for too long period than necessary. Additively, interfaces are kept
polled (in the tick) even if no more packets are available.
In order to avoid such situations a new generic mechanism can be
implemented in proactive way, keeping track of the time spent on any
packet and fragmenting the time for any tick, stopping the processing
as soon as possible.

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

Bump __FreeBSD_version in order to signal such situation.

Reviewed by: emaste
Sponsored by: Sandvine Incorporated


# f2e491c9 20-Apr-2009 Pyun YongHyeon <yongari@FreeBSD.org>

For RTL8139C+ controllers, have controller handle padding short
checksum offload frames. Software workaround used for broken
controllers(RTL8169, RTL8168, RTL8168B) seem to cause watchdog
timeouts on RTL8139C+.
Introduce a new flag RL_FLAG_AUTOPAD to mark automatic padding
feature of controller and set it for RTL8139C+ and controllers that
use new descriptor format. This fixes watchdog timeouts seen on
RTL8139C+.

Reported by: Dimitri Rodis < DimitriR <> integritasystems dot com >
Tested by: Dimitri Rodis < DimitriR <> integritasystems dot com >


# bd9bede5 30-Mar-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Partial revert r185756.
It seems that RTL8168D and RTL8102EL requires additional settle
time to complete RL_PHYAR register write. Accessing RL_PHYAR
register right after the write causes errors for subsequent PHY
register accesses.

Tested by: george at luckytele dot com,
Steve Wills < STEVE at stevenwills dot com >


# aa11a83c 09-Mar-2009 Warner Losh <imp@FreeBSD.org>

remove now-redunant cardbus attachment lines.


# 2c21710b 09-Mar-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Add a new tunable hw.re.prefer_iomap which disables memory register
mapping. The tunable is OFF for all controllers except RTL8169SC
family. RTL8169SC seems to require more magic to use memory
register mapping. r187483 added a fix for RTL8169SCe controller but
it does not looke like fix other variants of RTL8169SC.

Tested by: Gavin Stone-Tolcher g.stone-tolcher <> its dot uq dot edu dot au


# f1bb696a 10-Feb-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Allocating 2 MSI messages do not seem to work on certain controllers
so use just 1 MSI message. This fixes regression introduced in
r188381.

Tested by: many


# c2d2e19c 08-Feb-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Reclaim transmitted frames in re_tick(). This is for PCIe
controllers that lose Tx completion interrupts under certain
conditions. With this change it's safe to use MSI on PCIe
controllers so enable MSI on these controllers.


# 566ca8ca 20-Jan-2009 Jung-uk Kim <jkim@FreeBSD.org>

- Add support for 8110SCe part. Some magic registers were taken from
Linux driver.
- Swap hardware revisions for 8110S and 8169S as Linux driver claims.

Reviewed by: yongari (early version)


# aaab4fbe 20-Jan-2009 Jung-uk Kim <jkim@FreeBSD.org>

Retire RL_FLAG_INVMAR bit to match its comment and reality.


# ff191365 20-Jan-2009 Jung-uk Kim <jkim@FreeBSD.org>

- Do not read and write RX configuration register multiple times.
- Always program RX configuration register from scratch instead of
doing read/modify/write.
- Rename re_setmulti() to re_set_rxmode() to be reflect reality.
- Simplify hash filter logic a little while I am here.

Reviewed by: yongari (early version)


# 96b774f4 18-Jan-2009 Pyun YongHyeon <yongari@FreeBSD.org>

Sometimes RTL8168B seems to take long time to access GMII registers
in device attach phase. Double GMII register access timeout value
to fix the issue.

Reported by: wkoszek
Tested by: wkoszek


# 0fe200d9 21-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Since we don't request reset for rlphy(4), the link state 'UP'
event from mii(4) may not be delivered if valid link was already
established. To address the issue, check current link state after
driving MII_TICK. This should fix a regression introduced in
r185753 on fast ethernet controllers.

Reported by: csjp, Bruce Cran < bruce <> cran DOT org DOT uk >
Tested by: csjp, Bruce Cran (initial version)


# 818951af 17-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

It seems that RealTek PCIe controllers require an explicit Tx poll
command whenever Tx completion interrupt is raised. The Tx poll
bit is cleared when all packets waiting to be transferred have been
processed. This means the second Tx poll command can be silently
ignored as the Tx poll bit could be still active while processing
of previous Tx poll command is in progress.
To address the issue re(4) used to invoke the Tx poll command in Tx
completion handler whenever it detects there are pending packets in
TxQ. However that still does not seem to completely eliminate
watchdog timeouts seen on RealTek PCIe controllers. To fix the
issue kick Tx poll command only after Tx completion interrupt is
raised as this would indicate Tx is now idle state such that it can
accept new Tx poll command again. While here apply this workaround
for PCIe based controllers as other controllers does not seem to
have this limitation.

Tested by: Victor Balada Diaz < victor <> bsdes DOT net >


# 61f45a72 16-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

For RTL8168C SPIN2 controllers, make sure to take the controller
out of sleep mode prior to accessing to PHY. This should fix device
attach failure seen on these controllers. Also enable the sleep
mode when device is put into sleep state.

PR: kern/123123, kern/123053


# 886ff602 10-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Make WOL work on RTL8168B. This controller seems to require
explicit command to enable Rx MAC prior to entering D3.

Tested by: Cyrus Rahman <crahman <> gmail DOT com>


# 0596d7e6 10-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Don't access undocumented register 0x82 on controllers that
have no such register. While here clear undocumented PHY
register 0x0B for RTL8110S.

Obtained from: RealTek FreeBSD driver


# ead8fc66 10-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Newer RealTek controllers requires setting stop request bit to
terminate active Tx/Rx operation.


# b659f1f0 10-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Always put controller into known state before device intialization.
While here remove re_reset calls invoked in system error case as
controller reset is always done in device initialization.


# f68bc089 10-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Partly revert r185756. RTL8169SC doesn't like reduced delays in
GMII access while Tx/Rx is in progress.

Reported by: Jaakko Heinonen <jh <> saunalahti DOT fi>,
Anton Yuzhaninov <citrin <> citrin DOT ru>
Tested by: Jaakko Heinonen <jh <> saunalahti DOT fi>


# b45fb248 07-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Reduce spin wait time consumed in GMII register access routines.
Waiting for 1ms for each GMII register access looks overkill and it
may also decrease overall performance of driver because re(4)
invokes mii_tick for every hz.

Tested by: rpaulo


# 130b6dfb 07-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

o Implemented miibus_statchg handler. It detects whether re(4)
established a valid link or not. In miibus_statchg handler add a
check for established link is valid one for the controller(e.g.
1000baseT is not a valid link for fastethernet controllers.)
o Added a flag RE_FLAG_FASTETHER to mark fastethernet controllers.
o Added additional check to know whether we've really encountered
watchdog timeouts or missed Tx completion interrupts. This change
may help to track down the cause of watchdog timeouts.
o In interrupt handler, removed a check for link state change
interrupt. Not all controllers have the bit and re(4) did not
rely on the event for a long time. In addition, re(4) didn't
request the interrupt in RL_IMR register.

Tested by: rpaulo


# 6f0f9b12 07-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Make sure to return the result of meida change request.
Previously it used to return success regardless of the result.


# 59ef640d 01-Dec-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Add 8168D support.

Submitted by: Andrew < andrewwtulloch <> gmail DOT com >


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 97cf11ec 05-Sep-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Read ethernet address from ID registers for RTL8102E/RTL8102EL as
reading from EEPROM doesn't seem to work on these controllers.

Reported by: Milan Obuch ( freebsd-net at dino dot sk )
Tested by: Milan Obuch ( freebsd-net at dino dot sk )


# bddff934 12-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Fix VLAN hardware tag insertion/stripping on big-endian
architectures.

Reported by: naddy
Tested on: sparc64
MFC after: 1 week


# 3d85c23d 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Rearrange conditional compilation directives. This makes syntax
highlighting work in vim.


# 3199b0c4 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Remove return keyword at the end of functions that return void.


# 0ce0868a 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Remove register keyword.


# 7b5ffebf 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Use ANSI C declarations for all functions.


# a2a8420c 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Don't enable TSO by default. Users of RTL8169/8110 reported
watchdog timeout issues and the root cause seems to stem from
silicon bug of controller. Personally I couldn't reproduce it on
RTL8169 controller but it seems it's dependent on usage pattern.
For newer PCIe based controllers I have no TSO complaints but
turning off TSO would be more safe. Users who are sure that
their controller works with TSO can still reenable the TSO with
ifconfig(8).

Reported by: Oliver Lehmann (lehmann at ans-netz dot de), Eugene Butusov (ebutusov at gmail dot com)


# ae644087 03-Aug-2008 Pyun YongHyeon <yongari@FreeBSD.org>

The number of bits reserved for MSS in RealTek controllers is
11bits. This limits the maximum interface MTU size in TSO case
as upper stack should not generate TCP segments with MSS greater
than the limit. Armed with this information, disable TSO if
interface MTU is greater than the limit.


# b1d62f0f 08-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Add driver support for RTL8102E and RTL8102EL which is the second
generation of RTL810x PCIe fast ethernet controller. Note, Tx/Rx
descriptor format is different from that of first generation of
RTL8101E series. Jumbo frame is not supported for RTL810x
family.

Tested by: NAGATA Shinya ( maya AT negeta DOT com )


# 47fac8e5 08-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Disable jumbo frame support for RTL810x fast ethernet controllers.


# 715922d7 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Add a new RTL8169 variant, 8169SB(L)/8110SB(L).

Reported by: nork
Tested by: nork


# deb5c680 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Add basic support for RTL8168C, RTL8168CP, RTL8111C and RTL8111CP.
ATM Tx/Rx checksum offload is supported but TSO and jumbo frame is
not yet supported. Because these newer controllers use different
descriptor formats, a flag RL_FLAG_DESCV2 flag was introduced to
handle that case in Tx/Rx handler. Also newer controllers seems to
require to not touch 'enable Tx/Rx bit' in RL_CPLUS_CMD register
so don't blindly try to set that bits.

Note, it seems that there is still power-saving related issue where
driver fails to attach PHY. Rebooting seems to fix that issue but
number of required reboots varys.

Many thanks to users that helped during developement. I really
appreciate their patient and test/feedbacks.


# a810fc83 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Display detected chip revision in device attach. This will help to
diagnose revision specific issues in future. Also add 0x to notify
that the revision number is in hex form.


# 4d2bf239 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

If MSI is not active make sure to disable MSI in EEPROM.


# 81cf2eb6 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

In device detach don't access ifnet structure unless device is
attached. This fixes NULL pointer dereference when polling(9) is
active and unsupported hardware is detected in device attach.


# 3021aef8 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Toggling IFF_ALLMULTI flag does not require full interface
reintialization.


# 351a76f9 02-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Instead of allocating variables for each events/hardware flags, use
a dedicated flag that represents controller capabilities/events.
This will simplify many part of code that requires different
workaround for each controller revisions and will enhance
readability.
While I'm here move PHY wakeup code up before mii_phy_probe() which
seems to help to wake PHY in some cases.


# ace7ed5d 01-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Switch to memory space register mapping over IO space. If that
mapping fails fall back to traditional IO space access.


# f98dd8cf 01-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

While accessing EEPROM command register use pre-defined constant
instead of hardcoded value.


# 9dfcacbe 01-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

After the change of r176757 re(4) no longer relys on reading
RL_TXCFG register to identify a device in device probe. Reflect the
fact by modifing device description with general ethernet
controller family.
Note, rl_basetype in struct rl_type is not used and the more
detailed information is provided with rl_hwrev structure.


# dd6bd666 01-Jul-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Remove duplicated H/W revision check.


# 339a44fb 14-Apr-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Don't touch MSI enable bit in RL_CFG2 register. For unknown reason
clearing MSI enable bit for MSI capable hardwares resulted in Tx
problems. MSI enable bit is set only when MSI is requested from
user.

Tested by: remko


# a4148af5 30-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Padding more bytes than necessary one broke another variants of
PCIe RealTek chips. Only pad IP packets if the payload is less than
28 bytes.

Obtained from: NetBSD
PR: kern/122221


# 99c8ae87 27-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

In revision 1.70, 1.71 and 1.84 re(4) tried to workaround checksum
offload bugs by manual padding for short IP/UDP frames. Unfortunately
it seems that these workaround does not work reliably on newer PCIe
variants of RealTek chips.

To workaround the hardware bug, always pad short frames if Tx IP
checksum offload is requested. It seems that the hardware has a
bug in IP checksum offload handling. NetBSD manually pads short
frames only when the length of IP frame is less than 28 bytes but I
chose 60 bytes to safety. Also unconditionally set IP checksum
offload bit in Tx descriptor if any TCP or UDP checksum offload is
requested. This is the same way as Linux does but it's not
mentioned in data sheet.

Obtained from: NetBSD
Tested by: remko, danger


# 2000cf6c 22-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

MSI handling on some RealTek chips are broken so disable it by
default.

Reported by: Giulio Ferro ( auryn AT zirakzigil DOT org )
Tested by: Giulio Ferro ( auryn AT zirakzigil DOT org )


# 03ca7ae8 22-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

For MSI capable hardwares, enable MSI enable bit in RL_CFG2
register. If MSI was disabled by hw.re.msi_disable tunable
expliclty clear the MSI enable bit.


# ce628393 22-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Some RealTek chips are known to be buggy on DAC handling, so
disable DAC by default.


# ccf34c81 22-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

VLAN hardware tag information should be set for all desciptors of a
multi-descriptor transmission attempt. Datasheet said nothing about
this requirements. This should fix a long-standing VLAN hardware
tagging issues with re(4).

Reported by: Giulio Ferro ( auryn AT zirakzigil DOT org )
Tested by: Giulio Ferro ( auryn AT zirakzigil DOT org )


# 70acaecf 22-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Always honor configured VLAN/checksum offload capabilities.
Previously re(4) used to blindly enable VLAN hardware tag stripping
and Rx checksum offload regardless of enabled optional features of
interface.


# dfdb409e 02-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Don't map memory/IO resource in device probe and just use PCI
vendor/revision/sub device id of the hardware to probe it.
This is the same way as NetBSD does and it enhances readabilty
a lot.


# c1d0b573 02-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Don't allow jumbo frame on 8139C+ controller.
While I'm here add a check for minimal MTU length.


# 7467bd53 02-Mar-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Implement WOL.

Tested by: Fabian Keil ( freebsd-listen AT fabienkeli DOT de )


# 304a4c6f 17-Jan-2008 John Baldwin <jhb@FreeBSD.org>

- Retire npe_defrag(), gem_defrag(), msk_defrag(), nfe_defrag(), and
re_defrag() and use m_collapse() instead.
- Replace a reference to ath_defrag() in a comment in if_wpi.c with
m_collapse().


# 738489d1 14-Jan-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Fix build.


# d65abd66 14-Jan-2008 Pyun YongHyeon <yongari@FreeBSD.org>

Overhaul re(4).
o Increased number of Rx/Tx descriptors to 256 for 8169 GigEs
because it's hard to push the hardware to the limit with default
64 descriptors.
TSO requires large number of Tx descriptors to pass a full sized
TCP segment(65535 bytes IP packet) to hardware. Previously it
consumed 32 Tx descriptors, assuming MCLBYTES DMA segment size,
to send the TCP segment which means re(4) couldn't queue more
than two full sized IP packets.
For 8139C+ it still uses 64 Rx/Tx descriptors due to its hardware
limitations. With this changes there are (very) small waste of
memory for 8139C+ users but I don't think it would affect 8139C+
users for most cases.
o Various bus_dma(9) fixes.
- The hardware supports DAC so allow 64bit DMA operations.
- Removed BUS_DMA_ALLOC_NOW flag.
- Increased DMA segment size to 4096 from MCLBYTES because TSO
consumes too many descriptors with MCLBYTES DMA segment size.
- Tx/Rx side bus_dmamap_load_mbuf_sg(9) support. With these
changes the code is more readable than previous one and got a
(slightly) better performance as it doesn't need to pass/
decode arguments to/from callback function.
- Removed unnecessary callback function re_dmamap_desc() and
nuked rl_dmaload_arg structure which was used in the callback.
- Additional protection for DMA map load failure. In case of
failure reuse current map instead of returning a bogus DMA
map.
- Deferred DMA map unloading/sync operation for maximum
performance until we really need to load new DMA map. If we
happen to reuse current map(e.g. input error) there is no need
to sync/unload/load again.
- The number of allowable Tx DMA segments for a mbuf chains are
now 32 instead of magic nseg value. If the number of available
Tx descriptors are short enough to send highly fragmented mbuf
chains an optimized re_defrag() is called to collapse mbuf
chains which is supposed to be much faster than m_defrag(9).
re_defrag() was borrowed from ath(4).
- Separated Rx/Tx DMA tag from a common DMA tag such that Rx DMA
tag correctly uses DMA maps that were created with DMA alignment
restriction(8bytes alignments). Tx DMA tag does not have such
alignment limitation.
- Added additional sanity checks for DMA ring map load failure.
- Added additional spare Rx DMA map for graceful handling of Rx
DMA map load failure.
- Fixed misused bus_dmamap_sync(9) and added missing
bus_dmamap_sync(9) in re_encap()/re_txeof()/re_rxeof().
o Enabled TSO again as re(4) have reasonable number of Tx
descriptors.
o Don't touch DMA address of a Tx descriptor in re_txeof(). It's
not needed.
o Fix incorrect update of if_ierrors counter. For Rx buffer
shortage it should update if_qdrops as the buffer is reused.
o Added checks for unsupported H/W revisions and return ENXIO for
these hardwares. This is required to remove resource allocation
code in re_probe as other drivers do in device probe routine.
o Modified descriptor index manipulation macros as it's now possible
to have different number of descriptors for Rx/Tx.
o In re_start, to save a lock operation, use IFQ_DRV_IS_EMPTY before
trying to invoke IFQ_DRV_DEQUEUE. Also don't blindly call re_encap
since we already know the number of available Tx descriptors in
advance.
o Removed RL_TX_DESC_THLD which was used to reserve RL_TX_DESC_THLD
descriptors in Tx path. There is no such a limitation mentioned in
8139C+/8169/8110/8168/8101/8111 datasheet and it seems to work ok
without reserving RL_TX_DESC_THLD descriptors.
o Fix a comment for RL_GTXSTART. The register is 8bits register.
o Added comments for 8169/8139C+ hardware restrictions on descriptors.
o Removed forward declaration for "struct rl_softc", it's not needed.
o Added a new structure rl_txdesc for Tx descriptor managements and
a structure rl_rxdesc for Rx descriptor managements.
o Removed unused member variable rl_intlock in driver softc. There are
still several unused member variables which are supposed to be used
to access hardware statistics counters. But it seems that accessing
hardware counters were not implemented yet.


# a0637caa 20-Dec-2007 Pyun YongHyeon <yongari@FreeBSD.org>

By definition promiscuous mode should see all unicast frames as well
as multicast/broadcast frames. Previously re(4) ignored multicast
frames in promiscuous mode. The RTL8169 datasheet was not clear
how it handles multicast frames in promiscuous mode.

PR: kern/118572
MFC after: 3 days


# 1acbb78a 07-Dec-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Add another RTL8168 revision 3 which is found on RTL8111-GR Gigabit
Ethernet Controller. Multicast filtering wasn't tested and needs more
expore. While I'm here change complex if statements with switch
statement which would improve readability.

Reported by: Abdullah Ibn Hamad Al-Marri < wearabnet AT yahoo DOT ca >
Tested by: Abdullah Ibn Hamad Al-Marri < wearabnet AT yahoo DOT ca >


# 7c103000 02-Dec-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Always honor promiscuous flag prior to programming Rx multicast
filter. This fixes a regression introduced in rev 1.89.

PR: 114632
MFC after: 3 days


# 6a087a87 21-Nov-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Fix function prototype for device_shutdown method.


# 3b9982e5 12-Nov-2007 Remko Lodder <remko@FreeBSD.org>

Add support for D-Link DGE-528(T) Rev.B1

PR: 112774
Submitted by: Denis Fortin <fortin at acm dot org>
Approved by: imp (mentor), yongari
MFC After: 3 days


# c4aca09a 13-Aug-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Make sure to take PHY out of power down mode in device attach.
Without this the PHY wouldn't work as expected. This should fix
dual-boot Windows XP machine where RealTek Windows drivers put the
PHY in power down mode during shutdown. The magic PHY register
accesses come from RealTek driver. No datasheets mention the magic
PHY registers.
In general, the PHY wakeup code should go into PHY driver. However it
seems that it only apply to RTL8169S single chip and it would be
another hack if we have rgephy(4) check what parent driver/chip model
is attached.

Reported by: lofi, Laurens Timmermans ( laurens AT timkapel DOT nl )
Tested by: lofi
Obtained from: RealTek FreeBSD driver
Approved by: re (Ken Smith)


# 92825635 05-Aug-2007 Marius Strobl <marius@FreeBSD.org>

Initialize the rl_vlanctl field of the descriptors to zero (in order
to clear RL_TDESC_VLANCTL_TAG). This fixes sending packets in the
native VLAN when running both tagged and an untagged VLAN over the
same trunk and descriptors are recycled.

Approved by: re (kensmith)
MFC after: 1 week


# 4693e424 26-Jul-2007 Pyun YongHyeon <yongari@FreeBSD.org>

style(9)

Pointed out by: cnst
Approved by: re (kensmith)


# 5774c5ff 23-Jul-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Add MSI support.
Ever since switching to adaptive polling re(4) occasionally spews
watchdog timeouts on systems with MSI capability. This change is
minimal one for supporting MSI and re(4) also needs MSIX support
for RTL8111C in future. Because softc structure of re(4) is shared
with rl(4), rl(4) was touched to use the modified softc.

Reported by: cnst
Tested by: cnst
Approved by: re (kensmith)


# 141f92e7 05-Jul-2007 Pyun YongHyeon <yongari@FreeBSD.org>

re(4) devices requires an external EEPROM. Depending on models it
would be 93C46(1Kbit) or 93C56(2Kbit). One of differences between them
is number of address lines required to access the EEPROM. For example,
93C56 EEPROM needs 8 address lines to read/write data. If 93C56
recevied premature end of required number of serial clock(CLK) to set
OP code/address of EEPROM, the result would be unexpected behavior.
Previously it tried to detect 93C46, which requires 6 address lines,
and then assumed it would be 93C56 if read data was not expected
value. However, this approach didn't work in some models/situations
as 93C56 requries 8 address lines to access its data. In order to fix
it, change EEPROM probing order such that 93C56 is detected reliably.

While I'm here change hard-coded address line numbers with defined
constant to enhance readability.

PR: 112710
Approved by: re (mux)


# f28a171c 15-Jun-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Disable TSO support.
Without bus_dma clean up and increment of number of Tx descriptors
it's hard to guarantee correct Tx operation in TSO case. The TSO
support would be enabled again when I get more feeback from re(4)
patch posted to current.


# eed497bb 17-Apr-2007 Pyun YongHyeon <yongari@FreeBSD.org>

Don't reinitialize the hardware if only PROMISC flag was changed.
Previously whenever PROMISC mode turned on/off link renegotiation
occurs and it could resulted in network unavailability for serveral
seconds.(Depending on switch STP settings it could last several tens
seconds.)

Reported by: Prokofiev S.P. < proks AT logos DOT uptel DOT net >
Tested by: Prokofiev S.P. < proks AT logos DOT uptel DOT net >


# 2ee2c3b4 28-Mar-2007 Remko Lodder <remko@FreeBSD.org>

Add support for the RTL8110SC driver.

PR: 110804
Submitted by: Daan Vreeken
Sponsored by: Vitsch Electronics (patch)
Approved by: imp (mentor)
MFC After: 3 days


# 59a0d28b 03-Mar-2007 Christian S.J. Peron <csjp@FreeBSD.org>

Catch up the rest of the drivers with the ether_vlan_mtap modifications.
If these drivers are setting M_VLANTAG because they are stripping the
layer 2 802.1Q headers, then they need to be re-inserting them so any
bpf(4) peers can properly decode them.

It should be noted that this is compiled tested only.

MFC after: 3 weeks


# 3d4c1b57 27-Feb-2007 John Baldwin <jhb@FreeBSD.org>

Use taskqueue_drain() to wait for any pending tasks to complete rather
than just pausing for a second.


# ef544f63 22-Feb-2007 Paolo Pisati <piso@FreeBSD.org>

o break newbus api: add a new argument of type driver_filter_t to
bus_setup_intr()

o add an int return code to all fast handlers

o retire INTR_FAST/IH_FAST

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

Reviewed by: many
Approved by: re@


# e2bcb489 25-Jan-2007 Bill Paul <wpaul@FreeBSD.org>

The TCP checksum offload handling in the 8111B/8168B and 8101E PCIe can
apparently be confused by short TCP segments that have been manually
padded to the minimum ethernet frame size. The driver does short frame
padding in software as a workaround for a bug in the 8169 PCI devices
that causes short IP fragments to be corrupted due to an apparent
conflict between the hardware autopadding and hardware IP checksumming.

To fix this, we avoid software padding for short TCP segments, since
the hardware seems to autopad and checksum these correctly (even the
older 8169 NICs get these right). Short UDP packets appear to be
handled correctly in all cases. This should work around the IP header
checksum bug in the 8169 while not tripping the TCP checksum bug in
the 8111B/8168B and 8101E.


# d01fac16 22-Jan-2007 Pyun YongHyeon <yongari@FreeBSD.org>

It seems that enabling Tx and Rx before setting descriptor DMA
addresses shall access invalid descriptor DMA addresses on PCIe
hardwares and then panicked the system.
To fix it set descriptor DMA addresses before enabling Tx and Rx
such that hardware can see valid descriptor DMA addresses. Also
set RL_EARLY_TX_THRESH before starting Tx and Rx.

Reported by: steve.tell AT crashmail DOT de
Tested by: steve.tell AT crashmail DOT de
Obtained from: NetBSD
MFC after: 1 week


# b4b95879 16-Jan-2007 Marius Strobl <marius@FreeBSD.org>

o In re_newbuf() and re_encap() if re_dma_map_desc() aborts the mapping
operation as it ran out of free descriptors or if there are too many
segments in the first place, call bus_dmamap_unload() in order to
unload the already loaded segments.
For trying to map the defragmented mbuf (chain) in re_encap() this
introduces re_dma_map_desc() setting arg.rl_maxsegs to 0 as a new
failure mode. Previously we just ignored this case, corrupting our
view of the TX ring.
o In re_txeof():
- Don't clear IFF_DRV_OACTIVE unless there are at least 4 free TX
descriptors. Further down the road re_encap() will bail if there
aren't at least 4 free TX descriptors, causing re_start() to
abort and prepend the dequeued mbuf again so it makes no sense
to pretend we could process mbufs again when in fact we won't.
While at it replace this magic 4 with a macro RL_TX_DESC_THLD
throughout this driver.
- Don't cancel the watchdog timeout as soon as there's at least one
free TX descriptor but instead only if all descriptors have been
handled. It's perfectly normal, especially in the DEVICE_POLLING
case, that re_txeof() is called when only a part of the enqueued
TX descriptors have been handled, causing the watchdog to be
disarmed prematurely.
o In re_encap():
- If m_defrag() fails just drop the packet like other NIC drivers
do. This should only happen when there's a mbuf shortage, in which
case it was possible to end up with an IFQ full of packets which
couldn't be processed as they couldn't be defragmented as they
were taking up all the mbufs themselves. This includes adjusting
re_start() to not trying to prepend the mbuf (chain) if re_encap()
has freed it.
- Remove dupe initialization of members of struct rl_dmaload_arg to
values that didn't change since trying to process the fragmented
mbuf chain.
While at it remove an unused member from struct rl_dmaload_arg.
o In re_start() remove a abandoned, banal comment. The corresponding
code was moved to re_attach() some time ago.

With these changes re(4) now survives one day (until stopped) of
hammering out packets here.

Reviewed by: yongari
MFC after: 2 weeks


# bb7dfefb 11-Jan-2007 Bill Paul <wpaul@FreeBSD.org>

Fix re_setmulti() so that it works correctly for PCIe chips where
the multicast hash table are in reverse order compared to older
devices.


# 1d545c7a 19-Dec-2006 Marius Strobl <marius@FreeBSD.org>

- Use the re_tick() callout instead of if_slowtimo() for driving
re_watchdog() in order to avoid races accessing if_timer.
- Use bus_get_dma_tag() so re(4) works on platforms requiring it.
- Remove invalid BUS_DMA_ALLOCNOW when creating the parent DMA tag
and the tags that are used for static memory allocations.
- Don't bother to set if_mtu to ETHERMTU, ether_ifattach() does that.
- Remove an unused variable in re_intr().


# b61178a9 20-Nov-2006 Pyun YongHyeon <yongari@FreeBSD.org>

Fix typo.


# dc74159d 20-Nov-2006 Pyun YongHyeon <yongari@FreeBSD.org>

Add TSO support.

Tested by: wilko, Pieter de Goeje < pieter AT degoeje DOT nl >


# 960fd5b3 20-Nov-2006 Pyun YongHyeon <yongari@FreeBSD.org>

o Correctly set IFCAP_VLAN_HWCSUM as re(4) can do VLAN tagging/checksum
offloading in hardware.
o Correctly set media header length for VLAN.


# 19ecd231 20-Nov-2006 Pyun YongHyeon <yongari@FreeBSD.org>

Don't set RL_CFG1_FULLDUPLEX bit. The RL_CFG1_FULLDUPLEX bit in
config register 1 is only valid on 8129.


# 78ba57b9 17-Sep-2006 Andre Oppermann <andre@FreeBSD.org>

Move ethernet VLAN tags from mtags to its own mbuf packet header field
m_pkthdr.ether_vlan. The presence of the M_VLANTAG flag on the mbuf
signifies the presence and validity of its content.

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

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

to mark the packet m with the specified VLAN tag.

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

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

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

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

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

Reviewed by: thompsa, yar
Sponsored by: TCP/IP Optimization Fundraise 2005


# 6b9f5c94 15-Sep-2006 Gleb Smirnoff <glebius@FreeBSD.org>

- Consistently use if_printf() only in interface methods: if_start(),
if_watchdog, etc., or in functions used only in these methods.
In all other functions in the driver use device_printf().
- Use __func__ instead of typing function name.

Submitted by: Alex Lyashkov <umka sevcity.net>


# baa12772 07-Sep-2006 Pyun YongHyeon <yongari@FreeBSD.org>

Make 8139C+ work again which was broken since rev 1.68.
Ever since rev 1.68 re(4) checks the validity of link in re_start.
But rlphy(4) got a garbled data due to a different bit layout used on
8139C+ and it couldn't report correct link state. To fix it, ignore
BMCR_LOOP and BMCR_ISO bits which have different meanings on 8139C+.
I think this also make dhclient(8) work on 8139C+.

Reported by: Gerrit Kuehn <gerrit AT pmp DOT uni-hannover DOT de>
Tested by: Gerrit Kuehn <gerrit AT pmp DOT uni-hannover DOT de>


# be099007 02-Aug-2006 Pyun YongHyeon <yongari@FreeBSD.org>

Fix re(4) breakge introduced in tree from rev 1.68.
This should fix incorrect configuration of station address on
big-endian architectures.

Reviewed by: wpaul
Tested on: sparc64


# 0fc4974f 01-Aug-2006 Bill Paul <wpaul@FreeBSD.org>

Another small update to the re(4) driver:

- Change the workaround for the autopad/checksum offload bug so that
instead of lying about the map size, we actually create a properly
padded mbuf and map it as usual. The other trick works, but is ugly.
This approach also gives us a chance to zero the pad space to avoid
possibly leaking data.

- With the PCIe devices, it looks issuing a TX command while there's
already a transmission in progress doesn't have any effect. In other
words, if you send two packets in rapid succession, the second one may
end up sitting in the TX DMA ring until another transmit command is
issued later in the future. Basically, if re_txeof() sees that there
are still descriptors outstanding, it needs to manually resume the
TX DMA channel by issuing another TX command to make sure all
transmissions are flushed out. (The PCI devices seem to keep the
TX channel moving until all descriptors have been consumed. I'm not
sure why the PCIe devices behave differently.)

(You can see this issue if you do the following test: plug an re(4)
interface into another host via crossover cable, and from the other
host do 'ping -c 2 <host with re(4) NIC>' to prime the ARP cache,
then do 'ping -c 1 -s 1473 <host with re(4) NIC>'. You're supposed
to see two packets sent in response, but you may only see one. If
you do 'ping -c 1 -s 1473 <host with re(4) NIC>' again, you'll
see two packets, but one will be the missing fragment from the last
ping, followed by one of the fragments from this ping.)

- Add the PCI ID for the US Robotics 997902 NIC, which is based on
the RTL8169S.

- Add a tsleep() of 1 second in re_detach() after the interrupt handler
is disconnected. This should allow any tasks queued up by the ISR
to drain. Now, I know you're supposed to use taskqueue_drain() for
this, but something about the way taskqueue_drain() works with
taskqueue_fast queues doesn't seem quite right, and I refuse to be
tricked into fixing it.


# 498bd0d3 30-Jul-2006 Bill Paul <wpaul@FreeBSD.org>

Fix the following bugs in re(4)

- Correct the PCI ID for the 8169SC/8110SC in the device list (I added
the macro for it to if_rlreg.h before, but forgot to use it.)

- Remove the extra interrupt spinlock I added previously. After giving it
some more thought, it's not really needed.

- Work around a hardware bug in some versions of the 8169. When sending
very small IP datagrams with checksum offload enabled, a conflict can
occur between the TX autopadding feature and the hardware checksumming
that can corrupt the outbound packet. This is the reason that checksum
offload sometimes breaks NFS: if you're using NFS over UDP, and you're
very unlucky, you might find yourself doing a fragmented NFS write where
the last fragment is smaller than the minimum ethernet frame size (60
bytes). (It's rare, but if you keep NFS running long enough it'll
happen.) If checksum offload is enabled, the chip will have to both
autopad the fragment and calculate its checksum header. This confuses
some revs of the 8169, causing the packet that appears on the wire
to be corrupted. (The IP addresses and the checksum field are mangled.)
This will cause the NFS write to fail. Unfortunately, when NFS retries,
it sends the same write request over and over again, and it keeps
failing, so NFS stays wedged.

(A simple way to provoke the failure is to connect the failing system
to a network with a known good machine and do "ping -s 1473 <badhost>"
from the good system. The ping will fail.)

Someone had previously worked around this using the heavy-handed
approahch of just disabling checksum offload. The correct fix is to
manually pad short frames where the TCP/IP stack has requested
checksum offloading. This allows us to have checksum offload turned
on by default but still let NFS work right.

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


# e6e13c3c 28-Jun-2006 Bill Paul <wpaul@FreeBSD.org>

Properly detect the RTL8168(B?) again. RealTek sent me a bunch of sample
cards: the chips are all marked "RTL8111B", but they put stickers on the
back that say "RTL8168B/8111B". The manual says there's only one HWREV code
for both the 8111B and 8168B devices, which is 0x30000000, but the cards
they sent me actually report HWREV of 0x38000000. Deciding to trust the
hardware in front of me rather than a possibly incorrect manual (it wouldn't
be the first time the HWREVs were incorrectly documented), I changed the
8168 revision code. It turns out this was a mistake though: 0x30000000
really is a valid for the 8168.

There are two possible reasons for there to be two different HWREVs:

1) 0x30000000 is used only for the 8168B and 0x38000000 is only for
the 8111B.
2) There were 8111/8168 rev A devices which both used code 0x30000000,
and the 8111B/8168B both use 0x38000000.

The product list on the RealTek website doesn't mention the existence of
any 8168/8111 rev A chips being in production though, and I've never seen
one, so until I get clarification from RealTek, I'm going to assume that
0x30000000 is just for the 8168B and 0x38000000 is for the 8111B only.

So, the HWREV code for the 8168 has been put back to 0x30000000,
a new 8111 HWREV code has been added, and there are now separate
entries for recognizing both devices in the device list. This will
allow all devices to work, though if it turns out I'm wrong I may
need to change the ID strings


# ed510fb0 26-Jun-2006 Bill Paul <wpaul@FreeBSD.org>

Add support for the RealTek 8169SC/8110SC and RTL8101E devices. The
latter is a PCIe 10/100 chip.

Finally fix the EEPROM reading code so that we can access the EEPROMs on all
devices. In order to access the EEPROM, we must select 'EEPROM programming'
mode, and then set the EEPROM chip select bit. Previously, we were setting
both bits simultaneously, which doesn't work: they must be set in the
right sequence.

Always obtain the station address from the EEPROM, now that EEPROM
reading works correctly.

Make the TX interrupt moderation code based on the internal timer
optional and turned off by default.

Make the re_diag() routine conditional and off by default. When it is
on, only use it for the original 8169, which was the only device that
that really needed it.

Modify interrupt handling to use a fast interrupt handler and fast
taskqeueue.

Correct the rgephy driver so that it only applies the DSP fixup for
PHY revs 0 and 1. Later chips are fixed and don't need the fixup.

Make the rgephy driver advertise both 1000_FD and 1000_HD bits in
autoneg mode. A couple of the devices don't autoneg correctly unless
configured this way.


# 16a67f53 24-May-2006 Gleb Smirnoff <glebius@FreeBSD.org>

Rename device name in the last commit. According to PR, the ID is
more likely to belong to chips of 8168 family.

PR: kern/96734
Submitted by: Sven Petai <hadara bsd.ee>


# e72f58bb 22-Mar-2006 Gleb Smirnoff <glebius@FreeBSD.org>

Add support for RTL8111B chip, that can be found on some mainboards,
for example ASUS P5PL2.

Tested by: Vadim Frolov <vadim uch.net>


# f051cb85 02-Mar-2006 Gleb Smirnoff <glebius@FreeBSD.org>

Correctly switch IFCAP_VLAN_HWTAGGING on and off.

Reported & tested by: Peter Blok <pblok bsd4all.org>


# 4d3d7085 20-Feb-2006 Bernd Walter <ticso@FreeBSD.org>

Copy MAC address to fix alignment problems.
Tested on alpha (AS600) with RTL8169S
Suggested by: jhb


# 23033eeb 13-Feb-2006 Gleb Smirnoff <glebius@FreeBSD.org>

Do not touch ifp->if_baudrate in miibus aware drivers.


# d147662c 18-Dec-2005 Gleb Smirnoff <glebius@FreeBSD.org>

- Fix VLAN_INPUT_TAG() macro, so that it doesn't touch mtag in
case if memory allocation failed.
- Remove fourth argument from VLAN_INPUT_TAG(), that was used
incorrectly in almost all drivers. Indicate failure with
mbuf value of NULL.

In collaboration with: yongari, ru, sam


# a9fe9149 21-Nov-2005 Gleb Smirnoff <glebius@FreeBSD.org>

Check IFF_DRV_RUNNING in the re_intr() loop. It can disappear,
since re_rxeof() drops the lock for some time.

Reported & tested by: XueFeng Deng <dsnofe yahoo.com.cn>


# 4a0d6638 11-Nov-2005 Ruslan Ermilov <ru@FreeBSD.org>

- Store pointer to the link-level address right in "struct ifnet"
rather than in ifindex_table[]; all (except one) accesses are
through ifp anyway. IF_LLADDR() works faster, and all (except
one) ifaddr_byindex() users were converted to use ifp->if_addr.

- Stop storing a (pointer to) Ethernet address in "struct arpcom",
and drop the IFP2ENADDR() macro; all users have been converted
to use IF_LLADDR() instead.


# 298bfdf3 21-Oct-2005 Warner Losh <imp@FreeBSD.org>

The controller -> device switch happened in 4.0, fix comment


# 26390635 14-Oct-2005 John Baldwin <jhb@FreeBSD.org>

Only allow the sk(4) driver to attach to revision 2 of the LinkSys EG1032
cards and teach the re(4) driver to attach to revision 3 cards.

Submitted by: Fredrik Lindberg fli+freebsd-current at shapeshifter dot se
MFC after: 2 weeks
Reviewed by: imp, mdodd


# f0796cd2 05-Oct-2005 Gleb Smirnoff <glebius@FreeBSD.org>

- Don't pollute opt_global.h with DEVICE_POLLING and introduce
opt_device_polling.h
- Include opt_device_polling.h into appropriate files.
- Embrace with HAVE_KERNEL_OPTION_HEADERS the include in the files that
can be compiled as loadable modules.

Reviewed by: bde


# 40929967 01-Oct-2005 Gleb Smirnoff <glebius@FreeBSD.org>

Big polling(4) cleanup.

o Axe poll in trap.

o Axe IFF_POLLING flag from if_flags.

o Rework revision 1.21 (Giant removal), in such a way that
poll_mtx is not dropped during call to polling handler.
This fixes problem with idle polling.

o Make registration and deregistration from polling in a
functional way, insted of next tick/interrupt.

o Obsolete kern.polling.enable. Polling is turned on/off
with ifconfig.

Detailed kern_poll.c changes:
- Remove polling handler flags, introduced in 1.21. The are not
needed now.
- Forget and do not check if_flags, if_capenable and if_drv_flags.
- Call all registered polling handlers unconditionally.
- Do not drop poll_mtx, when entering polling handlers.
- In ether_poll() NET_LOCK_GIANT prior to locking poll_mtx.
- In netisr_poll() axe the block, where polling code asks drivers
to unregister.
- In netisr_poll() and ether_poll() do polling always, if any
handlers are present.
- In ether_poll_[de]register() remove a lot of error hiding code. Assert
that arguments are correct, instead.
- In ether_poll_[de]register() use standard return values in case of
error or success.
- Introduce poll_switch() that is a sysctl handler for kern.polling.enable.
poll_switch() goes through interface list and enabled/disables polling.
A message that kern.polling.enable is deprecated is printed.

Detailed driver changes:
- On attach driver announces IFCAP_POLLING in if_capabilities, but
not in if_capenable.
- On detach driver calls ether_poll_deregister() if polling is enabled.
- In polling handler driver obtains its lock and checks IFF_DRV_RUNNING
flag. If there is no, then unlocks and returns.
- In ioctl handler driver checks for IFCAP_POLLING flag requested to
be set or cleared. Driver first calls ether_poll_[de]register(), then
obtains driver lock and [dis/en]ables interrupts.
- In interrupt handler driver checks IFCAP_POLLING flag in if_capenable.
If present, then returns.This is important to protect from spurious
interrupts.

Reviewed by: ru, sam, jhb


# d1754a9b 29-Sep-2005 John Baldwin <jhb@FreeBSD.org>

- Use if_printf() and device_printf() in re(4) and remove rl_unit from
the softc.
- Use callout_init_mtx() and rather than timeout/untimeout in both rl(4)
and re(4).
- Fix locking for ifmedia by locking the driver in the ifmedia handlers
rather than in the miibus functions. (re(4) didn't lock the mii stuff
at all!)
- Fix some locking in re_ioctl().

Note: the two drivers share the same softc declared in if_rlreg.h, so they
had to be change simultaneously.

MFC after: 1 week
Tested by: several on rl(4), none on re(4)


# ad4f426e 18-Sep-2005 Warner Losh <imp@FreeBSD.org>

Make sure that we call if_free(ifp) after bus_teardown_intr. Since we
could get an interrupt after we free the ifp, and the interrupt
handler depended on the ifp being still alive, this could, in theory,
cause a crash. Eliminate this possibility by moving the if_free to
after the bus_teardown_intr() call.


# 72293673 15-Sep-2005 Ruslan Ermilov <ru@FreeBSD.org>

Don't recommend re_detach() (like in vr(4)) as another
possible method to prevent panicing in interrupt handler
after re_shutdown(), sometimes seen on SMP systems.
This would work here only because re_detach() clears
IFF_UP (to prevent another race) and it was demonstrated
that it's not enough to call vr_detach() in vr_shutdown()
to prevent a panic.


# 525e6a87 15-Sep-2005 Ruslan Ermilov <ru@FreeBSD.org>

re_detach() fixes:

- Fixed if_free() logic screw-up that can either result
in freeing a NULL pointer or leaking "struct ifnet".
- Move if_free() after re_stop(); the latter accesses
"struct ifnet". This bug was masked by a previous bug.
- Restore the fix for a panic on detach caused by racing
with BPF detach code by Bill by moving ether_ifdetach()
after re_stop() and resetting IFF_UP; this got screwed
up in revs. 1.30 and 1.36.


# 536fde34 18-Aug-2005 Maxim Sobolev <sobomax@FreeBSD.org>

In re_shutdown() mark interface as down since otherwise we will panic if
interrupt comes in later on, which can happen in some uncommon cases.

Another possible fix is to call re_detach() instead of re_stop(), like
ve(4) does, but I am not sure if the latter is really RTTD, so that stick
with this one-liner for now.

PR: kern/80005
Approved by: silence on -arch, no reply from selected network gurus


# 13f4c340 09-Aug-2005 Robert Watson <rwatson@FreeBSD.org>

Propagate rename of IFF_OACTIVE and IFF_RUNNING to IFF_DRV_OACTIVE and
IFF_DRV_RUNNING, as well as the move from ifnet.if_flags to
ifnet.if_drv_flags. Device drivers are now responsible for
synchronizing access to these flags, as they are in if_drv_flags. This
helps prevent races between the network stack and device driver in
maintaining the interface flags field.

Many __FreeBSD__ and __FreeBSD_version checks maintained and continued;
some less so.

Reviewed by: pjd, bz
MFC after: 7 days


# 32aa5f0e 05-Aug-2005 Anton Berezin <tobez@FreeBSD.org>

Recognize D-Link DGE-528(T) Gigabit as an re(4) device.

Submitted by: Andrus Nomm <andrus@members.ee>
PR: 76780
MFC After: 1 week


# 13b203d0 02-Aug-2005 Robert Watson <rwatson@FreeBSD.org>

Modify device drivers supporting multicast addresses to lock if_addr_mtx
over iteration of their multicast address lists when synchronizing the
hardware address filter with the network stack-maintained list.

Problem reported by: Ed Maste (emaste at phaedrus dot sandvine dot ca>
MFC after: 1 week


# 8fd99e38 30-Jun-2005 Pyun YongHyeon <yongari@FreeBSD.org>

Use correct pointer type. This should fix non-functional re(4)
driver on 64bit architectures.

Approved by: re (scottl)


# cd036ec1 10-Jun-2005 Brooks Davis <brooks@FreeBSD.org>

Move if_alloc() up so it's before mii_phy_probe().


# fc74a9f9 10-Jun-2005 Brooks Davis <brooks@FreeBSD.org>

Stop embedding struct ifnet at the top of driver softcs. Instead the
struct ifnet or the layer 2 common structure it was embedded in have
been replaced with a struct ifnet pointer to be filled by a call to the
new function, if_alloc(). The layer 2 common structure is also allocated
via if_alloc() based on the interface type. It is hung off the new
struct ifnet member, if_l2com.

This change removes the size of these structures from the kernel ABI and
will allow us to better manage them as interfaces come and go.

Other changes of note:
- Struct arpcom is no longer referenced in normal interface code.
Instead the Ethernet address is accessed via the IFP2ENADDR() macro.
To enforce this ac_enaddr has been renamed to _ac_enaddr.
- The second argument to ether_ifattach is now always the mac address
from driver private storage rather than sometimes being ac_enaddr.

Reviewed by: sobomax, sam


# d4fcf3cb 28-May-2005 Yoshihiro Takahashi <nyan@FreeBSD.org>

Remove bus_{mem,p}io.h and related code for a micro-optimization on i386
and amd64. The optimization is a trivial on recent machines.

Reviewed by: -arch (imp, marcel, dfr)


# 37652939 12-Mar-2005 Max Laier <mlaier@FreeBSD.org>

Unbreak build with POLLING. I should really listen and test with NOTES
instead of the module build.


# 52732175 12-Mar-2005 Max Laier <mlaier@FreeBSD.org>

ALTQ support for re(4).

Submitted by: Chris Dionissopoulos, Theo Schlossnagle
PR: kern/78681
MFC after: 2 weeks


# d2b677bb 01-Mar-2005 Warner Losh <imp@FreeBSD.org>

Use BUS_PROBE_DEFAULT in preference to 0 and BUS_PROBE_LOW_PRIORITY in
preference to some random negative number to allow other drivers a
bite at the apple.


# 5fb99dca 22-Jan-2005 Warner Losh <imp@FreeBSD.org>

Bring in support for SUGOI LAN GIGA NIC made by System TALKS, Inc from
a RealTek 8169SB.

PR: 74262
Submitted by: Yoshikazu GOTO-san

# Submitter notes that he's unsure of the revision string for 8169SB


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# 328b4b87 04-Jan-2005 Olivier Houchard <cognet@FreeBSD.org>

Disable checksum offloading by default. It seems to produce corrupted packets
with some revisions of the chip (particularly when using multiple TX
descriptors).

MFC after: 1 week


# 1861b342 01-Jan-2005 Olivier Houchard <cognet@FreeBSD.org>

In re_detach(), remove an extra call to ether_ifdetach().
This fixes a panic that occurs when unloading the kernel module.

MFC after: 3 days


# 22a11c96 28-Sep-2004 John-Mark Gurney <jmg@FreeBSD.org>

fix jumbo frames as much as they can be fixed for re. We now cap the MTU
to 7422 since it appears that the 8169S can't transmit anything larger..
The 8169S can receive full jumbo frames, but we don't have an mru to let
the upper layers know this...

add fixup so that this driver should work on alignment constrained platforms
(!i386 && !amd64)

MFC after: 5 days


# aedd16d9 20-Sep-2004 John-Mark Gurney <jmg@FreeBSD.org>

trim trailing white space..
call the re mutex by it's name..

MFC after: 3 days


# 61021536 19-Sep-2004 John-Mark Gurney <jmg@FreeBSD.org>

spell RX correctly
don't call re_rxeof a second time when we've already done the work
pull common code out from if and else clauses

MFC after: 3 days


# 80a2a305 18-Sep-2004 John-Mark Gurney <jmg@FreeBSD.org>

pass in pointer to m_head to re_encap because m_defrag could free the
original mbuf causing a free'd mbuf passed to bpf later and panic'ing the
system.. This should only effect jumbo frames.

MFC after: 5 days


# 0187838b 04-Sep-2004 Ruslan Ermilov <ru@FreeBSD.org>

Fixed build with DEVICE_POLLING defined.


# 97b9d4ba 03-Sep-2004 John-Mark Gurney <jmg@FreeBSD.org>

merge in if_rl locking because if_re was originally based upon if_rl.
This essentially merges revs 1.143-1.1445 of sys/pci/if_rl.c.
This now marks the interrupt MPSAFE along with making the mutex non-recursive.

Looked over by: bms


# ea263191 28-Aug-2004 MIHIRA Sanpei Yoshiro <sanpei@FreeBSD.org>

Add support Corega CG-LAPCIGT Gigabit Ethernet(8169S)

PR: [FreeBSD-users-jp 80667]
Submitted by: FUJIMOTO Kou <fujimoto@j.dendai.ac.jp>
MFC after: 1 week


# a11e2f18 05-Jul-2004 Bruce M Simpson <bms@FreeBSD.org>

Eliminate unneeded return keywords.


# 59b5d934 05-Jul-2004 Bruce M Simpson <bms@FreeBSD.org>

Whitespace pass


# 922a6055 28-Jun-2004 Warner Losh <imp@FreeBSD.org>

Remove code to slam the config space on transition to d0.


# 0e939c0c 09-Jun-2004 Christian Weisgerber <naddy@FreeBSD.org>

Replace handrolled CRC calculation with ether_crc32_[lb]e().


# fe12f24b 30-May-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Add missing <sys/module.h> includes


# 9930009e 24-May-2004 John Baldwin <jhb@FreeBSD.org>

Wrap the code to save/restore PCI config registers on suspend/resume in
#ifndef BURN_BRIDGES.

Noticed by: phk


# 25fbb2c3 23-May-2004 Yaroslav Tykhiy <ytykhiy@gmail.com>

A handler for ioctl(SIOCSIFCAP) should not alter a bit in
if_capenable unless the interface driver is actually able
to toggle the respective capability on and off.

Reviewed by: ru


# 866a788c 23-May-2004 Maxime Henrion <mux@FreeBSD.org>

We don't need to initialize if_output, ether_ifattach() does it
for us.


# f4ab22c9 11-Apr-2004 Ruslan Ermilov <ru@FreeBSD.org>

Implemented per-interface polling(4) control.


# 5f96beb9 17-Mar-2004 Nate Lawson <njl@FreeBSD.org>

Convert callers to the new bus_alloc_resource_any(9) API.

Submitted by: Mark Santcroos <marks@ripe.net>
Reviewed by: imp, dfr, bde


# e3bbbec2 14-Mar-2004 Matthew N. Dodd <mdodd@FreeBSD.org>

Announce ethernet MAC addresss in ether_ifattach().


# a55a017f 08-Dec-2003 David E. O'Brien <obrien@FreeBSD.org>

Don't use caddr_t in mchash(). Also use C99 spellings over BSD ones.

Requested by: bde,imp


# 347934fa 27-Nov-2003 Warner Losh <imp@FreeBSD.org>

Sometimes cardbus attachments don't attach, so while we track down
this problem put these lines back in. While they should be
unnecessary, they appear to be sometimes necessary.

Reviewed in concept: dfr
Approved by: re (scottl@)


# 5120abbf 14-Nov-2003 Sam Leffler <sam@FreeBSD.org>

Drop the driver lock around calls to if_input to avoid a LOR when
the packets are immediately returned for sending (e.g. when bridging
or packet forwarding). There are more efficient ways to do this
but for now use the least intrusive approach.

Reviewed by: imp, rwatson


# 4dc52c32 14-Nov-2003 David E. O'Brien <obrien@FreeBSD.org>

Remove duplicate FBSDID's, move others to their right place.


# aa825502 13-Nov-2003 David E. O'Brien <obrien@FreeBSD.org>

Try to create some sort of consistency in how the routings to find the
multicast hash are written. There are still two distinct algorithms used,
and there actually isn't any reason each driver should have its own copy
of this function as they could all share one copy of it (if it grew an
additional argument).


# 0be389f3 03-Nov-2003 Doug Rabson <dfr@FreeBSD.org>

Remove explicit cardbus attachments from drivers where this is identical
to the pci attachment. Cardbus is a derived class of pci so all pci
drivers are automatically available for matching against cardbus devices.

Reviewed by: imp


# 9bf40ede 31-Oct-2003 Brooks Davis <brooks@FreeBSD.org>

Replace the if_name and if_unit members of struct ifnet with new members
if_xname, if_dname, and if_dunit. if_xname is the name of the interface
and if_dname/unit are the driver name and instance.

This change paves the way for interface renaming and enhanced pseudo
device creation and configuration symantics.

Approved By: re (in principle)
Reviewed By: njl, imp
Tested On: i386, amd64, sparc64
Obtained From: NetBSD (if_xname)


# edd03374 20-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Remove the dual-address cycle stuff. DAC is used to allow a bus master
device to access 64-bit addresses from a 32-bit PCI bus. While the
RealTek manual says you can set this bit and the chip will perform
DAC only if you give it a DMA address with any of the upper 32
bits set, this appears not to be the case. If I turn on the DAC
bit, the chip sets the 'system error' bit in the status register
when I to do a DMA on my Athlon test box with 32-bit PCI bus (VIA
chipset) even though I only have 128MB of physical memory, and thus
can never give the chip a 64-bit address.

Obviously, I can't just set it and forget it, so until I figure
out the right rule for when it's safe/necessary to enable it, keep
it turned off.


# 6110675f 18-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Remove jumbo buffer #defines that I ended up not needing.


# 7cae6651 18-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

In re_diag(), there's no need for us to call re_start() ourselves:
IF_HANDOFF() does it for us behind the scenes. Remove the extra call
to re_start() otherwise we try to transmit twice.

In re_encap(), fix the code that guards against consuming too many
descriptors in the TX ring so that it actually works. With the
new 8169S chip, I was able to hit a corner case that drained the
free descriptor count all the way to 0. This is not supposed to
be possible.


# c2c6548b 13-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Teach the re(4) driver about the CFG2 register, which tells us whether
we're on a 32-bit/64-bit bus or not. Use this to decide if we should
set the PCI dual-address cycle enable bit in the C+ command register.
(Enabling DAC on a 32-bit bus seems to do bad things.)

Also, initialize the C+ command register early in the re_init() routine.
The documentation says this register should be configured first.


# 804af9a1 11-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Toggle the interface on and off before starting the diag test. This
seems to be necessary for the 8139C+ under certain circumstances, and
doesn't appear to hurt the other chips. (In the failure case, the
packet would be sent through the TX DMA ring but not get echoed
back. I suspect this has something to do with the link state changing
unexpectedly.)


# abc8ff44 11-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

- For the 8169 chips, read the station address by forcing an EEPROM
autoload and then copying the contends of the station address
registers. For some reason, reading the EEPROM on the 8169S doesn't
work right. This gets around the problem, and allows us to read
the station address correctly on the 8169S.

- Insert a delay after initiating packet transmition in re_diag() to
allow lots of time for the frame to echo back to the host, and wait
for both the 'RX complete' and 'timeout expired' bits in the ISR
register to be set.

- Deal more intelligently with the fact that the frame length
field in the RX descriptor is a different width on the 8139C+
than it is on the 8169/8169S/8110S

- For the 8169, you have to set bit 17 in the TX config register
to enter digital loopback mode, but for the 8139C+, you have to
set both bits 17 and 18. Take this into account so that re_diag()
works properly for both types of chips.


# 9bac70b8 10-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Add a PHY driver to support the built-in gigE PHY in the 8169S/8110S
ethernet chips. This driver is pretty simple, however it contains
special DSP initialization code which is needed in order to get
the chip to negotiate a gigE link. (This special initialization
may not be needed in subsequent chip revs.) Also:

- Fix typo in if_rlreg.h (RL_GMEDIASTAT_1000MPS -> RL_GMEDIASTAT_1000MBPS)

- Deal with shared interrupts in re_intr(): if interface isn't up,
return.

- Fix another bug in re_gmii_writereg() (properly apply data field mask)

- Allow PHY driver to read the RL_GMEDIASTAT register via the
re_gmii_readreg() register (this is register needed to determine
real time link/media status).


# 4ee16661 10-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Fix bug in re_gmii_writewreg(): we don't need to be screening out certain
PHY addresses here. (The chip will only let you talk to one PHY anyway.)


# 69a6b7fb 10-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Update hardware revision table. 0x04000000 appears to be the revision
for the 8169S, according to my sample board. The RealTek Linux driver
mentions 0x00800000. I'm assigning this to the 8110S until I get
more info on it. (The (preliminary) RealTek docs only say that 8169S/8110S
chips will have some combination of those two bits set, but doesn't say
exactly what bit combination goes with which chip variant.)


# a94100fa 07-Sep-2003 Bill Paul <wpaul@FreeBSD.org>

Take the support for the 8139C+/8169/8169S/8110S chips out of the
rl(4) driver and put it in a new re(4) driver. The re(4) driver shares
the if_rlreg.h file with rl(4) but is a separate module. (Ultimately
I may change this. For now, it's convenient.)

rl(4) has been modified so that it will never attach to an 8139C+
chip, leaving it to re(4) instead. Only re(4) has the PCI IDs to
match the 8169/8169S/8110S gigE chips. if_re.c contains the same
basic code that was originally bolted onto if_rl.c, with the
following updates:

- Added support for jumbo frames. Currently, there seems to be
a limit of approximately 6200 bytes for jumbo frames on transmit.
(This was determined via experimentation.) The 8169S/8110S chips
apparently are limited to 7.5K frames on transmit. This may require
some more work, though the framework to handle jumbo frames on RX
is in place: the re_rxeof() routine will gather up frames than span
multiple 2K clusters into a single mbuf list.

- Fixed bug in re_txeof(): if we reap some of the TX buffers,
but there are still some pending, re-arm the timer before exiting
re_txeof() so that another timeout interrupt will be generated, just
in case re_start() doesn't do it for us.

- Handle the 'link state changed' interrupt

- Fix a detach bug. If re(4) is loaded as a module, and you do
tcpdump -i re0, then you do 'kldunload if_re,' the system will
panic after a few seconds. This happens because ether_ifdetach()
ends up calling the BPF detach code, which notices the interface
is in promiscuous mode and tries to switch promisc mode off while
detaching the BPF listner. This ultimately results in a call
to re_ioctl() (due to SIOCSIFFLAGS), which in turn calls re_init()
to handle the IFF_PROMISC flag change. Unfortunately, calling re_init()
here turns the chip back on and restarts the 1-second timeout loop
that drives re_tick(). By the time the timeout fires, if_re.ko
has been unloaded, which results in a call to invalid code and
blows up the system.

To fix this, I cleared the IFF_UP flag before calling ether_ifdetach(),
which stops the ioctl routine from trying to reset the chip.

- Modified comments in re_rxeof() relating to the difference in
RX descriptor status bit layout between the 8139C+ and the gigE
chips. The layout is different because the frame length field
was expanded from 12 bits to 13, and they got rid of one of the
status bits to make room.

- Add diagnostic code (re_diag()) to test for the case where a user
has installed a broken 32-bit 8169 PCI NIC in a 64-bit slot. Some
NICs have the REQ64# and ACK64# lines connected even though the
board is 32-bit only (in this case, they should be pulled high).
This fools the chip into doing 64-bit DMA transfers even though
there is no 64-bit data path. To detect this, re_diag() puts the
chip into digital loopback mode and sets the receiver to promiscuous
mode, then initiates a single 64-byte packet transmission. The
frame is echoed back to the host, and if the frame contents are
intact, we know DMA is working correctly, otherwise we complain
loudly on the console and abort the device attach. (At the moment,
I don't know of any way to work around the problem other than
physically modifying the board, so until/unless I can think of a
software workaround, this will have do to.)

- Created re(4) man page

- Modified rlphy.c to allow re(4) to attach as well as rl(4).

Note that this code works for the sample 8169/Marvell 88E1000 NIC
that I have, but probably won't work for the 8169S/8110S chips.
RealTek has sent me some sample NICs, but they haven't arrived yet.
I will probably need to add an rlgphy driver to handle the on-board
PHY in the 8169S/8110S (it needs special DSP initialization).