Home | History | Annotate | Download | only in ic
History log of /src/sys/dev/ic/hme.c
RevisionDateAuthorComments
 1.110  29-Jun-2024  riastradh if_stats(9): Add ifp argument to if_stat..._ref.

This will enable us to pass the ifp through to a dtrace probe inside.

No functional change intended in this change, but this is an API
change visible to modules so it shouldn't be pulled up.

PR kern/58377
 1.109  29-May-2022  rin Audit unload/unmap v.s. free against DMA buffer for sys/dev;
make sure that bus_dmamap_unload(9) [or bus_dmamap_destroy(9)] or
bus_dmamem_unmap(9) are preceding to freeing DMA buffer, if it is
loaded or mapped, respectively.

This is mandatory for some archs. See, e.g.:

http://www.nerv.org/netbsd/?q=id:20210511T013030Z.013443cc790088147e4beed43f53dedabeaf9312
http://www.nerv.org/netbsd/?q=id:20220511T172220Z.561179f0b6fcc5b9cd73e274f69d74e2ce9e4c93

For some drivers, resource leaks for error paths are fixed at
the same time.

XXX XXX XXX
Compile test only (at least one arch per driver).
 1.108  12-Mar-2020  thorpej Add support for MBUFTRACE.
 1.107  07-Feb-2020  thorpej Use callout_setfunc() / callout_schedule().
 1.106  29-Jan-2020  thorpej Adopt <net/if_stats.h>.
 1.105  28-May-2019  msaitoh branches: 1.105.4;
Use ETHER_LOCK()/ETHER_UNLOCK() for all ethernet drivers to protect ec_multi*.
 1.104  23-May-2019  msaitoh Whitespace fix (mainly tabify).
 1.103  23-May-2019  msaitoh No functional change:
- Simplify MII structure initialization and reference.
- u_int*_t -> uint*_t.
- KNF
 1.102  05-Feb-2019  msaitoh Remove very old IFF_NOTRAILERS flag.
 1.101  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.100  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.99  26-Jun-2018  msaitoh branches: 1.99.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.98  22-Jun-2018  msaitoh It's not required to include net/bpfdesc.h. Remove it.
 1.97  08-May-2018  pgoyette Fix mis-placed right paren. kern/53271
 1.96  23-May-2017  ozaki-r branches: 1.96.2; 1.96.8;
Apply deferred if_start to more drivers

And annotate some XXX_start as it runs in softint to clarify that
it doesn't need deferred if_start.
 1.95  15-Dec-2016  ozaki-r 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.94  02-Oct-2016  christos MFREE -> m_free
 1.93  10-Jun-2016  ozaki-r branches: 1.93.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.92  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.91  13-Apr-2015  riastradh Convert sys/dev to use <sys/rndsource.h>.
 1.90  10-Aug-2014  tls branches: 1.90.2; 1.90.4;
Merge tls-earlyentropy branch into HEAD.
 1.89  22-Jul-2012  matt branches: 1.89.2; 1.89.12;
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.88  24-Jun-2012  jdc PR kern/46424
Revert the part of revision 1.77 that altered the PHY attachment order.
 1.87  02-Feb-2012  tls branches: 1.87.2;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.86  05-Apr-2010  joerg branches: 1.86.8; 1.86.12;
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.85  19-Jan-2010  pooka branches: 1.85.2; 1.85.4;
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.84  03-Nov-2009  jakllsch Use hme_init() to provide a non-NULL ifp->if_init.
 1.83  19-Sep-2009  tsutsui Use common ether_crc32_le() for multicast hash.
 1.82  18-Sep-2009  tsutsui hme_reset() is no longer called from bus attachments so make it static.
 1.81  08-Sep-2009  tsutsui Make local functions static and remove a declaration that is also in hmevar.h.
Also comment out or remove declarations for #if 0'ed or nonexistent functions.
 1.80  08-Sep-2009  tsutsui - split out chip reset ops from hme_stop() into a new function
hme_chipreset() to make hme_stop() match struct ifnet API
- set ifp->if_timer in hme_start() if any TX packets are queued
- also clear ifp->if_timer and ifp->if_flags in hme_stop()
- replace shutdownhook_establish(9) with pmf_device_reigster1(9)
Briefly checked hme at pci.
 1.79  17-May-2009  tsutsui Split device_t/softc.
