Home | History | Annotate | Download | only in pci
History log of /src/sys/dev/pci/if_nfe.c
RevisionDateAuthorComments
 1.81  05-Jul-2024  rin sys: Drop redundant NULL check before m_freem(9)

m_freem(9) safely has accepted NULL argument at least since 4.2BSD:
https://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/sys/sys/uipc_mbuf.c

Compile-tested on amd64/ALL.

Suggested by knakahara@
 1.80  22-Jan-2022  martin Explicitly cast a __MASK(40) to bus_addr_t (for 32bit bus_addr_t archs)
 1.79  22-Jan-2022  skrll Ensure bus_dmatag_subregion is called with an inclusive max_addr
everywhere.
 1.78  13-Mar-2020  msaitoh Improve error check:

- We check PHY register read error correctly (timeout and NFE_PHY_ERROR), so
don't check NFE_PHY_DATA register's value with 0xffffffff or 0. At least,
some registers may have 0.
- Check NFE_PHY_ERROR bit in nfe_miibus_writereg().
- Improve debug printf
 1.77  08-Mar-2020  msaitoh Use unsigned to avoid undefined behavior. Found by kUBSan.
 1.76  01-Mar-2020  thorpej Add explicit casts in bus_dmatag_subregion() calls to avoid overflow /
truncation warnings on 32-bit platforms.
 1.75  01-Mar-2020  thorpej - Range-limit our DMA tag to 40-bit.
- Eliminate __LP64__ ifdefs.
 1.74  04-Feb-2020  thorpej Use ifmedia_fini().
 1.73  30-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.72  13-Sep-2019  msaitoh branches: 1.72.2;
if_flags is neither int nor short. It's unsigned short.
 1.71  09-Jul-2019  msaitoh branches: 1.71.2;
Don't automatically set ec_capenable's ETHERCAP_VLAN_HWTAGGING bit in
vlan_config() to make it user-controllable. Instead, set the bit in
xxx_attach().
 1.70  28-May-2019  msaitoh Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.69  23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.68  11-Apr-2019  msaitoh Fix a bug that the duplex of manual media setting may be wrong
when the IFM_GMASK bit other than IFM_[FH]DX is set.
 1.67  22-Jan-2019  msaitoh Change MII PHY read/write API from:

int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:

int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);

Now we can test if a read/write operation failed or not by the return value.

In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.

Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:

arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c


Tested with the following device:

axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)

Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url

Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
 1.66  09-Dec-2018  jdolecek use pci_intr_establish_xname() everywhere
 1.65  26-Jun-2018  msaitoh branches: 1.65.2;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
 1.64  26-Sep-2017  knakahara branches: 1.64.2;
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.

I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html

XXX need pullup to -8 branch
 1.63  15-Dec-2016  ozaki-r branches: 1.63.8;
Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input

The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
- Where/When if_ipackets is counted up
- Note that some drivers still update packet statistics in their own
way (periodical update)
- Moved bpf_mtap run in softint
- This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
 1.62  08-Dec-2016  ozaki-r Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.
 1.61  10-Jun-2016  ozaki-r branches: 1.61.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
 1.60  09-Feb-2016  ozaki-r Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
 1.59  29-Mar-2014  christos branches: 1.59.6;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.
 1.58  30-Mar-2013  christos branches: 1.58.4;
remove trailing whitespace
 1.57  23-Sep-2012  chs use 64-bit DMA where possible.
 1.56  22-Jul-2012  matt branches: 1.56.2;
Fix mii_statchg to take a 'struct ifnet *' instead of device_t. This fixes
problem with a common MDIO bus used for multiple interfaces.
Some drivers converted to CFATTACL_DECL_NEW.
 1.55  30-Jan-2012  drochner branches: 1.55.2;
Use pci_aprint_devinfo(9) instead of pci_devinfo+aprint_{normal,naive}
where it looks straightforward, and pci_aprint_devinfo_fancy in a few
others where drivers want to supply their own device names instead
of the pcidevs generated one. More complicated cases, where names
are composed at runtime, are left alone for now. It certainly makes
sense to simplify the drivers here rather than inventing a catch-all API.
This should serve as as example for new drivers, and also ensure
consistent output in the AB_QUIET ("boot -q") case. Also, it avoids
excessive stack usage where drivers attach child devices because the
buffer for the device name is not kept on the local stack anymore.
 1.54  23-Jan-2011  tsutsui branches: 1.54.4; 1.54.8;