Tested PCI HME on i386. Sbus HME is compile test only.
 1.78  12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.77  06-May-2009  jdc Check for internal PHY first, so that it always attaches first, even when
we have an MII transeiver attached.
Count all collision and error counters.
Handle counter overflow and RXTERR.

Tested on U60 HME, PCI HME (501-5019) and SBus Sunswift (501-2739)
 1.76  16-Apr-2009  tsutsui Some cosmetics in rxcsum code. Tested on i386.
 1.75  16-Apr-2009  tsutsui u_intNN_t -> uintNN_t
 1.74  29-Mar-2009  tsutsui Don't assume all RX packets have VLAN headers even if vlanif is configured.
Instead, always check ether_type and use appropriate offsets to adjust
the hardware RX sum value.

XXX: vlan(4) doesn't seem to use csum_data and csum_flags in mbufs anyway.
 1.73  16-Mar-2009  tsutsui Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.

Found on debugging mec(4) on sgimips O2.
 1.72  14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.71  14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.70  07-Mar-2009  tsutsui Replace incorrect local ether_cmp() function with memcmp(9)
on checking multicast addresses, which is not so critical.
Noticed by FUKAUMI Naoki.
 1.69  07-Mar-2009  tsutsui Add an `else' missed in rev 1.49 otherwise RX hardware checksum on hme(4)
is not activated at all. Ok'ed by christos@, tested on macppc.
 1.68  16-Dec-2008  christos branches: 1.68.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.67  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.66  04-May-2008  xtraeme branches: 1.66.6; 1.66.8; 1.66.10; 1.66.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.65  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.64  08-Apr-2008  cegger branches: 1.64.2; 1.64.4;
use aprint_*_dev and device_xname
 1.63  07-Feb-2008  dyoung branches: 1.63.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.62  21-Jan-2008  dyoung Remove an unnecessary check that yields a spurious EINVAL during
initialization.
 1.61  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.60  19-Oct-2007  ad branches: 1.60.2; 1.60.8;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.59  01-Sep-2007  dyoung branches: 1.59.4;
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.58  12-Jul-2007  martin branches: 1.58.2; 1.58.6; 1.58.8;
Do not stop a callout before it is initialized.
 1.57  09-Jul-2007  ad Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.56  04-Mar-2007  christos branches: 1.56.2; 1.56.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.55  24-Nov-2006  christos branches: 1.55.4;
fix spelling of accommodate; from Zapher.
 1.54  07-Sep-2006  dogcow branches: 1.54.2; 1.54.4;
remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.53  24-Dec-2005  perry branches: 1.53.4; 1.53.8;
__inline__ -> inline
 1.52  11-Dec-2005  christos merge ktrace-lwp.
 1.51  02-May-2005  yamt branches: 1.51.2;
split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.50  17-Mar-2005  rafal Fix typo in HW checksum code -- check for TCP & UDP HW checksumming being
enabled rather than TCP twice.
 1.49  05-Mar-2005  heas branches: 1.49.2;
Perform a s/w checksum for packets that are not the same length as the length
field of the IP header (ip->ip-len) indicates they should be. This handles
the case where an ethernet frame has been padded to meet the minimum ethernet
frame length or erroneously (my cisco switch unnecessarily adds 4 bytes to its
SYN). This padding will be included in the hardware checksum and may be
non-zero, thus making it incorrect.
Also, clear csum_flags when we want a s/w checksum, since we may have started
down the h/w checksum path and determined that it was not usable.

While here, clean-up a few WS nits and ifdef INET the hardware checksum code.
 1.48  27-Feb-2005  perry nuke trailing whitespace
 1.47  21-Feb-2005  thorpej Define M_CSUM_DATA_IPv4_IPHL() and M_CSUM_DATA_IPv4_OFFSET() macros
to extract data from csum_data, rather than just open-coding it.
 1.46  18-Feb-2005  heas Add handling for hardware TCP/UDP checksums.
 1.45  18-Feb-2005  heas Handle interface IFF_DEBUG flags sooner in hme_ioctl and cache a copy of
sc_ethercom.ec_capenable such that we can properly adjust the max frame size
when vlan tagging is enabled/disabled.
 1.44  04-Feb-2005  perry de-__P
 1.43  30-Oct-2004  thorpej branches: 1.43.4; 1.43.6;
When adding/deleting multicast addresses, only whack the address
filter if the interface is marked RUNNING.

Fixes kern/27678.
 1.42  26-Oct-2004  heas GC some trailing WS.
 1.41  28-Jun-2004  heas do not reset the chip (and subsequently the phy) when unnecessary; that is,
for address changes, multicast filter changes, or adjusting promiscuous mode.
Fixes resetting the phy for things like start/stopping tcpdump.

ok petrov@, martin@, pk@
 1.40  21-Jan-2004  abs branches: 1.40.4;
If we are explicitly asked for entropy, provide it.
 1.39  03-Nov-2003  petrov Do not set HMEDEBUG as default mode.
 1.38  02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.37  03-May-2003  wiz branches: 1.37.2;
DMA, not dma nor Dma.
 1.36  26-Apr-2003  wiz Management, not managment. Mostly from jmc@openbsd.
 1.35  27-Feb-2003  pk Enable the MII output drivers in hme_mifinit() based on the currently
selected transceiver. Save and restore this setting in hme_mii_readreg()
and hme_mii_writereg().
 1.34  20-Feb-2003  petrov Use MIIF_FORCEANEG.
 1.33  13-Feb-2003  pk Preserve the current PHY select bit in the MIF configuration register
in mii_readreg()/mii_writereg(). Also restore this bit based on the
currently selected media instance every time we need to reinitialise
the interface.
 1.32  18-Dec-2002  martin Since we have to select one of the two possible PHYs when configuring
the MIF Configuration Register PHY_Select, there is no use in pretending
we could talk to both at the MII interface layer.

If both PHY are reported to be present, prefer the external one.

Remember this selection and enforce it in hme_mii_{read,write}reg.
This fixes problems with one of the dual hmes in Netra T1s.

From OpenBSD.
 1.31  22-Oct-2002  fair Change the "dontcare bits" argument to ifmedia_init() to IFM_IMASK
so that it is possible select PHY instances other than the first
one (instance zero), if there is more than one PHY attached.
 1.30  29-Aug-2002  martin Experimentation shows the hme chip is SIMPLEX if used in full-duplex
mode, but not otherwise.

This fixes PR 17523.
 1.29  05-May-2002  thorpej branches: 1.29.2;
hme_init(): call mii_mediachg() to make sure the current media is set.
 1.28  26-Nov-2001  tron Back out new "hme" driver because it causes a performance regression on
"netio" on an U5.
 1.27  26-Nov-2001  tron Bug fixes for VLAN handling supplied by Klaus Klein in private e-mail.
 1.26  25-Nov-2001  tron Pull in Jason Wright's latest changes to the "hme" driver from OpenBSD.
This supports direct DMA from and into mbuf cluster, and VLAN
handling is done a bit differently.
 1.25  13-Nov-2001  lukem add/cleanup RCSID
 1.24  22-Oct-2001  mrg fix a typo in the previous
 1.23  22-Oct-2001  mrg increase the value of _HME_NDESC from 32 to 128. it reduces the noise the
driver makes due to various bad status conditions.
 1.22  05-Oct-2001  thorpej Minor tidying up of the HME driver attach:
- Print nicer-looking message.
- Use bus_space_subregion() when appropriate, rather than arithmetic
on a bus_space_handle_t.
 1.21  07-Jul-2001  thorpej branches: 1.21.2; 1.21.4;
bcopy -> memcpy, strcpy
 1.20  14-Dec-2000  thorpej branches: 1.20.2;
ALTQ'ify.
 1.19  17-Nov-2000  bouyer Supports ETHERCAP_VLAN_MTU. Tested on sbus hme on Ultra/1.
Thanks to Andrei Petrov for the hint !
 1.18  15-Nov-2000  thorpej Move bpfattach()/bpfdetach() calls into ether_ifattach()/ether_ifdetach().
 1.17  20-Oct-2000  mrg ensure DMA mappings are not mapped streamable. fixes ethernet problems on
ultrasparc sbus class machines. from eeh.
 1.16  01-Oct-2000  thorpej Move the check for "promisc + unicast + not for us" into ether_input(),
and change Ethernet drivers to always pass all received frames to
ether_input() (with a few exceptions, which are documented in the
code).
 1.15  25-Jun-2000  eeh Get PCI HME working.
 1.14  15-Jun-2000  pk branches: 1.14.2;
Turn on the hash filter enable bit in the RX configuration register
when loading the multicast hash filter (noted by itojun@iijlab.net).
 1.13  18-May-2000  mrg branches: 1.13.2;
rearrange the order of bus_dma operations to be more like many other
drivers, at the suggestion of fvdl. also, use bus_dmamap_load() not
load_raw().
 1.12  18-May-2000  mrg do not pass a `boundary' argument to bus_dmamap_create(), particularly one