Pull the following fix from OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/src/sys/dev/pci/if_nfe.c#rev1.97
>> Some nfe(4)/rlphy(4) combos don't work, because the PHY responds to all
>> addresses on the mii bus. As a countereasure, only attach the first PHY we
>> encounter. It is very unlikely we're going to ever see nfe(4) with multiple
>> PHYs. The same is probably true for any modern NIC.

Should suppress bogus ukphy30 noted in PR kern/42950.
No bad side effect on my nfe(4) which didn't get ghosts:
---
nfe0 at pci0 dev 5 function 0: NVIDIA nForce3 Ethernet #4 (rev. 0xa2)
:
rlphy0 at nfe0 phy 1: RTL8201L 10/100 media interface, rev. 1
rlphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
 1.53  03-Nov-2010  jakllsch branches: 1.53.2; 1.53.4;
Make nfe(4) detachable.
 1.52  02-Nov-2010  jakllsch Explicitly set PCI_COMMAND_MASTER_ENABLE.
 1.51  05-Apr-2010  joerg Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
 1.50  24-Feb-2010  dyoung branches: 1.50.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.49  19-Jan-2010  pooka branches: 1.49.2;
Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client. This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached. However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff. ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
 1.48  08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.47  26-Nov-2009  njoly Cleanup interrupt establish error messages. Do not mix
aprint_error/aprint_normal/printf calls for a single line.
 1.46  05-Sep-2009  tsutsui Invert logic around nested pmf(9) registrations for readability.
 1.45  14-Jun-2009  cegger use __arraycount
 1.44  18-Mar-2009  cegger bcmp -> memcmp
 1.43  01-Mar-2009  cegger bzero -> memset per request from martin@
bcopy -> memcpy

XXX Would changing bcmp to memcpy be a functional change regarding its return value?
 1.42  01-Mar-2009  cegger when nfe_attach() fails, free all resources including
interrupt map, interrupt handler and dma maps.
Also prevent call to bus_dmamap_destroy() when bus_dmamap_create() failed.
The nfe_free_* routines assume, the map pointers are NULL but they
are actually undefined. Make the assumption true by making them NULL
in the error path of bus_dmamap_create().

All together, this fixes crashes when nfe_attach() fails.
ok martin@
 1.41  01-Mar-2009  cegger MCP79 supports JUMBO frames.
Information from Linux driver.
Patch presented on current-users@ http://mail-index.netbsd.org/current-users/2009/02/11/msg008037.html
 1.40  12-Feb-2009  cegger flow-control support for MCP65 chip.
XXX other chips may also have flow-control, but only on MCP65 tested.
ok cube@
 1.39  18-Jan-2009  cegger branches: 1.39.2;
Bracket IRQ masking around nfe_intr() in nfe_init() rather inside nfe_intr().
Proposed by dyoung@ in PR 40345. Should fix PR 40345.
 1.38  16-Dec-2008  christos replace bitmask_snprintf(9) with snprintb(3)
 1.37  07-Nov-2008  dyoung *** Summary ***

When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.

Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)

Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.

Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.

Return consistent, appropriate error codes from network drivers.

Improve readability. KNF.

*** Details ***

In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.

In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.

Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.

In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.

Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:

switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}

Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,

switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}

unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).

In ipw(4), remove an if_set_sadl() call that is out of place.

In nfe(4), reuse the jumbo MTU logic in ether_ioctl().

Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.

Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.

Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.

Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.

In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.

Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.

In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.

Let ifioctl_common() handle SIOCGIFADDR.

Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.

In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.

bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
 1.36  17-Jun-2008  cube branches: 1.36.2; 1.36.4; 1.36.6;
Use MUTEX_DEFAULT to initialise the mutex, per martin@'s input.
 1.35  25-May-2008  jmcneill branches: 1.35.2;
Based on changes to nfe_attach in r1.27, wake newer chips from powerdown
mode on resume as well as at attach time.
 1.34  20-Apr-2008  cube branches: 1.34.2; 1.34.4;
Restore jumbo frame support and protect access to the DMA space for
received frames with a mutex.

Tested by Paul Goyette, Martin Husemann and myself.
 1.33  17-Apr-2008  christos branches: 1.33.2;
join line for symmetry.
 1.32  17-Apr-2008  xtraeme Make this build again... HI XTOS.
 1.31  17-Apr-2008  christos sync with openbsd; fixes observed corruption issues.
 1.30  26-Mar-2008  cube Split device_t and softc, and related cosmetic changes.
 1.29  24-Feb-2008  isaki Minor style fix.
 1.28  07-Feb-2008  dyoung branches: 1.28.2; 1.28.6;
Start patching up the kernel so that a network driver always has
the opportunity to handle an ioctl before generic ifioctl handling
occurs. This will ease extending the kernel and sharing of code
between drivers.

First steps: Make the signature of ifioctl_common() match struct
ifinet->if_ioctl. Convert SIOCSIFCAP and SIOCSIFMTU to the new
ifioctl() regime, throughout the kernel.
 1.27  26-Jan-2008  tsutsui Wakeup some newer chips from powerdown mode. From FreeBSD/Linux driver
via OpenBSD.

Tested by wiz@ in PR kern/37868.
 1.26  19-Jan-2008  dyoung Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)

This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.

I have made a few miscellaneous changes, too:

gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media

Except for the change to mtd(4), no functional changes are intended.

XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
 1.25  17-Dec-2007  tsutsui Handle a quirk of newer MCP6x chips on reading MAC address.
Fix from Richy Kim in PR kern/36576.
 1.24  09-Dec-2007  jmcneill branches: 1.24.2;
Merge jmcneill-pm branch.
 1.23  14-Nov-2007  xtraeme branches: 1.23.2; 1.23.4;
Add the MCP{67,73} products on nfe_attach().
 1.22  14-Nov-2007  xtraeme Attach to NVIDIA MCP67/73 Ethernet controllers.
 1.21  07-Nov-2007  ad Merge from vmlocking:

- pool_cache changes.
- Debugger/procfs locking fixes.
- Other minor changes.
 1.20  19-Oct-2007  ad branches: 1.20.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.19  24-Sep-2007  cube branches: 1.19.2;
- If the chip doesn't support jumbo frames, don't use bus_dmamap_load_mbuf
which expects a properly filled mbuf chain, but bus_dmamap_load for the
mbuf storage space instead.

- If the chip supports jumbo frames
+ keep track of which RX descriptor uses which jumbo mbuf buffer, so
that we can rewrite the physaddr field of the descriptor later, as it
might be partially overwritten by the hw
+ when we're out of jumbo mbufs, and if the packet is small enough,
copy it into a cluster mbuf

Those changes make my nfe(4) stable in both cases (defining NFE_NO_JUMBO
for the first one).
 1.18  24-Sep-2007  cube From OpenBSD, rev 1.72:

In nfe_start() do a fast return if IFF_OACTIVE is set, in
this case we need a Tx interrupt to clean up the DMA ring
before if_start can be properly called.
 1.17  01-Sep-2007  dyoung branches: 1.17.2;
Change a bazillion occurrences of code resembling this,

error = (cmd == SIOCADDMULTI) ?
ether_addmulti(ifr, &sc->sc_ec) :
ether_delmulti(ifr, &sc->sc_ec);