that is smaller than the `size' argument.
 1.11  09-May-2000  pk Conform bus_dmamem_{alloc,map} usage to bus_dma(9) specs.
 1.10  05-Apr-2000  mrg return if we can't map DMA buffers
 1.9  23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.8  14-Feb-2000  pk Bump receive buffer size up to the maximum DMA burst boundary.
 1.7  02-Feb-2000  thorpej Don't dry to diving MIIF_NOISOLATE in the PHY drivers. Instead, pass
flags down from the parent to child vi mii_attach().
 1.6  02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.5  18-Dec-1999  pk Add support for selecting a PHY (i.e. built-in transceiver vs. external MII
device) by using media/instance parameters.
 1.4  17-Dec-1999  pk Avoid feeding negative values to the `roundup()' macro.
Configure the MII management interface earlier.
 1.3  15-Dec-1999  pk Correctly encode the configured number of buffer descriptors.
 1.2  14-Dec-1999  pk * Probe the MII device.
* Ask for an interesting set of interrupt conditions.
* Correct various other typos and omissions.
 1.1  27-Jun-1999  pk branches: 1.1.2; 1.1.4; 1.1.10;
HME ethernet driver.
Note: this is work in progress; needs testing and tweaking. mgr has
promised to do that..
 1.1.10.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.3  05-Jan-2001  bouyer Sync with HEAD
 1.1.4.2  22-Nov-2000  bouyer Sync with HEAD.
 1.1.4.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.2  01-Jul-1999  thorpej Sync w/ -current.
 1.1.2.1  27-Jun-1999  thorpej file hme.c was added on branch chs-ubc2 on 1999-07-01 23:32:27 +0000
 1.13.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.2.2  25-Oct-2000  tv Pullup 1.17 [mrg]:
ensure DMA mappings are not mapped streamable. fixes ethernet problems on
ultrasparc sbus class machines. from eeh.
 1.14.2.1  31-Jul-2000  mrg pull up 1.15 (approved by thorpej):
>Get PCI HME working.
 1.20.2.8  19-Dec-2002  thorpej Sync with HEAD.
 1.20.2.7  11-Nov-2002  nathanw Catch up to -current
 1.20.2.6  17-Sep-2002  nathanw Catch up to -current.
 1.20.2.5  20-Jun-2002  nathanw Catch up to -current.
 1.20.2.4  08-Jan-2002  nathanw Catch up to -current.
 1.20.2.3  14-Nov-2001  nathanw Catch up to -current.
 1.20.2.2  22-Oct-2001  nathanw Catch up to -current.
 1.20.2.1  24-Aug-2001  nathanw Catch up with -current.
 1.21.4.1  11-Oct-2001  fvdl Catch up with -current. Fix some bogons in the sparc64 kbd/ms
attach code. cd18xx conversion provided by mrg.
 1.21.2.3  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.21.2.2  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.21.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.29.2.1  31-Aug-2002  gehenna catch up with -current.
 1.37.2.9  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.37.2.8  01-Apr-2005  skrll Sync with HEAD.
 1.37.2.7  08-Mar-2005  skrll Sync with HEAD.
 1.37.2.6  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.37.2.5  04-Feb-2005  skrll Sync with HEAD.
 1.37.2.4  02-Nov-2004  skrll Sync with HEAD.
 1.37.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.37.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.37.2.1  03-Aug-2004  skrll Sync with HEAD
 1.40.4.1  24-Jan-2005  he Pull up revision 1.43 (requested by thorpej in ticket #939):
When adding or deleting multicast addresses, only change
the address filter if the interface is marked RUNNING.
Fixes PR#27678.
 1.43.6.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.43.6.1  12-Feb-2005  yamt sync with head.
 1.43.4.1  29-Apr-2005  kent sync with -current
 1.49.2.1  27-May-2007  bouyer Pull up following revision(s) (requested by hubertf in ticket #1774):
sys/dev/ic/hme.c: revision 1.50
Fix typo in HW checksum code -- check for TCP & UDP HW checksumming being
enabled rather than TCP twice.
 1.51.2.7  11-Feb-2008  yamt sync with head.
 1.51.2.6  04-Feb-2008  yamt sync with head.
 1.51.2.5  21-Jan-2008  yamt sync with head
 1.51.2.4  27-Oct-2007  yamt sync with head.
 1.51.2.3  03-Sep-2007  yamt sync with head.
 1.51.2.2  30-Dec-2006  yamt sync with head.
 1.51.2.1  21-Jun-2006  yamt sync with head.
 1.53.8.1  14-Sep-2006  yamt sync with head.
 1.53.4.1  09-Sep-2006  rpaulo sync with head
 1.54.4.1  10-Dec-2006  yamt sync with head.
 1.54.2.1  12-Jan-2007  ad Sync with head.
 1.55.4.1  12-Mar-2007  rmind Sync with HEAD.
 1.56.4.1  11-Jul-2007  mjf Sync with head.
 1.56.2.4  23-Oct-2007  ad Sync with head.
 1.56.2.3  09-Oct-2007  ad Sync with head.
 1.56.2.2  15-Jul-2007  ad Sync with head.
 1.56.2.1  01-Jul-2007  ad Adapt to callout API change.
 1.58.8.2  23-Mar-2008  matt sync with HEAD
 1.58.8.1  06-Nov-2007  matt sync with HEAD
 1.58.6.2  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.58.6.1  03-Sep-2007  jmcneill Sync with HEAD.
 1.58.2.1  03-Sep-2007  skrll Sync with HEAD.
 1.59.4.1  25-Oct-2007  bouyer Sync with HEAD.
 1.60.8.2  23-Jan-2008  bouyer Sync with HEAD.
 1.60.8.1  20-Jan-2008  bouyer Sync with HEAD
 1.60.2.1  18-Feb-2008  mjf Sync with HEAD.
 1.63.6.2  17-Jan-2009  mjf Sync with HEAD.
 1.63.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.64.4.7  11-Aug-2010  yamt sync with head.
 1.64.4.6  11-Mar-2010  yamt sync with head
 1.64.4.5  16-Sep-2009  yamt sync with head
 1.64.4.4  20-Jun-2009  yamt sync with head
 1.64.4.3  16-May-2009  yamt sync with head
 1.64.4.2  04-May-2009  yamt sync with head.
 1.64.4.1  16-May-2008  yamt sync with head.
 1.64.2.1  18-May-2008  yamt sync with head.
 1.66.14.1  21-Apr-2010  matt sync to netbsd-5
 1.66.10.4  13-Nov-2009  sborrill Pull up the following revisions(s) (requested by jakllsch in ticket #1133):
sys/dev/ic/hme.c: revision 1.84 via patch

Use hme_init() to provide a non-NULL ifp->if_init.
 1.66.10.3  01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/gem.c: revision 1.83
sys/dev/ic/hme.c: revision 1.73
Fix a bug in calculation of checksum deduction:
- To get 16 bit one's complement value from uint32_t variable,
higher 16 bits should be ignored.
- RFC 1624 describes methods to recalculate checksum field in headers,
i.e. one's complement of one's complement sum that could be 0x0000,
but we don't have to use the strategy to deduct one's complement sum
itself which won't be zero but should be 0xffff.
Found on debugging mec(4) on sgimips O2.
 1.66.10.2  01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/hme.c: revision 1.70
Replace incorrect local ether_cmp() function with memcmp(9)
on checking multicast addresses, which is not so critical.
Noticed by FUKAUMI Naoki.
 1.66.10.1  01-May-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #595):
sys/dev/ic/hme.c: revision 1.69
Add an `else' missed in rev 1.49 otherwise RX hardware checksum on hme(4)
is not activated at all. Ok'ed by christos@, tested on macppc.
 1.66.8.2  28-Apr-2009  skrll Sync with HEAD.
 1.66.8.1  19-Jan-2009  skrll Sync with HEAD.
 1.66.6.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.68.2.2  23-Jul-2009  jym Sync with HEAD.
 1.68.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.85.4.1  30-May-2010  rmind sync with head
 1.85.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.86.12.1  18-Feb-2012  mrg merge to -current.
 1.86.8.2  30-Oct-2012  yamt sync with head
 1.86.8.1  17-Apr-2012  yamt sync with head
 1.87.2.2  14-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #1548):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.87.2.1  04-Jul-2012  riz Pull up following revision(s) (requested by jdc in ticket #368):
sys/dev/ic/hme.c: revision 1.88
share/man/man4/hme.4: revision 1.10
PR kern/46424
Revert the part of revision 1.77 that altered the PHY attachment order.
Note that the PHY instance changes when a MII transceiver is connected.
 1.89.12.1  07-Apr-2014  tls Be a little more clear and consistent about harvesting entropy from devices:

1) deprecate RND_FLAG_NO_ESTIMATE

2) define RND_FLAG_COLLECT_TIME, RND_FLAG_COLLECT_VALUE

3) define RND_FLAG_ESTIMATE_TIME, RND_FLAG_ESTIMATE_VALUE

4) define RND_FLAG_DEFAULT: RND_FLAG_COLLECT_TIME|
RND_FLAG_COLLECT_VALUE|RND_FLAG_ESTIMATE_TIME

5) Make entropy harvesting from environmental sensors a little more generic
and remove it from individual sensor drivers.

6) Remove individual open-coded delta-estimators for values from a few
places in the tree (uvm, environmental drivers).

7) 0 -> RND_FLAG_DEFAULT, actually gather entropy from various drivers
that had stubbed out code, other minor cleanups.
 1.89.2.2  03-Dec-2017  jdolecek update from HEAD
 1.89.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.90.4.6  28-Aug-2017  skrll Sync with HEAD
 1.90.4.5  05-Feb-2017  skrll Sync with HEAD
 1.90.4.4  05-Oct-2016  skrll Sync with HEAD
 1.90.4.3  09-Jul-2016  skrll Sync with HEAD
 1.90.4.2  19-Mar-2016  skrll Sync with HEAD
 1.90.4.1  06-Jun-2015  skrll Sync with HEAD
 1.90.2.1  14-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #1604):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.93.2.2  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.93.2.1  04-Nov-2016  pgoyette Sync with HEAD
 1.96.8.5  26-Jan-2019  pgoyette Sync with HEAD
 1.96.8.4  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.96.8.3  28-Jul-2018  pgoyette Sync with HEAD
 1.96.8.2  25-Jun-2018  pgoyette Sync with HEAD
 1.96.8.1  21-May-2018  pgoyette Sync with HEAD
 1.96.2.2  26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #938):
sys/arch/acorn32/podulebus/if_ie.c: revision 1.41
sys/arch/amiga/dev/if_es.c: revision 1.58
sys/arch/amiga/dev/if_qn.c: revision 1.45
sys/arch/arm/at91/at91emac.c: revision 1.20
sys/arch/arm/ep93xx/epe.c: revision 1.37
sys/arch/emips/ebus/if_le_ebus.c: revision 1.14
sys/arch/emips/ebus/if_le_ebus.c: revision 1.15
sys/arch/mac68k/dev/if_mc.c: revision 1.46
sys/arch/macppc/dev/am79c950.c: revision 1.39
sys/arch/newsmips/apbus/if_sn.c: revision 1.40
sys/arch/next68k/dev/mb8795.c: revision 1.59
sys/arch/playstation2/dev/if_smap.c: revision 1.25
sys/arch/playstation2/dev/if_smap.c: revision 1.26
sys/arch/sun2/dev/if_ec.c: revision 1.28
sys/arch/sun3/dev/if_ie.c: revision 1.63
sys/arch/x68k/dev/if_ne_intio.c: revision 1.19
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.75
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.63
sys/dev/bi/if_ni.c: revision 1.45
sys/dev/cadence/if_cemac.c: revision 1.12
sys/dev/ic/am7990.c: revision 1.78
sys/dev/ic/am79900.c: revision 1.27
sys/dev/ic/an.c: revision 1.67
sys/dev/ic/cs89x0.c: revision 1.40
sys/dev/ic/dm9000.c: revision 1.13
sys/dev/ic/dm9000.c: revision 1.14
sys/dev/ic/dp8390.c: revision 1.88
sys/dev/ic/elink3.c: revision 1.141
sys/dev/ic/elinkxl.c: revision 1.122
sys/dev/ic/hme.c: revision 1.98
sys/dev/ic/i82586.c: revision 1.77
sys/dev/ic/lance.c: revision 1.53
sys/dev/ic/mb86950.c: revision 1.27
sys/dev/ic/mb86960.c: revision 1.86
sys/dev/ic/mtd803.c: revision 1.34
sys/dev/ic/pdq_ifsubr.c: revision 1.59
sys/dev/ic/rrunner.c: revision 1.86
sys/dev/ic/seeq8005.c: revision 1.58
sys/dev/ic/sgec.c: revision 1.47
sys/dev/ic/smc90cx6.c: revision 1.72
sys/dev/ic/smc91cxx.c: revision 1.96
sys/dev/ic/tropic.c: revision 1.49
sys/dev/ic/wi.c: revision 1.245
sys/dev/isa/if_eg.c: revision 1.93
sys/dev/isa/if_el.c: revision 1.95
sys/dev/isa/if_iy.c: revision 1.101
sys/dev/ofw/ofnet.c: revision 1.58
sys/dev/pci/if_alc.c: revision 1.27
sys/dev/pci/if_de.c: revision 1.152
sys/dev/pci/if_fpa.c: revision 1.61
sys/dev/pci/if_jme.c: revision 1.34
sys/dev/pci/if_tl.c: revision 1.108
sys/dev/pci/if_vte.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe.h: revision 1.50
sys/dev/pcmcia/if_cnw.c: revision 1.62
sys/dev/pcmcia/if_malo_pcmcia.c: revision 1.17
sys/dev/pcmcia/if_ray.c: revision 1.89
sys/dev/pcmcia/if_xi.c: revision 1.81
sys/dev/pcmcia/mhzc.c: revision 1.51
sys/dev/pcmcia/xirc.c: revision 1.34
sys/dev/qbus/if_de.c: revision 1.33
sys/dev/qbus/if_qe.c: revision 1.78
sys/dev/qbus/if_qt.c: revision 1.22
sys/dev/sbus/be.c: revision 1.87
sys/dev/sbus/qe.c: revision 1.68
sys/dev/scsipi/if_se.c: revision 1.96
sys/dev/usb/if_atu.c: revision 1.59
sys/net/if_l2tp.c: revision 1.28 via patch
sys/net/if_ppp.c: revision 1.160
It's not required to include net/bpfdesc.h. Remove it.
--
Simplify like other drivers. NULL check of ifp->if_bpf is done in
bpf_mtap(), so it's not required to do it here.
--
Remove duplicated inclusion of net/bpf.h.
--
Remove duplicated inclusion of net/bpf.h.
--
Simplify bpf_mtap() call. No functional change.
 1.96.2.1  09-May-2018  martin Pull up following revision(s) (requested by pgoyette in ticket #815):

sys/dev/ic/hme.c: revision 1.97

Fix mis-placed right paren. kern/53271
 1.99.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.99.2.1  10-Jun-2019  christos Sync with HEAD
 1.105.4.1  29-Feb-2020  ad Sync with head.

RSS XML Feed