if (error == ENETRESET) {

to this,

if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {

which does the same thing.

(A bazillion is a very large number. This seems to make the i386
ALL kernel smaller by 3kB to 4kB.)

Use ifreq_getaddr() twice in es(4).

Whitespace nits.
 1.16  09-Jul-2007  ad branches: 1.16.2; 1.16.6; 1.16.8;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.15  04-Mar-2007  christos branches: 1.15.2; 1.15.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14  28-Feb-2007  tsutsui Apply patches which may fix RX stall problem on nfe(4):
- make DMA descriptors volatile to avoid possible unintended reordering
which might cause some race conditions
- process interrupts until all NFE_IRQ_WANTED bits are handled

and also put misc fixes:
- return 1 and call nfe_start() in nfe_intr() only if any own interrupts
are actually handled
- use bus_dmamap_load_mbuf(9) for RX mbufs rather than bus_dmamap_load(9)
with mtod(9) and MCLBYTES
- check sc->txq.queued to see if TX descriptors are queued or handled
in nfe_start() and nfe_txeof()
- use proper BUS_DMASYNC_{PRE,POST} ops
- prepare and use NFE_[RT]X_NEXTDESC() macro
- rename NFE_TX_TCP_CSUM to NFE_TX_TCP_UDP_CSUM since it also enables
hardware udp4csum-tx for UDP4 packets
- some minor optimization
- misc KNF

Tested and confirmed by matthew green by
"to send >25MB/sec to nfe0 for over one hour,"
and also tested by me (with light TRX load on 100baseTX though)
for a month.
 1.13  09-Jan-2007  tsutsui branches: 1.13.2;
Enable hardware checksum support by hardware info taken from FreeBSD.
Tested on nForce3 250 and nForce4 by Chuck Silvers, Cesar Catrian Carreno,
and me.
 1.12  05-Jan-2007  jmcneill A few changes to make this work on the Microsoft Xbox. Should also help
with other users who have been experiencing watchdog timeouts:
* Mask all interrupts while servicing a tx or rx interrupt.
* On init, clear IRQ status registers (workaround for buggy netbooters).
 1.11  01-Jan-2007  tsutsui Pull a TX timeout fix from OpenBSD:
> Defer setting of the valid bit in the first TX descriptor after
> all descriptors have been setup. Otherwise, hardware may start
> processing descriptors faster than us and crap out.
> Fixes "watchdog timeout" errors.
>
> Original idea from Matthew Dillon @DragonFly.
 1.10  01-Jan-2007  tsutsui Minor style fixes in nfe_attach:
- print PCI device name and revision
- print interrupt and Ethernet address like other devices

Before:
---
nfe0 at pci0 dev 5 function 0LKLN: Picked IRQ 20 with weight 1
: ioapic0 pin 20 (irq 9), address xx:xx:xx:xx:xx:xx

After:
---
nfe0 at pci0 dev 5 function 0: NVIDIA nForce3 ethernet #4 (rev. 0xa2)
LKLN: Picked IRQ 20 with weight 1
nfe0: interrupting at ioapic0 pin 20 (irq 9)
nfe0: Ethernet address xx:xx:xx:xx:xx:xx

(note "Picked IRQ" message is logged by aprint_verbose(9) in acpi(4))
 1.9  27-Dec-2006  alc remove the KASSERT() introduced in last commit and use VLAN_OUTPUT_TAG() macro.

tested by martin@
pointed out and ok by pavel@, also ok from christos@
 1.8  25-Dec-2006  alc CID-3667: check if 'mtag != NULL' before dereferencing it
 1.7  16-Nov-2006  christos branches: 1.7.2;
__unused removal on arguments; approved by core.
 1.6  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.5  24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.4  03-Sep-2006  xtraeme branches: 1.4.2; 1.4.4; 1.4.6;
Add support for MCP61/65 controllers... from obsd.
 1.3  26-Mar-2006  chs branches: 1.3.2; 1.3.4; 1.3.6; 1.3.12; 1.3.14;
work around another mbuf leak, the hardware doesn't seem
to work quite the way that the driver expects.
 1.2  16-Mar-2006  chs branches: 1.2.2;
handle another difference between the BSDs:
free the original mbuf in the jumbo-free callback too.
 1.1  12-Mar-2006  chs branches: 1.1.2;
add nfe driver and manpage from OpenBSD.
 1.1.2.4  03-Sep-2006  yamt sync with head.
 1.1.2.3  01-Apr-2006  yamt sync with head.
 1.1.2.2  13-Mar-2006  yamt sync with head.
 1.1.2.1  12-Mar-2006  yamt file if_nfe.c was added on branch yamt-pdpolicy on 2006-03-13 09:07:26 +0000
 1.2.2.1  28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.3.14.1  07-Sep-2006  riz Pull up following revision(s) (requested by xtraeme in ticket #112):
sys/dev/pci/if_nfe.c: revision 1.4
sys/dev/pci/pcidevs: revision 1.824
- Add nForce MCP61/65 LAN controllers... from obsd.
- Improve description in some nForce controllers as well.
Add support for MCP61/65 controllers... from obsd.
 1.3.12.11  27-Feb-2008  yamt sync with head.
 1.3.12.10  11-Feb-2008  yamt sync with head.
 1.3.12.9  04-Feb-2008  yamt sync with head.
 1.3.12.8  21-Jan-2008  yamt sync with head
 1.3.12.7  15-Nov-2007  yamt sync with head.
 1.3.12.6  27-Oct-2007  yamt sync with head.
 1.3.12.5  03-Sep-2007  yamt sync with head.
 1.3.12.4  26-Feb-2007  yamt sync with head.
 1.3.12.3  30-Dec-2006  yamt sync with head.
 1.3.12.2  21-Jun-2006  yamt sync with head.
 1.3.12.1  26-Mar-2006  yamt file if_nfe.c was added on branch yamt-lazymbuf on 2006-06-21 15:05:04 +0000
 1.3.6.2  22-Apr-2006  simonb Sync with head.
 1.3.6.1  26-Mar-2006  simonb file if_nfe.c was added on branch simonb-timecounters on 2006-04-22 11:39:14 +0000
 1.3.4.4  20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/dev/pci/if_nfe.c: revision 1.3
work around another mbuf leak, the hardware doesn't seem
to work quite the way that the driver expects.
 1.3.4.3  20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/dev/pci/if_nfe.c: revision 1.2
handle another difference between the BSDs:
free the original mbuf in the jumbo-free callback too.
 1.3.4.2  20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
share/man/man4/Makefile: revision 1.377
sys/dev/pci/if_nfe.c: revision 1.1
sys/dev/pci/if_nfereg.h: revision 1.1
share/man/man4/nfe.4: revision 1.1
sys/dev/pci/if_nfevar.h: revision 1.1
distrib/sets/lists/man/mi: revision 1.863
add nfe driver and manpage from OpenBSD.
 1.3.4.1  26-Mar-2006  snj file if_nfe.c was added on branch netbsd-3 on 2006-04-20 03:11:14 +0000
 1.3.2.2  19-Apr-2006  elad sync with head.
 1.3.2.1  26-Mar-2006  elad file if_nfe.c was added on branch elad-kernelauth on 2006-04-19 03:25:35 +0000
 1.4.6.2  10-Dec-2006  yamt sync with head.
 1.4.6.1  22-Oct-2006  yamt sync with head
 1.4.4.2  09-Sep-2006  rpaulo sync with head
 1.4.4.1  03-Sep-2006  rpaulo file if_nfe.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:52:17 +0000
 1.4.2.2  12-Jan-2007  ad Sync with head.
 1.4.2.1  18-Nov-2006  ad Sync with head.
 1.7.2.3  23-Feb-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1061):
sys/dev/pci/if_nfe.c: revision 1.22, 1.23, 1.25, 1.27
sys/dev/pci/pcidevs: revision 1.914
sys/dev/pci/if_nfereg.h: revision 1.5, 1.6
share/man/man4/nfe.4: revision 1.4
sys/dev/pci/if_nfevar.h: revision 1.5, 1.6
Add NVIDIA MCP7[37] devices, from OpenBSD.
Attach to NVIDIA MCP67/73 Ethernet controllers.
Add the MCP{67,73} products on nfe_attach().
Sync with reality.
Handle a quirk of newer MCP6x chips on reading MAC address.
Fix from Richy Kim in PR kern/36576.
Wakeup some newer chips from powerdown mode. From FreeBSD/Linux driver
via OpenBSD.
Tested by wiz@ in PR kern/37868.
 1.7.2.2  07-Oct-2007  pavel Pull up following revisions (requested by cube in ticket #920):
sys/dev/pci/if_nfe.c: revision 1.14, 1.18-1.19
sys/dev/pci/if_nfereg.h: revision 1.4
sys/dev/pci/if_nfevar.h: revision 1.3
Apply patches which may fix RX stall problem on nfe(4):
- make DMA descriptors volatile to avoid possible unintended reordering
which might cause some race conditions
- process interrupts until all NFE_IRQ_WANTED bits are handled
and also put misc fixes:
- return 1 and call nfe_start() in nfe_intr() only if any own interrupts
are actually handled
- use bus_dmamap_load_mbuf(9) for RX mbufs rather than bus_dmamap_load(9)
with mtod(9) and MCLBYTES
- check sc->txq.queued to see if TX descriptors are queued or handled
in nfe_start() and nfe_txeof()
- use proper BUS_DMASYNC_{PRE,POST} ops
- prepare and use NFE_[RT]X_NEXTDESC() macro
- rename NFE_TX_TCP_CSUM to NFE_TX_TCP_UDP_CSUM since it also enables
hardware udp4csum-tx for UDP4 packets
- some minor optimization
- misc KNF
Tested and confirmed by matthew green by
"to send >25MB/sec to nfe0 for over one hour,"
and also tested by me (with light TRX load on 100baseTX though)
for a month.


From OpenBSD, rev 1.72:
In nfe_start() do a fast return if IFF_OACTIVE is set, in
this case we need a Tx interrupt to clean up the DMA ring
before if_start can be properly called.


- If the chip doesn't support jumbo frames, don't use bus_dmamap_load_mbuf
which expects a properly filled mbuf chain, but bus_dmamap_load for the
mbuf storage space instead.
- If the chip supports jumbo frames
+ keep track of which RX descriptor uses which jumbo mbuf buffer, so
that we can rewrite the physaddr field of the descriptor later, as it
might be partially overwritten by the hw
+ when we're out of jumbo mbufs, and if the packet is small enough,
copy it into a cluster mbuf
Those changes make my nfe(4) stable in both cases (defining NFE_NO_JUMBO
for the first one).
 1.7.2.1  19-Jan-2007  bouyer branches: 1.7.2.1.2;
Pull up following revision(s) (requested by tsutsui in ticket #370):
sys/dev/pci/if_nfe.c: revision 1.8 - 1.13
sys/dev/pci/if_nfereg.h: revision 1.2 - 1.3
several bug fixes and hardware checksum support for nfs(4).
 1.7.2.1.2.2  03-Jun-2008  skrll Sync with netbsd-4.
 1.7.2.1.2.1  29-Oct-2007  wrstuden Catch up with 4.0 RC3
 1.13.2.1  12-Mar-2007  rmind Sync with HEAD.
 1.15.4.1  11-Jul-2007  mjf Sync with head.
 1.15.2.4  23-Oct-2007  ad Sync with head.
 1.15.2.3  09-Oct-2007  ad Sync with head.
 1.15.2.2  01-Sep-2007  ad Update for pool_cache API changes.
 1.15.2.1  01-Jul-2007  ad Adapt to callout API change.
 1.16.8.4  23-Mar-2008  matt sync with HEAD
 1.16.8.3  09-Jan-2008  matt sync with HEAD
 1.16.8.2  08-Nov-2007  matt sync with -HEAD
 1.16.8.1  06-Nov-2007  matt sync with HEAD
 1.16.6.8  08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.16.6.7  14-Nov-2007  joerg Sync with HEAD.
 1.16.6.6  11-Nov-2007  joerg Sync with HEAD.
 1.16.6.5  06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.16.6.4  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.16.6.3  05-Oct-2007  joerg Convert nfe(4) to PNP power management.
 1.16.6.2  02-Oct-2007  joerg Sync with HEAD.
 1.16.6.1  03-Sep-2007  jmcneill Sync with HEAD.
 1.16.2.1  03-Sep-2007  skrll Sync with HEAD.
 1.17.2.1  06-Oct-2007  yamt sync with head.
 1.19.2.3  18-Nov-2007  bouyer Sync with HEAD
 1.19.2.2  13-Nov-2007  bouyer Sync with HEAD
 1.19.2.1  25-Oct-2007  bouyer Sync with HEAD.
 1.20.2.3  18-Feb-2008  mjf Sync with HEAD.
 1.20.2.2  27-Dec-2007  mjf Sync with HEAD.
 1.20.2.1  19-Nov-2007  mjf Sync with HEAD.
 1.23.4.1  11-Dec-2007  yamt sync with head.
 1.23.2.1  26-Dec-2007  ad Sync with head.
 1.24.2.2  20-Jan-2008  bouyer Sync with HEAD
 1.24.2.1  02-Jan-2008  bouyer Sync with HEAD
 1.28.6.4  17-Jan-2009  mjf Sync with HEAD.
 1.28.6.3  29-Jun-2008  mjf Sync with HEAD.
 1.28.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.28.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.28.2.1  24-Mar-2008  keiichi sync with head.
 1.33.2.2  04-Jun-2008  yamt sync with head
 1.33.2.1  18-May-2008  yamt sync with head.
 1.34.4.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.34.2.5  11-Aug-2010  yamt sync with head.
 1.34.2.4  11-Mar-2010  yamt sync with head
 1.34.2.3  16-Sep-2009  yamt sync with head
 1.34.2.2  20-Jun-2009  yamt sync with head
 1.34.2.1  04-May-2009  yamt sync with head.
 1.35.2.1  18-Jun-2008  simonb Sync with head.
 1.36.6.1  02-Mar-2009  snj Pull up following revision(s) (requested by cegger in ticket #540):
sys/dev/pci/if_nfe.c: revision 1.42
when nfe_attach() fails, free all resources including
interrupt map, interrupt handler and dma maps.
Also prevent call to bus_dmamap_destroy() when bus_dmamap_create() failed.
The nfe_free_* routines assume, the map pointers are NULL but they
are actually undefined. Make the assumption true by making them NULL
in the error path of bus_dmamap_create().
All together, this fixes crashes when nfe_attach() fails.
ok martin@
 1.36.4.3  28-Apr-2009  skrll Sync with HEAD.
 1.36.4.2  03-Mar-2009  skrll Sync with HEAD.
 1.36.4.1  19-Jan-2009  skrll Sync with HEAD.
 1.36.2.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.39.2.2  23-Jul-2009  jym Sync with HEAD.
 1.39.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.49.2.2  06-Nov-2010  uebayasi Sync with HEAD.
 1.49.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.50.2.2  05-Mar-2011  rmind sync with head
 1.50.2.1  30-May-2010  rmind sync with head
 1.53.4.1  08-Feb-2011  bouyer Sync with HEAD
 1.53.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.54.8.1  18-Feb-2012  mrg merge to -current.
 1.54.4.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.54.4.2  30-Oct-2012  yamt sync with head
 1.54.4.1  17-Apr-2012  yamt sync with head
 1.55.2.1  22-Nov-2012  riz Pull up following revision(s) (requested by chs in ticket #685):
sys/dev/pci/if_nfe.c: revision 1.57
use 64-bit DMA where possible.
 1.56.2.4  03-Dec-2017  jdolecek update from HEAD
 1.56.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.56.2.2  23-Jun-2013  tls resync from head
 1.56.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.58.4.1  18-May-2014  rmind sync with head
 1.59.6.3  05-Feb-2017  skrll Sync with HEAD
 1.59.6.2  09-Jul-2016  skrll Sync with HEAD
 1.59.6.1  19-Mar-2016  skrll Sync with HEAD
 1.61.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.63.8.2  13-May-2019  martin Pull up the following, via patch, requested by msaitoh in ticket #1263:

sys/dev/mii/brgphy.c 1.84
sys/dev/mii/ciphy.c 1.33 via patch
sys/dev/mii/rgephy.c 1.53
sys/arch/arm/imx/if_enet.c 1.18
sys/arch/mips/adm5120/dev/if_admsw.c 1.19-1.20
sys/dev/pci/if_bge.c 1.329
sys/dev/pci/if_bnx.c 1.81
sys/dev/pci/if_et.c 1.21
sys/dev/pci/if_lii.c 1.22
sys/dev/pci/if_msk.c 1.87
sys/dev/pci/if_nfe.c 1.68
sys/dev/pci/if_sk.c 1.95
sys/dev/pci/if_ti.c 1.107
sys/dev/pci/if_txp.c 1.52
sys/dev/pci/if_vge.c 1.69
sys/dev/usb/if_axen.c 1.38
sys/dev/usb/if_aue.c 1.149

Fix a bug that the duplex of manual media setting may be wrong
when the IFM_GMASK bit other than IFM_[FH]DX is set.
 1.63.8.1  24-Oct-2017  snj Pull up following revision(s) (requested by knakahara in ticket #302):
sys/arch/powerpc/booke/dev/pq3etsec.c: 1.30-1.31
sys/arch/x86/pci/if_vmx.c: 1.20
sys/dev/ic/i82557.c: 1.148
sys/dev/ic/rtl8169.c: 1.152
sys/dev/pci/cxgb/cxgb_sge.c: 1.5
sys/dev/pci/if_age.c: 1.51
sys/dev/pci/if_alc.c: 1.25
sys/dev/pci/if_ale.c: 1.23
sys/dev/pci/if_bge.c: 1.311
sys/dev/pci/if_bge.c: 1.312
sys/dev/pci/if_bnx.c: 1.62
sys/dev/pci/if_jme.c: 1.32
sys/dev/pci/if_nfe.c: 1.64
sys/dev/pci/if_sip.c: 1.167
sys/dev/pci/if_stge.c: 1.63-1.64
sys/dev/pci/if_ti.c: 1.102
sys/dev/pci/if_txp.c: 1.48
sys/dev/pci/if_vge.c: 1.61
sys/dev/pci/if_wm.c: 1.538
sys/dev/pci/ixgbe/ix_txrx.c: 1.29 via patch
sys/net/agr/if_agrether_hash.c: 1.4
sys/net/if_ether.h: 1.67-1.68
sys/net/if_ethersubr.c: 1.244
sys/net/if_vlan.c: 1.100
sys/net80211/ieee80211_input.c: 1.89
sys/net80211/ieee80211_output.c: 1.59
sys/sys/mbuf.h: 1.171
VLAN ID uses pkthdr instead of mtag now. Contributed by s-yamaguchi@IIJ.
I just commit by proxy. Reviewed by joerg@n.o and christos@n.o, thanks.
See http://mail-index.netbsd.org/tech-net/2017/09/26/msg006459.html
--
only get vtag when we have vtag like the other drivers.
--
- only get the vtag if we have it like the other drivers
- mask the hardware vlan tag
--
- add a constant for the vlan mask.
- enforce that we have a tag before we get it.
only get vtag when we have vtag like the other drivers.
like if_bge.c:1.312 and if_stge.c:1.64.
fixed by s-yamaguchi@IIJ, thanks.
 1.64.2.3  26-Jan-2019  pgoyette Sync with HEAD
 1.64.2.2  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.64.2.1  28-Jul-2018  pgoyette Sync with HEAD
 1.65.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.65.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.65.2.1  10-Jun-2019  christos Sync with HEAD
 1.71.2.1  19-Mar-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #786):

sys/dev/pci/if_nfe.c: revision 1.77
sys/dev/pci/if_nfe.c: revision 1.78
sys/dev/mii/atphy.c: revision 1.28
sys/dev/mii/atphy.c: revision 1.29
sys/dev/mii/miidevs: revision 1.166

Use unsigned to avoid undefined behavior. Found by kUBSan.
0x001374 is non-bitreversed value of Attansic OUI(0x00c82e).
Attansic/Atheros correctly uses ID1 and ID2 register, so delete all 0x001374
related entries.

Improve error check:
- We check PHY register read error correctly (timeout and NFE_PHY_ERROR), so
don't check NFE_PHY_DATA register's value with 0xffffffff or 0. At least,
some registers may have 0.
- Check NFE_PHY_ERROR bit in nfe_miibus_writereg().
- Improve debug printf

Fix a bug that atphy(4) doesn't work with Attansic L2 rev. 1.
Reported by Rocky Hotas.

- On ASUS M2N-MX SE Plus (NVIDIA MCP61 with Attansic L2 rev. 1), changing
debug port 0x29's value makes the next PHY read fail with error. Read any
register to ignore this problem if the PHY is Attansic L2 revision 1.
I don't know if this problem is from L2 rev. 1 itself or from the
combination because I have only one machine which has L2 rev. "1".
At least, ASUS eee pc 900 (Attansic L2 rev. "2") has no this problem.
- Add comment. AR8021 document has no description about the power saving
control register(debug port 0x29).
- Add comment. AR8031 document says the lower 14 bits are reserved and the
default value is 0x36d0. Shouldn't we clear those bits?
- I have no document neither L1(F1) nor L2(F2), so I don't know whether the
debug port access is correct or not.
Tested with the following machines:
- ASUS P5B SE, L1 rev. 5, age(4)
- ASUS K50IJ, L1 rev. 9, ale(4)
- ASUS eee pc 900, L2 rev. 2, lii(4)
- ASUS M2N-MX SE Plus, L2 rev. 1, nfe(4)
- Intel DP55WB, 82578(AR8021 rev. 2), wm(4)
- Dell inspiron 14z, AR0835 rev. 9, alc(4)
 1.72.2.1  29-Feb-2020  ad Sync with head.

RSS XML Feed