Home | History | Annotate | only in /src/sys/dev/mii
History log of /src/sys/dev/mii
RevisionDateAuthorComments
 1.8 11-Apr-2001  jdolecek Only install headers which are actually used by our userland. This
saves about 2.2MB under /usr/include/dev/. Discussed on tech-kern@
recently.

I HOPE to get the list right. The headers I left in are ones
used for MI tools and those whose usage I discovered by grep over tree sources.
Feel free to put needed includes back in if you encounter anything which
should not be removed from lists.
 1.7 07-Dec-1999  thorpej branches: 1.7.6;
Add a driver for the National Semiconductor DP83843 `PHYTER' 10/100
Ethernet PHY.
 1.6 07-Sep-1999  soren branches: 1.6.2; 1.6.8;
Spacing.
 1.5 07-Sep-1999  soren Install *reg.h
 1.4 05-Sep-1999  soren TDK Semiconductor 78Q2120 PHY, commonly used in low-power Cardbus cards.
 1.3 05-Sep-1999  soren Add PHY driver the the Intel 82553 found on some fxp's.
Some variants of this chip need a little extra MII fix before
being usable, so this is not yet put into GENERIC's.
 1.2 11-Aug-1998  thorpej Adapt to MII layer changes.
 1.1 12-Jun-1998  cgd Rework the way kernel include files are installed. In the new method,
as with user-land programs, include files are installed by each directory
in the tree that has includes to install. (This allows more flexibility
as to what gets installed, makes 'partial installs' easier, and gives us
more options as to which machines' includes get installed at any given
time.) The old SYS_INCLUDES={symlinks,copies} behaviours are _both_
still supported, though at least one bug in the 'symlinks' case is
fixed by this change. Include files can't be build before installation,
so directories that have includes as targets (e.g. dev/pci) have to move
those targets into a different Makefile.
 1.6.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.6.2.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.7.6.1 28-Feb-2002  nathanw Catch up to -current.
 1.4 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.3 19-Oct-2008  apb branches: 1.3.100;
Use ${TOOL_AWK} instead of ${AWK} or plain "awk" in make commands.
Pass AWK=${TOOL_AWK:Q} to shell scripts that use awk.
 1.2 08-May-2000  augustss branches: 1.2.126; 1.2.130; 1.2.136;
Allow a verbose description to be printed with the option MIIVERBOSE.
 1.1 10-Aug-1998  thorpej branches: 1.1.12;
Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.1.12.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.2.136.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.2.130.1 04-May-2009  yamt sync with head.
 1.2.126.1 17-Jan-2009  mjf Sync with HEAD.
 1.3.100.1 01-Aug-2021  thorpej Sync with HEAD.
 1.30 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.29 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.28 25-Mar-2019  msaitoh KNF. No functional change.
 1.27 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.26 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.25 07-Jul-2016  msaitoh branches: 1.25.16; 1.25.18;
KNF. Remove extra spaces. No functional change.
 1.24 16-Jun-2014  msaitoh branches: 1.24.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.23 17-Nov-2008  dyoung branches: 1.23.22; 1.23.26; 1.23.40;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.22 04-May-2008  xtraeme branches: 1.22.6; 1.22.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.21 08-Apr-2008  cegger branches: 1.21.2; 1.21.4;
use aprint_*_dev and device_xname
 1.20 09-Dec-2007  jmcneill branches: 1.20.10;
Merge jmcneill-pm branch.
 1.19 16-Nov-2006  christos branches: 1.19.22; 1.19.24; 1.19.34; 1.19.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.18 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.17 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.16 29-Mar-2006  thorpej branches: 1.16.8; 1.16.10;
Use device_private().
 1.15 11-Dec-2005  christos branches: 1.15.4; 1.15.6; 1.15.8; 1.15.10; 1.15.12;
merge ktrace-lwp.
 1.14 23-Aug-2004  thorpej branches: 1.14.12;
Make use of static.
 1.13 29-Apr-2003  thorpej branches: 1.13.2;
Use aprint*().
 1.12 26-Jan-2003  matt Add support for Am79C87[45].
 1.11 17-Jan-2003  gendalia Add altima (broadcom) AC101L, phy for 3com 3c905cx-tx on nForce2 MCP-T
 1.10 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.9 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.8 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.7 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.6 17-Apr-2002  wiz branches: 1.6.2;
Fix typo in comment. kern/16382 by Sean Davis.
 1.5 25-Mar-2002  thorpej Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.4 15-Dec-2001  augustss Add another Altima PHY. From Peter Seebach.
 1.3 13-Nov-2001  lukem add RCSID
 1.2 25-Aug-2001  thorpej branches: 1.2.4;
ANSI'ify.
 1.1 24-Aug-2001  thorpej branches: 1.1.2;
Driver for the Altima AC101 10/100 Ethernet PHY.
 1.1.2.7 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.1.2.1 24-Aug-2001  thorpej file acphy.c was added on branch kqueue on 2001-08-25 06:16:21 +0000
 1.2.4.9 17-Jan-2003  thorpej Sync with HEAD.
 1.2.4.8 18-Oct-2002  nathanw Catch up to -current.
 1.2.4.7 01-Aug-2002  nathanw Catch up to -current.
 1.2.4.6 20-Jun-2002  nathanw Catch up to -current.
 1.2.4.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.2.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.2.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.2.4.1 25-Aug-2001  nathanw file acphy.c was added on branch nathanw_sa on 2001-09-21 22:35:48 +0000
 1.6.2.1 15-Jul-2002  gehenna catch up with -current.
 1.13.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.14.12.3 21-Jan-2008  yamt sync with head
 1.14.12.2 30-Dec-2006  yamt sync with head.
 1.14.12.1 21-Jun-2006  yamt sync with head.
 1.15.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.15.10.1 19-Apr-2006  elad sync with head.
 1.15.8.1 01-Apr-2006  yamt sync with head.
 1.15.6.1 22-Apr-2006  simonb Sync with head.
 1.15.4.1 09-Sep-2006  rpaulo sync with head
 1.16.10.2 10-Dec-2006  yamt sync with head.
 1.16.10.1 22-Oct-2006  yamt sync with head
 1.16.8.1 18-Nov-2006  ad Sync with head.
 1.19.36.1 11-Dec-2007  yamt sync with head.
 1.19.34.1 26-Dec-2007  ad Sync with head.
 1.19.24.1 09-Jan-2008  matt sync with HEAD
 1.19.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.19.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.20.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.20.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.4.2 04-May-2009  yamt sync with head.
 1.21.4.1 16-May-2008  yamt sync with head.
 1.21.2.1 18-May-2008  yamt sync with head.
 1.22.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.22.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.23.40.1 10-Aug-2014  tls Rebase.
 1.23.26.2 03-Dec-2017  jdolecek update from HEAD
 1.23.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.22.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.24.4.1 09-Jul-2016  skrll Sync with HEAD
 1.25.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.25.18.1 10-Jun-2019  christos Sync with HEAD
 1.25.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 25-Aug-2001  thorpej branches: 1.2.2; 1.2.6;
Note compatibility with the Am79c874, and document some more
registers.
 1.1 24-Aug-2001  thorpej Driver for the Altima AC101 10/100 Ethernet PHY.
 1.2.6.2 21-Sep-2001  nathanw Catch up to -current.
 1.2.6.1 25-Aug-2001  nathanw file acphyreg.h was added on branch nathanw_sa on 2001-09-21 22:35:48 +0000
 1.2.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.2.2.1 25-Aug-2001  thorpej file acphyreg.h was added on branch kqueue on 2001-08-25 06:16:21 +0000
 1.27 08-Feb-2024  andvar s/should't/shouldn't/ and s/mistmatch/mismatch/ in comments.
 1.26 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.25 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.24 26-Nov-2019  msaitoh Fix typo in comment.
 1.23 25-Mar-2019  msaitoh KNF. No functional change.
 1.22 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.21 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.20 16-Jun-2014  msaitoh branches: 1.20.26; 1.20.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.19 17-Nov-2008  dyoung branches: 1.19.22; 1.19.26; 1.19.40;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.18 04-May-2008  xtraeme branches: 1.18.6; 1.18.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.17 08-Apr-2008  cegger branches: 1.17.2; 1.17.4;
use aprint_*_dev and device_xname
 1.16 09-Dec-2007  jmcneill branches: 1.16.10;
Merge jmcneill-pm branch.
 1.15 16-Nov-2006  christos branches: 1.15.22; 1.15.24; 1.15.34; 1.15.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.14 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.13 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.12 29-Mar-2006  thorpej branches: 1.12.8; 1.12.10;
Use device_private().
 1.11 11-Dec-2005  christos branches: 1.11.4; 1.11.6; 1.11.8; 1.11.10; 1.11.12;
merge ktrace-lwp.
 1.10 23-Aug-2004  thorpej branches: 1.10.12;
Make use of static.
 1.9 29-Apr-2003  thorpej branches: 1.9.2;
Use aprint*().
 1.8 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.7 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.6 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.5 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.4 25-Mar-2002  thorpej branches: 1.4.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.3 13-Nov-2001  lukem add RCSID
 1.2 25-Aug-2001  thorpej branches: 1.2.4; 1.2.6;
ANSI'ify.
 1.1 25-Aug-2001  thorpej Driver for the 10BASE-T portion of the AMD 79c901 PHY.
 1.2.6.6 18-Oct-2002  nathanw Catch up to -current.
 1.2.6.5 01-Aug-2002  nathanw Catch up to -current.
 1.2.6.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.2.6.2 21-Sep-2001  nathanw Catch up to -current.
 1.2.6.1 25-Aug-2001  nathanw file amhphy.c was added on branch nathanw_sa on 2001-09-21 22:35:48 +0000
 1.2.4.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.4.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.4.1 25-Aug-2001  thorpej file amhphy.c was added on branch kqueue on 2001-09-13 01:15:44 +0000
 1.4.2.1 15-Jul-2002  gehenna catch up with -current.
 1.9.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.10.12.3 21-Jan-2008  yamt sync with head
 1.10.12.2 30-Dec-2006  yamt sync with head.
 1.10.12.1 21-Jun-2006  yamt sync with head.
 1.11.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.11.10.1 19-Apr-2006  elad sync with head.
 1.11.8.1 01-Apr-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.12.10.2 10-Dec-2006  yamt sync with head.
 1.12.10.1 22-Oct-2006  yamt sync with head
 1.12.8.1 18-Nov-2006  ad Sync with head.
 1.15.36.1 11-Dec-2007  yamt sync with head.
 1.15.34.1 26-Dec-2007  ad Sync with head.
 1.15.24.1 09-Jan-2008  matt sync with HEAD
 1.15.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.15.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.16.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.16.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.17.4.2 04-May-2009  yamt sync with head.
 1.17.4.1 16-May-2008  yamt sync with head.
 1.17.2.1 18-May-2008  yamt sync with head.
 1.18.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.18.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.19.40.1 10-Aug-2014  tls Rebase.
 1.19.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.22.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.20.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.20.28.1 10-Jun-2019  christos Sync with HEAD
 1.20.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 06-Jun-2024  andvar s/chane/change/ in comment.
 1.1 25-Aug-2001  thorpej branches: 1.1.4; 1.1.6;
Driver for the 10BASE-T portion of the AMD 79c901 PHY.
 1.1.6.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.6.1 25-Aug-2001  nathanw file amhphyreg.h was added on branch nathanw_sa on 2001-09-21 22:35:48 +0000
 1.1.4.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.4.1 25-Aug-2001  thorpej file amhphyreg.h was added on branch kqueue on 2001-09-13 01:15:44 +0000
 1.33 04-Oct-2025  thorpej Use device_{get,set}prop_bool() for rgmii-related properties.
 1.32 20-Jul-2024  andvar fix typos in comments, mainly s/harware/hardware/.
 1.31 22-Feb-2023  msaitoh branches: 1.31.6;
Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.30 15-Mar-2020  thorpej branches: 1.30.22;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.29 13-Mar-2020  msaitoh 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.28 13-Mar-2020  msaitoh 0x001374 is non-bitreversed value of Attansic OUI(0x00c82e).

Attansic/Atheros correctly uses ID1 and ID2 register, so delete all 0x001374
related entries.
 1.27 13-Dec-2019  msaitoh KNF. No functional change.
 1.26 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.25 20-Nov-2019  msaitoh Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.24 18-Oct-2019  hkenken Modified atphy(4)

* Support CLK_25M clock out.
* Support internal delay for RGMII interface.
 1.23 02-Sep-2019  msaitoh s/etphy/atphy/. No functional change.
 1.22 11-Apr-2019  msaitoh branches: 1.22.4;
Simplify. No functional change.
 1.21 25-Mar-2019  msaitoh KNF. No functional change.
 1.20 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.19 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.18 02-Nov-2016  msaitoh branches: 1.18.8; 1.18.14; 1.18.16;
Set mii_mpd_{oui,model,rev}.
 1.17 08-Sep-2015  msaitoh branches: 1.17.2;
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.16 16-Jun-2014  msaitoh branches: 1.16.2; 1.16.4; 1.16.6;
Fix a bug that atphy doesn't set the capability of pause function correctly.
This bug was added in "mii.h" rev. 1.17.
 1.15 16-Jun-2013  msaitoh branches: 1.15.6;
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.14 09-Jun-2013  msaitoh atphy, ciphy, ihphy and rgephy are gigabit PHY, so not only check IFM_AUTO
for autonegotiation but also check IFM_1000_T, too.
 1.13 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.12 23-Jul-2012  matt branches: 1.12.2;
Make it match AR8035
 1.11 02-Oct-2011  jmcneill branches: 1.11.2; 1.11.8; 1.11.12; 1.11.14;
Attansic L2 is 10/100 but the status registers report 1000 Mbps, so don't
bother reading MII_EXTSR for this part. Also use MII_ANEGTICKS instead of
MII_ANEGTICKS_GIGE for this part.
 1.10 23-Feb-2011  jmcneill match on MII_MODEL_ATTANSIC_L2

alc0 at pci3 dev 0 function 0: Atheros AR8152 v2.0 PCIe Fast Ethernet
alc0: ioapic0 pin 17
alc0: Ethernet address 00:26:6c:9e:d4:c1
atphy0 at alc0 phy 0: L2 10/100 PHY, rev. 5
atphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT-FDX, auto
 1.9 22-Jan-2011  cegger fix comment. from PR kern/44395
 1.8 22-Jan-2011  cegger Fixes from PR kern/44395 Masanori Kanaoka:
- Fix register address in ale_phy_reset(). from linux
- Fix mask value in ale_stop_mac().
- Fix multicast handling. from openbsd
- Fix phy reset handling.
 1.7 11-Dec-2010  matt branches: 1.7.2; 1.7.4;
Recognize AR8021
 1.6 25-Jul-2009  cegger branches: 1.6.4; 1.6.6;
- replace magic number with proper define from mii.h. From OpenBSD.
- fix typo in comment. From OpenBSD.
 1.5 27-Mar-2009  cegger branches: 1.5.2; 1.5.4;
use auto-negotiation for manual media type selection.
This should fix establishment of 10/100Mbps link on L1E.
Helpful to reduce watchdog timeout problems on L1 (age(4)) reported by Jochen Kunz.
From FreeBSD via OpenBSD.
 1.4 12-Feb-2009  cegger pretty print atphy's supported medias in dmesg.
 1.3 11-Feb-2009  cegger Attach atphy(4) on ATTANSIC oui.
ok cube@
 1.2 16-Jan-2009  cegger branches: 1.2.2; 1.2.4; 1.2.6;
add RCSID
 1.1 16-Jan-2009  cegger Driver for Attansic Technology F1 10/100/1000 Ethernet PHY.

Written by Pyun YongHyeon for FreeBSD, ported to OpenBSD by Kevin Lo, ported to
NetBSD by me.
 1.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 16-Jan-2009  skrll file atphy.c was added on branch nick-hppapmap on 2009-01-19 13:18:14 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 16-Jan-2009  mjf file atphy.c was added on branch mjf-devfs2 on 2009-01-17 13:28:57 +0000
 1.5.4.3 19-Aug-2009  yamt sync with head.
 1.5.4.2 04-May-2009  yamt sync with head.
 1.5.4.1 27-Mar-2009  yamt file atphy.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:52 +0000
 1.5.2.3 07-Nov-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1978):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.5.2.2 03-May-2009  snj branches: 1.5.2.2.2; 1.5.2.2.4; 1.5.2.2.6;
Pull up following revision(s) (requested by cegger in ticket #735):
sys/dev/pci/if_age.c: revisions 1.1-1.28
sys/dev/pci/if_agereg.h: revisions 1.1-1.2
sys/dev/pci/if_ale.c: revisions 1.1-1.3
sys/dev/pci/if_alereg.h: revisions 1.1-1.2
sys/dev/pci/files.pci: revisions 1.310-1.313
sys/dev/mii/atphy.c: revisions 1.1-1.5
sys/dev/mii/files.mii: revision 1.42
share/man/man4/age.4: revisions 1.1-1.3
share/man/man4/ale.4: revisions 1.1-1.2
share/man/man4/atphy.4: revisions 1.1-1.2
share/man/man4/Makefile: revisions 1.486, 1.489
distrib/sets/lists/man/mi: revisions 1.1118, 1.1132
sys/arch/i386/conf/GENERIC: revisions 1.928, 1.933
sys/arch/i386/conf/XEN2_DOM0: revisions 1.57, 1.60
sys/arch/amd64/conf/GENERIC: revisions 1.239, 1.241
sys/arch/amd64/conf/XEN3_DOM0: revisions 1.38, 1.42
Add the age(4) and ale(4) drivers for Attansic L1 and Atheros
AR8121/AR8113/AR8114 devices respectively.
 1.5.2.1 27-Mar-2009  snj file atphy.c was added on branch netbsd-5 on 2009-05-03 23:45:47 +0000
 1.5.2.2.6.1 07-Nov-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1978):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
 1.5.2.2.4.1 07-Jan-2011  matt Match some more phys.
 1.5.2.2.2.1 07-Nov-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1978):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
 1.6.6.2 21-Apr-2010  matt sync to netbsd-5
 1.6.6.1 25-Jul-2009  matt file atphy.c was added on branch matt-nb5-mips64 on 2010-04-21 00:27:39 +0000
 1.6.4.1 05-Mar-2011  rmind sync with head
 1.7.4.2 05-Mar-2011  bouyer Sync with HEAD
 1.7.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.7.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.11.14.1 15-Nov-2015  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1325):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.11.12.1 15-Nov-2015  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1325):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.11.8.3 15-Nov-2015  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1325):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.11.8.2 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.11.8.1 04-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1146):
sys/dev/mii/mii_physubr.c: revision 1.79
sys/dev/mii/rgephy.c: revision 1.33
sys/dev/mii/brgphy.c: revision 1.66
sys/dev/mii/atphy.c: revision 1.15
sys/dev/mii/mii.h: revision 1.17
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.11.2.2 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.11.2.1 30-Oct-2012  yamt sync with head
 1.12.2.3 03-Dec-2017  jdolecek update from HEAD
 1.12.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.2.1 23-Jun-2013  tls resync from head
 1.15.6.1 10-Aug-2014  tls Rebase.
 1.16.6.1 04-Nov-2015  riz Pull up following revision(s) (requested by msaitoh in ticket #971):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.16.4.2 05-Dec-2016  skrll Sync with HEAD
 1.16.4.1 22-Sep-2015  skrll Sync with HEAD
 1.16.2.2 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1301):
sys/dev/mii/inphy.c: revision 1.55
sys/dev/mii/makphy.c: revision 1.42
sys/dev/mii/ikphy.c: revision 1.12
sys/dev/mii/atphy.c: revision 1.18
sys/dev/mii/ihphy.c: revision 1.10
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,rev}.
 1.16.2.1 04-Nov-2015  riz branches: 1.16.2.1.2;
Pull up following revision(s) (requested by msaitoh in ticket #971):
sys/dev/mii/atphy.c: revision 1.17
Fix incorrect argument of mii_anar(). Fixes PR#50206.
XXX pullup -[567]
 1.16.2.1.2.1 18-Jan-2017  skrll Sync with netbsd-5
 1.17.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.18.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.18.16.1 10-Jun-2019  christos Sync with HEAD
 1.18.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.18.8.2 14-Apr-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1529:

sys/dev/mii/miidevs 1.154, 1.162-1.167
sys/dev/mii/atphy.c 1.28 via patch
sys/dev/mii/brgphy.c 1.87 via patch
sys/dev/mii/etphy.c 1.5, 1.6 via patch
sys/dev/mii/rdcphy.c 1.6, 1.8 via patch

- Add support Broadcom BCM54213PE and some new RDC devices.
- Rename RDC to xxRDC.
- Use xxVIA instead of VIA.
- etphy(4):
- Rename ET1011 to ET1011C and add ET1011 support.
- Use mii_phy_flowstatus() to reflect flow status from negotiated
result.
- Use static.
- KNF.
 1.18.8.1 21-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1454:

sys/dev/mii/atphy.c 1.22-1.23, 1.25 via patch
sys/dev/mii/mii_physubr.c 1.88 via patch
sys/dev/mii/miivar.h 1.69 via patch

- Fix a bug that atphy(4) can't negotiate correctly when the media
setting is neither auto nor 1000baseT.
- Code cleanup.
 1.22.4.2 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.22.4.1 21-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #459):

sys/dev/mii/atphy.c: revision 1.23
sys/dev/mii/atphy.c: revision 1.25
sys/dev/mii/miivar.h: revision 1.69
sys/dev/mii/mii_physubr.c: revision 1.88

s/etphy/atphy/. No functional change.

Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.30.22.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.31.6.1 02-Aug-2025  perseant Sync with HEAD
 1.37 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.36 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.35 25-Mar-2019  msaitoh KNF. No functional change.
 1.34 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.33 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.32 07-Jul-2016  msaitoh branches: 1.32.16; 1.32.18;
KNF. Remove extra spaces. No functional change.
 1.31 16-Jun-2014  msaitoh branches: 1.31.4;
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.30 19-Oct-2009  bouyer branches: 1.30.18; 1.30.22; 1.30.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.29 18-Jan-2009  mrg Enable flow control and poll the status appropriately.

contributed anonymously.
 1.28 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.27 04-May-2008  xtraeme branches: 1.27.6; 1.27.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.26 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.25 08-Apr-2008  cegger branches: 1.25.2; 1.25.4;
use aprint_*_dev and device_xname
 1.24 05-Jan-2008  jdc branches: 1.24.6;
Updates from OpenBSD:
-- r1.15
Add some DSP init code for BCM5221's.

Values derived from Apple's GMAC driver, same init
code also exists in Linux's sungem_phy driver.

tested by miod@ pedro@ and otto@ on a few systems.
-- r1.16
Always explicitly set IFM_HDX for half-duplex.

From brad@
--
 1.23 09-Dec-2007  jmcneill branches: 1.23.2;
Merge jmcneill-pm branch.
 1.22 16-Nov-2006  christos branches: 1.22.2; 1.22.16; 1.22.22; 1.22.24; 1.22.30; 1.22.34; 1.22.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.21 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.20 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.19 29-Mar-2006  thorpej branches: 1.19.8; 1.19.10;
Use device_private().
 1.18 11-Dec-2005  christos branches: 1.18.4; 1.18.6; 1.18.8; 1.18.10; 1.18.12;
merge ktrace-lwp.
 1.17 17-Jan-2005  scw branches: 1.17.8;
Support Broadcom BCM5222 dual 10/100 media interface.
 1.16 24-Nov-2004  martin branches: 1.16.4;
Add BCM 4401 phy (from FreeBSD).
 1.15 23-Aug-2004  thorpej Make use of static.
 1.14 06-Jun-2003  martin branches: 1.14.2;
Only read media status bits when they are valid.
From Makoto Fujiwara in PR kern/21810.
 1.13 02-May-2003  scw Match Broadcom's BCM5214 Quad 10/100 media interface.
 1.12 29-Apr-2003  thorpej Use aprint*().
 1.11 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.10 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.9 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.8 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.7 25-Mar-2002  thorpej branches: 1.7.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.6 13-Nov-2001  lukem add RCSID
 1.5 25-Aug-2001  thorpej ANSI'ify.
 1.4 27-Jul-2001  thorpej Use the bit-swapped OUI for the 5221. (Have I mentioned that I really
don't like how the current MII_OUI() works?)
 1.3 27-Jul-2001  thorpej Add a 3Com 3c905B internal PHY.
 1.2 08-Jun-2001  enami branches: 1.2.2; 1.2.4;
Initialize sc->sc_anegticks to 5 on attach to prevent panic due to
assertion failure.
 1.1 02-Jun-2001  thorpej Driver for the Broadcom BCM5201/BCM5202 "Mini-Theta" Ethernet
PHYs. This is also the same PHY core as in the 3Com 3c905C.
The PHY is documented in the 3c905C manual.
 1.2.4.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.4.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.4.1 03-Aug-2001  lukem update to -current
 1.2.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.2.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.2.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.2.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.2.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.2.1 08-Jun-2001  nathanw file bmtphy.c was added on branch nathanw_sa on 2001-06-21 20:04:15 +0000
 1.7.2.1 15-Jul-2002  gehenna catch up with -current.
 1.14.2.5 24-Jan-2005  skrll Sync with HEAD.
 1.14.2.4 29-Nov-2004  skrll Sync with HEAD.
 1.14.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.14.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.16.4.1 29-Apr-2005  kent sync with -current
 1.17.8.3 21-Jan-2008  yamt sync with head
 1.17.8.2 30-Dec-2006  yamt sync with head.
 1.17.8.1 21-Jun-2006  yamt sync with head.
 1.18.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.18.10.1 19-Apr-2006  elad sync with head.
 1.18.8.1 01-Apr-2006  yamt sync with head.
 1.18.6.1 22-Apr-2006  simonb Sync with head.
 1.18.4.1 09-Sep-2006  rpaulo sync with head
 1.19.10.2 10-Dec-2006  yamt sync with head.
 1.19.10.1 22-Oct-2006  yamt sync with head
 1.19.8.1 18-Nov-2006  ad Sync with head.
 1.22.36.1 11-Dec-2007  yamt sync with head.
 1.22.34.1 26-Dec-2007  ad Sync with head.
 1.22.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.22.24.1 09-Jan-2008  matt sync with HEAD
 1.22.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.22.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.22.16.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.22.2.1 17-May-2008  bouyer Pull up following revision(s) (requested by jdc in ticket #1145):
src/share/man/man4/gem.4 1.5,1.6 via patch
src/sys/arch/sparc64/conf/GENERIC 1.97 via patch
src/sys/dev/ic/gem.c 1.59,1.61-1.68,1.70-1.73 via patch
src/sys/dev/ic/gemreg.h 1.11 via patch
src/sys/dev/ic/gemvar.h 1.16,1.18 via patch
src/sys/dev/mii/bmtphy.c 1.24 via patch
src/sys/dev/pci/if_gem_pci.c 1.25,1.27 via patch
src/sys/dev/pci/pcidevs 1.12 via patch
src/sys/dev/pci/pcidevs.h regenerate
src/sys/dev/pci/pcidevs_data.h regenerate
Add support for Sun PCI X1141A (SX fibre) cards.
Add improvements to the driver.
Disable HW UDP4 and RX TCP4 checksums because they are buggy (PR#34799)
Add improvements to bmtphy.
 1.23.2.1 08-Jan-2008  bouyer Sync with HEAD
 1.24.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.24.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.4.3 11-Mar-2010  yamt sync with head
 1.25.4.2 04-May-2009  yamt sync with head.
 1.25.4.1 16-May-2008  yamt sync with head.
 1.25.2.1 18-May-2008  yamt sync with head.
 1.27.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.27.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.30.36.1 10-Aug-2014  tls Rebase.
 1.30.22.2 03-Dec-2017  jdolecek update from HEAD
 1.30.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.30.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.31.4.1 09-Jul-2016  skrll Sync with HEAD
 1.32.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.32.18.1 10-Jun-2019  christos Sync with HEAD
 1.32.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4 06-Jun-2024  andvar s/dupled/duplex/ in comments.
 1.3 03-Jun-2023  andvar fix various typos in comments and messages.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 02-Jun-2001  thorpej branches: 1.1.2; 1.1.122; 1.1.124; 1.1.126;
Driver for the Broadcom BCM5201/BCM5202 "Mini-Theta" Ethernet
PHYs. This is also the same PHY core as in the 3Com 3c905C.
The PHY is documented in the 3c905C manual.
 1.1.126.1 16-May-2008  yamt sync with head.
 1.1.124.1 18-May-2008  yamt sync with head.
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 02-Jun-2001  nathanw file bmtphyreg.h was added on branch nathanw_sa on 2001-06-21 20:04:16 +0000
 1.91 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.90 25-May-2020  jmcneill branches: 1.90.20;
Add support for BCM54213PE RGMII clock delays, from OpenBSD
 1.89 28-Mar-2020  thorpej Don't set DVF_DETACH_SHUTDOWN. The MII layer wants to manage the lifecycle
of the PHY devices, and if a NIC driver chooses not to detach its PHYs
at shutdown, that's the driver's business.

PR kern/55121.
 1.88 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.87 22-Feb-2020  jmcneill Match BCM54213PE
 1.86 27-Nov-2019  msaitoh branches: 1.86.2;
- Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.85 26-Nov-2019  msaitoh Fix typo in comment.
 1.84 11-Apr-2019  msaitoh branches: 1.84.4;
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. Same as a part of
FreeBSD r217413.
 1.83 25-Mar-2019  msaitoh KNF. No functional change.
 1.82 25-Feb-2019  msaitoh - Add Broadcom BCM540[24], BCM5424 and BCM5466.
- Sort lines.
 1.81 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.80 20-Feb-2019  msaitoh - Add support for BCM5762 ASIC devices.
- Add BCM5762, BCM5725, BCM5727, BCM57764, BCM57767 and BCM57787.
 1.79 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.78 11-Jan-2019  msaitoh Remove extra PHY read in brgphy_mii_phy_auto().
 1.77 08-Jan-2019  msaitoh Whitespace fixes. No functional change.
 1.76 02-Jul-2014  msaitoh branches: 1.76.20; 1.76.26; 1.76.28;
Add BCM5706.
 1.75 02-Jul-2014  msaitoh - 5720S and 5709S share the same PHY id. Assume 5720S PHY if parent device
is bge(4). Same as FreeBSD. Tested on HP Moonshot.
- Fix media detect on some Fiber chips. Tested on my own BCM5709 card.
Same as {Free,Open}BSD.
 1.74 02-Jul-2014  msaitoh Don't check BNX_CHIP_NUM. Check MII PHY ID because this check is used
for both bge(4) and bnx(4).
 1.73 02-Jul-2014  msaitoh - Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
- s/u_int/uint/
- KNF.
 1.72 18-Jun-2014  msaitoh Fix uninitiazed variable problem found on zaurus. I don't know why
only zaurus found it.
 1.71 17-Jun-2014  msaitoh - Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Add BCM5708S support in brgphy(4). The auto negotiation may have some bugs.
- Add 2500SX support (not tested).
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
 1.70 16-Jun-2014  msaitoh IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.69 12-Jun-2014  msaitoh No functional change:
- Remove BRGPHY_SERDES_ANAR_* and BRGPHY_SERDES_ANLPAR_*. Those registers
are the same as MII_ANAR_* and MII_ANLPAR_*.
- Fix typo.
- Remove trailing white spaces.
- KNF.
 1.68 31-Oct-2013  msaitoh branches: 1.68.2;
Cleanup flag setting. No functional change.
- Split flags into bge_flags and bge_phy_flags.
- Rename flags. PHY related flags are prefixed with BGEPHYF_*.
Other flags are prefixed with BGEF_*.
 1.67 21-Jun-2013  msaitoh branches: 1.67.2;
Call brgpy specific autonego function in MII_TICK. Before this commit,
only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK calls MI
mii_phy_auto(). That was not intended.
 1.66 16-Jun-2013  msaitoh The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.65 14-Jun-2013  msaitoh KNF.
 1.64 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.63 01-Apr-2013  msaitoh In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before PHY_RESET()
because brgphy_reset() refers those flags.
 1.62 19-Mar-2013  msaitoh - Rename PHY related flags for the consistency. It's the same as FreeBSD.
- Remove BGE_10_100_ONLY flag because this was not used.
For 10/100 devices, when calling mii_attach(), mask BMSR_EXTSTAT flag to
not to check Gigabit flags. It's the same as FreeBSD.
 1.61 15-Mar-2013  msaitoh Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
 1.60 17-Sep-2012  tsutsui Add support for BCM57765. PR kern/46961
 1.59 07-Jun-2011  cegger branches: 1.59.2; 1.59.8; 1.59.12;
add BCM5785 phy:

brgphy0 at bge0 phy 1: BCM5785 1000BASE-T media interface, rev. 3
brgphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT, 1000baseT-FD , auto
 1.58 02-May-2011  jym branches: 1.58.2;
Fix BCM5709 PHY detection for ethernet PHYs (the SerDes case being already
handled):
- export bge(4) and bnx(4) CHIP ID and PHY flags to brgphy(4). Move to
"unsigned int" rather than "int", and reuse the same softc members for
chipid and phyflags (behavior controlled by the sc_isbge/isbnx boolean).
- apply bug fix for revisions A and B, so that autonegotiation can
complete (from OpenBSD).

Bug reported by Rivo Nurges via private mail, patch tested and
confirmed working by him (with thanks!)
 1.57 09-Dec-2010  jym branches: 1.57.2;
Add support for BCM5709S (SerDes PHY) in brgphy(4).

From FreeBSD, via OpenBSD, with some minor adaptations.

No comments, no objections on tech-kern@.

The driver was tested on a Dell M710. Access was kindly provided by
Uwe Toenjes, whom I thank for this.

See also http://mail-index.netbsd.org/tech-kern/2010/12/01/msg009478.html
 1.56 27-Nov-2010  jym Use device_private() instead of casting softc to (void *).
 1.55 02-May-2010  pgoyette Include support for BCM5481. From OpenBSD and confirmed to work by
myself on XFX nForce 790i motherboard.
 1.54 27-Apr-2010  dyoung For a couple of flags, use bool/true/false instead of int/1/0.
 1.53 13-Mar-2010  kiyohara branches: 1.53.2;
Add Broadcom BCM5482.
It tested on OpenBlockS600. (coming soon ;-)
And reorder.
 1.52 24-Jan-2010  msaitoh branches: 1.52.2;
Add support for BCM5461,BCM5784 and BCM5761.
Enable brgphy_jumbo_settings().
Enable the Ethernet@Wirespeed function.
 1.51 18-Nov-2009  bouyer Support BCM5709CAX and BCM5709C PHYs.
 1.50 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.49 12-Aug-2009  simonb Match the Broadcom BCM5464 PHY.
 1.48 17-Jun-2009  tsutsui Unwrap not so long lines.
 1.47 17-Jun-2009  tsutsui - no need to use device_parent() because device_t parent is passed
via config_attach(9)
- use device_is_a() rather than strcmp() for readability
 1.46 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.45 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.44 23-Apr-2009  msaitoh use proplib
 1.43 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.42 07-Apr-2009  dyoung Detach brgphy(4) at shutdown.
 1.41 17-Nov-2008  dyoung branches: 1.41.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.40 25-Aug-2008  cegger branches: 1.40.2; 1.40.4; 1.40.8;
PR 39241: Add support for Broadcom BCM5906(M) from Karl Uwe Lockhoff
 1.39 04-May-2008  xtraeme branches: 1.39.2; 1.39.6;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.38 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.37 08-Apr-2008  cegger branches: 1.37.2; 1.37.4;
use aprint_*_dev and device_xname
 1.36 20-Feb-2008  markd branches: 1.36.6;
Add BCM5708C. Treating it like 5750/5780 is a guess but my Dell
PowerEdge 1950 now successfully negotiates 1000baseT full-duplex
where it didn't previously.
 1.35 09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.34 06-Aug-2007  markd branches: 1.34.2; 1.34.10; 1.34.12; 1.34.14;
Add support for BCM5754 and BCM5755. From suggestions from Jonathan
Stone.
 1.33 13-Mar-2007  msaitoh branches: 1.33.6; 1.33.10;
tabify
 1.32 10-Mar-2007  msaitoh branches: 1.32.2; 1.32.4;
Commit from AsiaBSDCon 2007's place

Fix the problem "ifconfig bge0 media auto" negotiates to 100Mbps on 1000BaseT
HUB.
 1.31 26-Nov-2006  tsutsui branches: 1.31.2; 1.31.4;
Match BCM5752 PHY. From Matthias Drochner and FreeBSD/OpenBSD.
 1.30 16-Nov-2006  christos - don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.29 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.28 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.27 27-Apr-2006  jonathan branches: 1.27.8; 1.27.10;
Add PHY ID for the integral 1000base-T PHY in the bcm5780 (also known
as Broadcom/Serverworks HT-2000). Following the Broadcom-supplied
Linux driver, update brgphy.c to treat the bcm5780 integral copper PHY
just like the 5714/5715 PHY.

For NetBSB-3 pullup purposes, this commit includes:

src/sys/dev/mii/miidevs revision: 1.65 -> 1.66
src/sys/dev/mii/brgphy.c revision: 1.26 -> 1.27

plus a regen of src/sys/dev/mii/{miidevs.h,miidevs_data.h}.
 1.26 29-Mar-2006  thorpej Use device_private().
 1.25 10-Dec-2005  jonathan branches: 1.25.4; 1.25.6; 1.25.8; 1.25.10; 1.25.12;
Oops! Restore brgphys[]z stanza for bcm5705 integral PHY, somehow
lost in the previous addition of the bcm5714 integral phy.
 1.24 08-Dec-2005  jonathan Add PHY mii-id for the Broadcom 1000base-T PHY integral to the
bcm5714, added yesterday to sys/dev/pci/if_bge.c in revision 1.98,
since it appears the 5714 has a new PHY revision. Pending further
details, follow the FreeBSD code (as submitted by
John Cagle <john dot cagle at hp dot com> and committed by
ps@FreeBSD.ORG), and treat the 5714 integral PHY the same way as we
treat the bcm5750 integral PHY.
 1.23 27-Feb-2005  perry branches: 1.23.2; 1.23.4;
nuke trailing whitespace
 1.22 28-Oct-2004  cube branches: 1.22.4; 1.22.6;
Add support for the PHY found with BCM575x chips. Beware the magic
numbers!

From FreeBSD.
 1.21 23-Aug-2004  thorpej Make use of static.
 1.20 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.19 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.18 17-Jul-2003  hannken Add support for the BCM5705:
- Only BCM5705M asic rev A1 was tested.

Thanks to Bill Paul (wpaul@freebsd.org) for help and support.

Approved by: Frank van der Linden <fvdl@netbsd.org>
 1.17 29-Apr-2003  thorpej branches: 1.17.2;
Use aprint*().
 1.16 16-Jan-2003  jonathan Update first 16-bit word of 5401 DSP patch to match latest Linux drivers.
Add comment saying what the magic values do: disable tap power management.
 1.15 16-Jan-2003  jonathan Add PHY entry for bcm5704c (copper) integral phy to miidevs.
Add 5704 phy and dsp patch, and untestsed dsp patch for 5703, to brgphy.c.
 1.14 27-Dec-2002  matt Recognize BCM5703 phy. (with this and the bge changes, the bge0 on my
ASUS P4PE m/b is now working)
 1.13 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.12 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.11 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.10 13-Jul-2002  thorpej Move the BCM5401 DSP patch out of the bge driver and into
the brgphy driver; all users of the BCM5400 and BCM5401 need
the DSP patch and the sledgehammer-reset-at-media-set-time.

Also add a DSP patch for the BCM5411 gleaned from Apple's
GMAC driver for Darwin.

Tested with a 3Com 3c996-T (BCM5700 + BCM5401).
 1.9 12-Jul-2002  thorpej Match the BCM5421, found on the Apple Xserve. From Matt Thomas.
 1.8 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.7 22-Jun-2002  fvdl Match BCM5701
 1.6 25-Mar-2002  thorpej branches: 1.6.2; 1.6.4;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.5 13-Nov-2001  lukem add RCSID
 1.4 25-Aug-2001  thorpej ANSI'ify.
 1.3 30-Jun-2001  bjh21 branches: 1.3.2;
IFM_1000_TX -> IFM_1000_T, as (breifly) discussed on tech-net.
 1.2 02-Jun-2001  thorpej branches: 1.2.2;
Make PHY matching all table-driven.
 1.1 01-Jun-2001  thorpej Driver for Broadcom BCM5400-family Gig-E PHYs. Programming
information gleaned from FreeBSD.
 1.2.2.10 17-Jan-2003  thorpej Sync with HEAD.
 1.2.2.9 29-Dec-2002  thorpej Sync with HEAD.
 1.2.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.2.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.2.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.2.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.2.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.2.1 02-Jun-2001  nathanw file brgphy.c was added on branch nathanw_sa on 2001-06-21 20:04:16 +0000
 1.3.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.3.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.3.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.6.4.2 28-Jan-2003  jmc Pullup revisions 1.9-1.10,1.13-1.16 (requested by fvdl in ticket #1126)
Pullup support for bge device. (Broadcom Gigabit Ethernet)
 1.6.4.1 12-Jul-2002  thorpej Match BCM5421 and BCM5701. Spurred by pullup-1-6 ticket #492.
 1.6.2.1 15-Jul-2002  gehenna catch up with -current.
 1.17.2.7 11-Dec-2005  christos Sync with head.
 1.17.2.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.17.2.5 02-Nov-2004  skrll Sync with HEAD.
 1.17.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.17.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.17.2.1 03-Aug-2004  skrll Sync with HEAD
 1.22.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.22.4.1 29-Apr-2005  kent sync with -current
 1.23.4.5 27-Feb-2008  yamt sync with head.
 1.23.4.4 21-Jan-2008  yamt sync with head
 1.23.4.3 03-Sep-2007  yamt sync with head.
 1.23.4.2 30-Dec-2006  yamt sync with head.
 1.23.4.1 21-Jun-2006  yamt sync with head.
 1.23.2.4 23-Sep-2007  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1842):
sys/dev/mii/miidevs: revisions 1.69, 1.71
sys/dev/mii/brgphy.c: revisions 1.31 - 1.34
Add support for BCM5752, BCM5754 and BCM5755.
Fix the problem "ifconfig bge0 media auto" negotiates to 100Mbps
on 1000BaseT HUB.
 1.23.2.3 28-Apr-2006  riz Pull up following revision(s) (requested by jonathan in ticket #1292):
sys/dev/mii/brgphy.c: revision 1.27
sys/dev/mii/miidevs: revision 1.66
Add PHY ID for the integral 1000base-T PHY in the bcm5780 (also known
as Broadcom/Serverworks HT-2000). Following the Broadcom-supplied
Linux driver, update brgphy.c to treat the bcm5780 integral copper PHY
just like the 5714/5715 PHY.
For NetBSB-3 pullup purposes, this commit includes:
src/sys/dev/mii/miidevs revision: 1.65 -> 1.66
src/sys/dev/mii/brgphy.c revision: 1.26 -> 1.27
plus a regen of src/sys/dev/mii/{miidevs.h,miidevs_data.h}.
 1.23.2.2 29-Dec-2005  riz Pull up following revision(s) (requested by jonathan in ticket #1044):
sys/dev/mii/brgphy.c: revision 1.25
Oops! Restore brgphys[]z stanza for bcm5705 integral PHY, somehow
lost in the previous addition of the bcm5714 integral phy.
 1.23.2.1 29-Dec-2005  riz Pull up following revision(s) (requested by jonathan in ticket #1044):
sys/dev/mii/brgphy.c: revision 1.24
sys/dev/mii/miidevs: revision 1.61
Add PHY mii-id for the Broadcom 1000base-T PHY integral to the
bcm5714, added yesterday to sys/dev/pci/if_bge.c in revision 1.98,
since it appears the 5714 has a new PHY revision. Pending further
details, follow the FreeBSD code (as submitted by
John Cagle <john dot cagle at hp dot com> and committed by
ps@FreeBSD.ORG), and treat the 5714 integral PHY the same way as we
treat the bcm5750 integral PHY.
 1.25.12.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.25.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.25.10.2 11-May-2006  elad sync with head
 1.25.10.1 19-Apr-2006  elad sync with head.
 1.25.8.2 24-May-2006  yamt sync with head.
 1.25.8.1 01-Apr-2006  yamt sync with head.
 1.25.6.2 01-Jun-2006  kardel Sync with head.
 1.25.6.1 22-Apr-2006  simonb Sync with head.
 1.25.4.1 09-Sep-2006  rpaulo sync with head
 1.27.10.2 10-Dec-2006  yamt sync with head.
 1.27.10.1 22-Oct-2006  yamt sync with head
 1.27.8.2 12-Jan-2007  ad Sync with head.
 1.27.8.1 18-Nov-2006  ad Sync with head.
 1.31.4.2 24-Mar-2007  yamt sync with head.
 1.31.4.1 12-Mar-2007  rmind Sync with HEAD.
 1.31.2.3 18-Aug-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1342):
sys/dev/pci/if_bge.c: revisions 1.135, 1.146, 1.151-1.152,
1.155-1.167 via patch
sys/dev/pci/if_bgereg.h: revisions 1.43, 1.48-1.52
sys/dev/pci/if_bgevar.h: revision 1.1
sys/dev/mii/brgphy.c: revisions 1.36, 1.40, 1.43-1.44 and
1.47-1.48 via patch
sys/dev/mii/brgphyreg.h: revisions 1.3-1.4
sys/dev/mii/miidevs: revisions 1.75, 1.77, 1.85
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs_data.h: regen
sys/dev/mii/miivar.h: revision 1.54
For bge:
- Really set Tx threshold.
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the "link changed" bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
- Add BCM5786 support.
for brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2, BCM5708C, BCM5722, and BCM5906.
 1.31.2.2 31-Aug-2007  xtraeme Pull up following revision(s) (requested by phil in ticket #819):
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs: revision 1.71
sys/dev/pci/if_bge.c: revision 1.133
sys/dev/pci/if_bge.c: revision 1.134
sys/dev/pci/if_bgereg.h: revision 1.43
sys/dev/mii/brgphy.c: revision 1.34
sys/dev/mii/miidevs_data.h: regen
Add BCM5755 and 5754 Gig-E PHYs.
Regen for BCM5755 and 5754.
Add support for BCM5754 and BCM5755. From suggestions from Jonathan
Stone.
Add a couple more BGE_CHIPIDs
Add support for BCM5755 and BCM5754/5787. Suggestions from Jonathan
Stone and fixes from OpenBSD for various hardware bugs/errata.
Disable firmware fastboot on 5754 and 5755. From FreeBSD by way of Phil
Nelson.
 1.31.2.1 26-Mar-2007  jdc branches: 1.31.2.1.2;
Pull up revisions 1.32-1.33 (requested by msaitoh in ticket #518).

Commit from AsiaBSDCon 2007's place

Fix the problem "ifconfig bge0 media auto" negotiates to 100Mbps on 1000BaseT
HUB.

tabify
 1.31.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.32.4.1 11-Jul-2007  mjf Sync with head.
 1.32.2.2 20-Aug-2007  ad Sync with HEAD.
 1.32.2.1 13-Mar-2007  ad Sync with head.
 1.33.10.4 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.33.10.3 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.33.10.2 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.33.10.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.33.6.1 15-Aug-2007  skrll Sync with HEAD.
 1.34.14.2 06-Aug-2007  markd Add support for BCM5754 and BCM5755. From suggestions from Jonathan
Stone.
 1.34.14.1 06-Aug-2007  markd file brgphy.c was added on branch matt-mips64 on 2007-08-06 12:16:34 +0000
 1.34.12.1 11-Dec-2007  yamt sync with head.
 1.34.10.1 26-Dec-2007  ad Sync with head.
 1.34.2.2 23-Mar-2008  matt sync with HEAD
 1.34.2.1 09-Jan-2008  matt sync with HEAD
 1.36.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.36.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.36.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.37.4.7 11-Aug-2010  yamt sync with head.
 1.37.4.6 11-Mar-2010  yamt sync with head
 1.37.4.5 19-Aug-2009  yamt sync with head.
 1.37.4.4 20-Jun-2009  yamt sync with head
 1.37.4.3 16-May-2009  yamt sync with head
 1.37.4.2 04-May-2009  yamt sync with head.
 1.37.4.1 16-May-2008  yamt sync with head.
 1.37.2.1 18-May-2008  yamt sync with head.
 1.39.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.39.6.1 19-Oct-2008  haad Sync with HEAD.
 1.39.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.40.8.1 21-Apr-2010  matt sync to netbsd-5
 1.40.4.4 09-Nov-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1983):
sys/dev/pci/pcidevs: revisions 1.1079, 1.1134, 1.1148-1.1149, 1.1151
sys/dev/pci/pcidevs.h: regen
sys/dev/pci/pcidevs_data.h: regen
sys/dev/pci/if_bge.c: revisions 1.183-1.185, 1.187, 1.189-1.193, 1.195-1.199, 1.202-1.226, 1.228-1.237, 1.240-1.264, 1.267-1.276, 1.278-1.280, 1.283-1.287 via patch
sys/dev/pci/if_bgereg.h: revisions 1.57-1.74, 1.76-1.90 via patch
sys/dev/pci/if_bgevar.h: revisions 1.6, 1.10-1.13, 1.15-1.17 via patch
sys/dev/pci/if_bnx.c: revisions 1.32, 1.34-1.43, 1.48-1.49, 1.52
sys/dev/pci/if_bnxreg.h: revisions 1.8, 1.11-1.14
sys/dev/pci/if_bnxvar.h: revisions 1.1-1.3
sys/dev/mii/brgphy.c: revisions 1.53-1.63, 1.65-69, 1.72-1.74 via patch
sys/dev/mii/brgphyreg.h: revisions 1.5-1.8
sys/dev/mii/miivar.h: revisions 1.61
sys/dev/pci/pcireg.h: patch

Sync bge(4) up to if_bge.c rev. 1.287. Sync brgphy(4) up to 1.74.
Fix some bugs on bnx(4).

Common:
- Add device IDs for Broadcom BCM57710, BCM57711(E), BCM57712(E) and
BCM57766 (pcidevs only).
- Fix BCM5709 PHY detection.
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Add BCM5708S support in brgphy(4).
- Don't use the WIRESPEED function for fiber devices.
bge(4):
- Add some Fujitsu's device support from Michael Moll.
- Add BCM57762 support (PR#46961 from Ryo Onodera).
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F. BCM5785G,
BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- Fix DMA setting for read/write on conventional PCI bus devices.
This bug was added in rev. 1.166.
- Fix printing "discarding oversize frame (len=-4)" message and
crash by NULL pointer dereferencing.
- The BCM5785 is a PCIe chip but does not report PCIe capabilities.
Check for this chip explicitely and enable PCIe. Fixes
'firmware handshake timeout'.
- Allow disabling interrupt mitigation.
- Workaround for BCM5906 silicon bug. When auto-negotiation results
in half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292).
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785. (FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf. (FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC. (FreeBSD
r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems we have
seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case. Note that
{tcp,udp}6csum flag is currently not added in the capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking.
- Do not touch the jumbo replenish threshold register on chips that do
not have jumbo support.
- Wait for the bootcode to complete initialization for 5717 and newer
devices.
- 5718 and 57785 document say we should wait 100us in init.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix the setting of Tx Random Backoff Register.
- Check the hardware config words and print them.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind(). Fixes PR#47716.
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Set DMA watermark depend on the PCI max payload size.
- Set BGE_JUMBO_CAPABLE correctly.
- Fix a link detect bug on non-autopoll systems.
- Change the TX ring size for 5717 series and 57764 series.
- Set maximum read byte count to 2048 for PCI-X BCM5703/5704 devices.
- For PCI-X BCM5704, set maximum outstanding split transactions to 0.
- Add 40bit DMA bug workaround(BGEF_40BIT_BUG) from FreeBSD.
This workaround is for 5714/5715 controllers and is not actually a
MAC controller bug but an issue with the embedded PCIe to PCI-X
bridge in the device. This change uses bus_dmatag_subregion(),
so this workaround won't work on some archs which doesn't support
bus_dmatag_subregion().
- Add 2500SX support (not tested).
- Don't use the PHY Auto Poll Mode on many chips. This fixes a bug
that MII Fiber NIC drop packet about 50%. Tested on HP Moonshot.
- Add workaround for PR#48451. Some BCM5717-5720 based systems getNMI
on boot. This problem doesn't occur when we don't use prefetchable
memory in the APE area. Tested with HP MicroServer Gen8.
- In the BCM5703, the DMA read watermark should be set to less than
or equal to the maximum memory read byte count of the PCI-X command
register.
- Fix a bug that BGE_PHY_TEST_CTRL_REG isn't set correctly on some
PCIe devices.
- Use another firmware command in bge_asf_driver_up(). Same as Linux.
This change fixes a bug that watchdog timeout occurs every 25-30
minutes on HP ML110 G6 reported enami@ in PR#49657.
- Fix mbuf leak on failure.
- Remove PCI_PRODUCT_BROADCOM_BCM5724 and
PCI_PRODUCT_BROADCOM_BCM5750M. These devices have not released to
public.
- Add some workaround code for BGE_ASICREV_BCM5784 from Linux.
- Change some printf() to aprint_*().
- Fix typo in comments.
- Cleanup.
brgphy(4):
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
- Add BCM5481, BCM5709S, BCM5756, BCM5717C, BCM5720C, BCM5785,
BCM57765(PR#46961), BCM57780
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this
commit, only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK
calls MI mii_phy_auto(). That was not intended.
- Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
bnx(4):
- Add missing ifmedia_delete_instance() in bnx_detach().
- Fix a bug that BNX_NO_WOL_FLAG isn't correctly set on some chips.
Reported by From Henning Petersen in PR#44151.
- Fix SERDES initialization.
- Get out of the interrupt handler early if !IFF_RUNNING.
 1.40.4.3 19-Nov-2010  riz Pull up revisions (requested by msaitoh in ticket #1359):
sys/dev/pci/if_bge.c 1.170-1.181
sys/dev/pci/if_bgereg.h 1.53-1.56
sys/dev/pci/if_bgevar.h 1.2-1.5
sys/dev/pci/pcidevs 1.1017, 1.1021
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/miidevs 1.89, 1.93
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/dev/mii/brgphy.c 1.49, 1.52

- Fix a bug of BGE_RDMA_MODE_FIFO_LONG_BURST definition.
- Fix the bug that both BGE_PCIE and BGE_PCIX are set on PCI-Express devices.
- Add support for BCM5705F,BCM5714,SBCM5715S,BCM5717,BCM5718,BCM5720,BCM5723,
BCM5724,BCM5751F,BCM5753F,BCM5756,BCM5761,BCM5761E,BCM5761S,BCM5761SE,
BCM5764,BCM5781,BCM5784M,BCM5903M,BCM57760,BCM57761,BCM57765,BCM57780,
BCM57781,BCM57785,BCM57788,BCM57790,BCM57791 and BCM57795. Fixes PR#41694.
- Fix misunderstanding the capability for TSO4 on some chips.
- Use proplib for no EEPROM systems (e.g. sparc64 with onboard bge).
- Add debug function to show some flags.
- (brgphy(4)) Add support for BCM5461, BCM5464, BCM5784 and BCM5761.
- (brgphy(4)) Enable brgphy_jumbo_settings().
- (brgphy(4)) Enable the Ethernet@Wirespeed function.
- Add support for device properties to override the mac address and set
the BGE_NO_EEPROM flag if we have an onboard device w/o SEEPROM.
- Introduce IPMI and ASF related code from FreeBSD. It fixes some problems
which occured in netboot on sparc64 and PR#32767
- move the code of disabling host interrput in bge_stop() like linux tg3
driver.
- fix the return value of bge_eeprom_getbyte().
- Fixes the bug that error bits arent cleard because these bit are W2C
(in other words W1C).
- Many other bugfixes from FreeBSD and OpenBSD.
- remove an unused structure.
- ANSI C, KNF and tabify
- fix typo in comment.
 1.40.4.2 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1268):
sys/dev/mii/miidevs: revision 1.90
sys/dev/pci/pcidevs: revision 1.1001
sys/dev/mii/brgphy.c: revision 1.51
sys/dev/microcode/bnx/bnxfw.h: revision 1.3
sys/dev/pci/if_bnx.c: revision 1.29
sys/dev/pci/if_bnxreg.h: revision 1.9
sys/dev/pci/if_bnx.c: revision 1.30

Add support for the Broadcom BCM5709 and BCM5716 chips. Upgrade
the B06 firmware and add the B09 firmware required by the BCM5709.
Replace TX dmamap array with a dynamically-grown list.
Support associated BCM5709CAX and BCM5709C PHYs.
 1.40.4.1 04-Aug-2009  snj Apply patch (requested by msaitoh in ticket #866):
For bge:
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the 'link changed' bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
For brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2 and BCM5722.
 1.40.2.2 28-Apr-2009  skrll Sync with HEAD.
 1.40.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.41.4.2 23-Jul-2009  jym Sync with HEAD.
 1.41.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.52.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.52.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.53.2.4 12-Jun-2011  rmind sync with head
 1.53.2.3 31-May-2011  rmind sync with head
 1.53.2.2 05-Mar-2011  rmind sync with head
 1.53.2.1 30-May-2010  rmind sync with head
 1.57.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.58.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.59.12.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.12.2 23-Jun-2013  tls resync from head
 1.59.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.59.8.8 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.59.8.7 07-Dec-2014  martin Pull up the following, requested by msaitoh in #1207:

sys/dev/mii/brgphy.c 1.69, 1.71-1.76 via patch
sys/dev/mii/brgphyreg.h 1.6-1.7, 1.9
sys/dev/pci/if_bge.c 1.259,1.267-1.276 via patch
sys/dev/pci/if_bgereg.h 1.87-1.88
sys/dev/pci/if_bnx.c 1.48, 1.49, 1.52-1.57 via patch
sys/dev/pci/if_bnxreg.h 1.15-1.18
sys/dev/pci/if_bnxvar.h 1.4-1.6

Changes for bge(4), bnx(4) and brgphy(4):
- Add device IDs for Broadcom BCM57710, BCM57711(E), BCM57712(E) and
BCM5719 into pcidevs.
- Change BCM5720's device ID from 0x1658 to 0x165f. 0x1658 is only for
the pre-product and not released to public.
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Fix typo in comment.
- KNF
- brgphy(4):
- Add BCM5708S support.
- Add 2500SX support.
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
- Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
- Fix media detect on some Fiber chips.
- Add BCM5706.
- bge(4):
- Print yet another hardware config word in SRAM(BGE_SRAM_DATA_CFG_5)
for BCM5717 and newer devices.
- Fix a trivial bug in #ifdef NOTYET.
- Add BGEPHYF_NO_WIRESPEED flag for fiber devices.
- Print APE firmware correctly.
- Don't use the PHY Auto Poll Mode on many chips. This fixes a bug
that MII Fiber NIC drop packets about 50%. Same as {Free,Open}BSD.
Tested on HP Moonshot.
- Add workaround for PR#48451. Some BCM5717-5720 based systems get
NMI on boot. This problem doesn't occur when we don't use
prefetchable memory in the APE area. I don't know the reason...
Tested with HP MicroServer Gen8.
- Fix a bug that bge can't be initialized correctly on some sparc64
systems (PR#49018).
- Change initializaton order as the same as the document, Linux tg3
and FreeBSD (part of r241436).
- In the BCM5703, the DMA read watermark should be set to less than
or equal to the maximum memory read byte count of the PCI-X command
register. Same as FreeBSD r204978 and Linux tg3 driver.
- bnx(4):
- Enclose #ifdef BNX_DEBUG correctly.
- Add 2500SX support.
- Print some information (ASCI revision, PCI status, etc).
From FreeBSD.
 1.59.8.6 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.59.8.5 04-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1146):
sys/dev/mii/mii_physubr.c: revision 1.79
sys/dev/mii/rgephy.c: revision 1.33
sys/dev/mii/brgphy.c: revision 1.66
sys/dev/mii/atphy.c: revision 1.15
sys/dev/mii/mii.h: revision 1.17
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.59.8.4 18-Nov-2013  msaitoh Fix commpile error. This diff was in ticket #983.
 1.59.8.3 17-Nov-2013  bouyer Apply patch, requested by msaitoh in ticket #983:
sys/dev/mii/brgphy.c 1.68 via patch
sys/dev/pci/if_bge.c 1.260-1.262 via patch
sys/dev/pci/if_bgereg.h 1.85-1.86 via patch
sys/dev/pci/if_bgevar.h 1.17 via patch

Set maximum read byte count to 2048 for PCI-X BCM5703/5704 devices.
For PCI-X BCM5704, set maximum outstanding split transactions to 0.
Same as Linux tg3 and FreeBSD (part of FreeBSD r204978).
Add 40bit DMA bug workaround(BGEF_40BIT_BUG) from FreeBSD
(part of r199670). This workaround is for 5714/5715 controllers and
is not actually a MAC controller bug but an issue with the embedded
PCIe to PCI-X bridge in the device. This change
uses bus_dmatag_subregion(), so this workaround won't work on some
archs which doesn't support bus_dmatag_subregion().
 1.59.8.2 07-Sep-2013  bouyer sys/dev/pci/if_bge.c 1.203-1.237, 1.239-1.241, 1.243-1.258 via patch
sys/dev/pci/if_bgereg.h 1.58-1.74, 1.76-1.83 via patch
sys/dev/pci/if_bgevar.h 1.10-1.16 via patch
sys/dev/pci/pcidevs 1.1149 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/brgphy.c 1.61-1.63, 1.65, 1.67 via patch
sys/dev/mii/miivar.h 1.61 via patch
sys/dev/mii/miidevs 1.112-1.113 via patch
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/bge.4 1.13-1.15 via patch

Add some device support, fix a lot of bugs and add some enahcements.
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F,
BCM5785G, BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- brgphy(4): Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
- Add some bugfixes and enhancement from FreeBSD:
- Workaround for BCM5906 silicon bug. When auto-negotiation results in
half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292)
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785.
(FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf.
(FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC.
(FreeBSD r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems
we have seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
From Linux tg3 driver.
- Sync with *BSD. No functional change:
- make bge_chipid() and use it.
- use switch() instead of a lot of if()s.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case.
Note that {tcp,udp}6csum flag is currently not added in the
capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking. FreeBSD has the same delay().
- Rename PHY related flags for the consistency. It's the same as
FreeBSD.
- Remove BGE_10_100_ONLY flag because this was not used.
For 10/100 devices, when calling mii_attach(), mask BMSR_EXTSTAT
flag to not to check Gigabit flags. It's the same as FreeBSD.
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this commit,
only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK calls MI
mii_phy_auto(). That was not intended.
- Sync with FreeBSD and OpenBSD. Almost the same as OpenBSD rev. 1.325:
- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that
do not have jumbo support
- Wait for the bootcode to complete initialization for 5717 and newer
devices. See BCM5718 programmer's guide's "step 13,
Device reset Procedure, Section7".
57781's document has the same note.
- 5718 and 57785 document say we should wait 100us.
- Change the order of register settings a little to match both
Broadcom's document and Linux tg3.
- Add detach function.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix a bug that the NVRAM lock timeout occured on sparc64 onboard bge.
- Check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd
(OpenBSD rev. 1.327).
- Fix the setting of Tx Random Backoff Register.
- Add BGE_PCIMISCCTL_PCISTATE_RW in BGE_INIT. It's required to set the
PCISTATE register correctly.
- Update comments from 57XX-PG105-R.pdf and 5718-PG106-R.pdf.
- Add missing bus_dmamap_sync() in bge_intr(). The status word is
in DMAed area. Same as other *BSDs.
- Check the hardware config words and print them. This change only
read them and print the values.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind().
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- bge_init_tx_ring() uses BGE_RSLOTS (==256) but bge_free_tx_ring() uses
BGE_TX_RING_CNT (== 512). Delete BGE_RSLOTS and use BGE_TX_RING_CNT.
Same as OpenBSD's if_bge.c rev. 1.86.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Call bge_poll_fw() before writing BGE_MODE_CTL register like the
latest linux tg3 dirver.
- Set DMA watermark depend on the PCI max payload size.
- Add BGE_JUMBO_CAPABLE flag to some chips. With this commit, 5714,
5780, 5717, 5718, 5719 (exclude rev. A0), 5720, 57765 and 57766 are
added to support jumbo frame.
- Fix the setting of sc->bge_flags for 5717 and newer devices.
- Fix a link detect bug on non-autopoll systems. Same as OpenBSD
(rev.1.329 and 1.336) and FreeBSD (r213710).
- 57765 series is not based on 5717 series. 5717 series is based on
57765 series.
- Set the TX DMA segment size based on the MTU size.
- Change the TX ring size for 5717 series and 57764 series.
- For 57766, set BGE_RDMAMODE_JMB_2K_MMRR for non-jumbo frame.
Same as Linux tg3.
- For 57765 and newer devices, set BGE_MAX_RX_FRAME_LOWAT to 1.
This value is recommended by the document.
- Change sysctl related functions for consistency.
- Style change.
- Use macro. Remove duplicated macro. Remove unused variable.
- Fix comments. Add comments.
- Remove extra semicolon. Remove unused code.
[msaitoh, ticket #939]
 1.59.8.1 26-Aug-2013  msaitoh Pull up following revision(s) (requested by tsutsui in ticket #652):
sys/dev/mii/brgphy.c 1.60
sys/dev/pci/if_bge.c 1.202
sys/dev/pci/if_bgereg.h 1.57
Add support for BCM57762 and BCM57765, found in Apple's Thunderbolt
to Gigabit Ethernet adapter. PR kern/46961.
 1.59.2.2 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.59.2.1 30-Oct-2012  yamt sync with head
 1.67.2.1 18-May-2014  rmind sync with head
 1.68.2.1 10-Aug-2014  tls Rebase.
 1.76.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.76.28.1 10-Jun-2019  christos Sync with HEAD
 1.76.26.2 26-Jan-2019  pgoyette Sync with HEAD
 1.76.26.1 18-Jan-2019  pgoyette Synch with HEAD
 1.76.20.3 14-Apr-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1529:

sys/dev/mii/miidevs 1.154, 1.162-1.167
sys/dev/mii/atphy.c 1.28 via patch
sys/dev/mii/brgphy.c 1.87 via patch
sys/dev/mii/etphy.c 1.5, 1.6 via patch
sys/dev/mii/rdcphy.c 1.6, 1.8 via patch

- Add support Broadcom BCM54213PE and some new RDC devices.
- Rename RDC to xxRDC.
- Use xxVIA instead of VIA.
- etphy(4):
- Rename ET1011 to ET1011C and add ET1011 support.
- Use mii_phy_flowstatus() to reflect flow status from negotiated
result.
- Use static.
- KNF.
 1.76.20.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.76.20.1 07-Mar-2019  martin Pull up r1.80, requested by msaitoh in ticket #1209
 1.84.4.1 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #831):

sys/dev/mii/rdcphy.c: revision 1.6
sys/dev/mii/rdcphy.c: revision 1.8
sys/dev/mii/miidevs: revision 1.162
sys/dev/mii/miidevs: revision 1.163
sys/dev/mii/miidevs: revision 1.164
sys/dev/mii/miidevs: revision 1.165
sys/dev/mii/miidevs: revision 1.167
sys/dev/mii/brgphy.c: revision 1.87

Change the OUI macro name of RDC to xxRDC. 0x00d02d is non-bitreverse value
of official 0x000bb4. From Andrius V.
RDC -> xxRDC. No functional change.

Add BCM54213PE

Match BCM54213PE

Use xxVIA instead of VIA.
0x004063 is VIA's official OUI but VT6103 use 0x0002c6.
0x0002c6 is non-bitreversed value of 0x004063. Reported by Andrius V.

- Add Quake Technologies and Aeluros' OUI
- Add Teranetics TN1010 10GBase-T PHY
Add two new RDC PHYs from Andrius V.
Add two new RDC PHYs from Andrius V.
 1.86.2.1 29-Feb-2020  ad Sync with head.
 1.90.20.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.13 06-May-2023  andvar s/Regiser/Register/ and s/regester/register/ in comments.
 1.12 25-May-2020  jmcneill Add support for BCM54213PE RGMII clock delays, from OpenBSD
 1.11 11-Apr-2019  msaitoh KNF. No functional change.
 1.10 16-Jan-2019  msaitoh Remove the definition of BRGPHY_MII_1000CTL and use MII_GTCR.
 1.9 17-Jun-2014  msaitoh branches: 1.9.26; 1.9.28;
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Add BCM5708S support in brgphy(4). The auto negotiation may have some bugs.
- Add 2500SX support (not tested).
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
 1.8 16-Jun-2014  msaitoh No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.7 12-Jun-2014  msaitoh No functional change:
- Remove BRGPHY_SERDES_ANAR_* and BRGPHY_SERDES_ANLPAR_*. Those registers
are the same as MII_ANAR_* and MII_ANLPAR_*.
- Fix typo.
- Remove trailing white spaces.
- KNF.
 1.6 01-Apr-2013  msaitoh branches: 1.6.8;
Sort. No functional change.
 1.5 09-Dec-2010  jym branches: 1.5.8; 1.5.14; 1.5.18;
Add support for BCM5709S (SerDes PHY) in brgphy(4).

From FreeBSD, via OpenBSD, with some minor adaptations.

No comments, no objections on tech-kern@.

The driver was tested on a Dell M710. Access was kindly provided by
Uwe Toenjes, whom I thank for this.

See also http://mail-index.netbsd.org/tech-kern/2010/12/01/msg009478.html
 1.4 19-Apr-2009  msaitoh branches: 1.4.4;
Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.3 25-Aug-2008  cegger branches: 1.3.2; 1.3.4; 1.3.8; 1.3.12;
PR 39241: Add support for Broadcom BCM5906(M) from Karl Uwe Lockhoff
 1.2 22-Jun-2002  fvdl branches: 1.2.58; 1.2.104; 1.2.108; 1.2.110; 1.2.114;
Add more register definitions. From FreeBSD.
 1.1 01-Jun-2001  thorpej branches: 1.1.2; 1.1.4; 1.1.16; 1.1.18;
Driver for Broadcom BCM5400-family Gig-E PHYs. Programming
information gleaned from FreeBSD.
 1.1.18.1 28-Jan-2003  jmc Pullup revisions 1.1-1.2 (requested by fvdl in ticket #1126)
Pullup support for bge device. (Broadcom Gigabit Ethernet)
 1.1.16.1 15-Jul-2002  gehenna catch up with -current.
 1.1.4.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 01-Jun-2001  nathanw file brgphyreg.h was added on branch nathanw_sa on 2001-06-21 20:04:17 +0000
 1.2.114.1 19-Oct-2008  haad Sync with HEAD.
 1.2.110.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.108.1 04-May-2009  yamt sync with head.
 1.2.104.1 28-Sep-2008  mjf Sync with HEAD.
 1.2.58.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1342):
sys/dev/pci/if_bge.c: revisions 1.135, 1.146, 1.151-1.152,
1.155-1.167 via patch
sys/dev/pci/if_bgereg.h: revisions 1.43, 1.48-1.52
sys/dev/pci/if_bgevar.h: revision 1.1
sys/dev/mii/brgphy.c: revisions 1.36, 1.40, 1.43-1.44 and
1.47-1.48 via patch
sys/dev/mii/brgphyreg.h: revisions 1.3-1.4
sys/dev/mii/miidevs: revisions 1.75, 1.77, 1.85
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs_data.h: regen
sys/dev/mii/miivar.h: revision 1.54
For bge:
- Really set Tx threshold.
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the "link changed" bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
- Add BCM5786 support.
for brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2, BCM5708C, BCM5722, and BCM5906.
 1.3.12.1 21-Apr-2010  matt sync to netbsd-5
 1.3.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.4.2 09-Nov-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1983):
sys/dev/pci/pcidevs: revisions 1.1079, 1.1134, 1.1148-1.1149, 1.1151
sys/dev/pci/pcidevs.h: regen
sys/dev/pci/pcidevs_data.h: regen
sys/dev/pci/if_bge.c: revisions 1.183-1.185, 1.187, 1.189-1.193, 1.195-1.199, 1.202-1.226, 1.228-1.237, 1.240-1.264, 1.267-1.276, 1.278-1.280, 1.283-1.287 via patch
sys/dev/pci/if_bgereg.h: revisions 1.57-1.74, 1.76-1.90 via patch
sys/dev/pci/if_bgevar.h: revisions 1.6, 1.10-1.13, 1.15-1.17 via patch
sys/dev/pci/if_bnx.c: revisions 1.32, 1.34-1.43, 1.48-1.49, 1.52
sys/dev/pci/if_bnxreg.h: revisions 1.8, 1.11-1.14
sys/dev/pci/if_bnxvar.h: revisions 1.1-1.3
sys/dev/mii/brgphy.c: revisions 1.53-1.63, 1.65-69, 1.72-1.74 via patch
sys/dev/mii/brgphyreg.h: revisions 1.5-1.8
sys/dev/mii/miivar.h: revisions 1.61
sys/dev/pci/pcireg.h: patch

Sync bge(4) up to if_bge.c rev. 1.287. Sync brgphy(4) up to 1.74.
Fix some bugs on bnx(4).

Common:
- Add device IDs for Broadcom BCM57710, BCM57711(E), BCM57712(E) and
BCM57766 (pcidevs only).
- Fix BCM5709 PHY detection.
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Add BCM5708S support in brgphy(4).
- Don't use the WIRESPEED function for fiber devices.
bge(4):
- Add some Fujitsu's device support from Michael Moll.
- Add BCM57762 support (PR#46961 from Ryo Onodera).
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F. BCM5785G,
BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- Fix DMA setting for read/write on conventional PCI bus devices.
This bug was added in rev. 1.166.
- Fix printing "discarding oversize frame (len=-4)" message and
crash by NULL pointer dereferencing.
- The BCM5785 is a PCIe chip but does not report PCIe capabilities.
Check for this chip explicitely and enable PCIe. Fixes
'firmware handshake timeout'.
- Allow disabling interrupt mitigation.
- Workaround for BCM5906 silicon bug. When auto-negotiation results
in half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292).
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785. (FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf. (FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC. (FreeBSD
r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems we have
seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case. Note that
{tcp,udp}6csum flag is currently not added in the capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking.
- Do not touch the jumbo replenish threshold register on chips that do
not have jumbo support.
- Wait for the bootcode to complete initialization for 5717 and newer
devices.
- 5718 and 57785 document say we should wait 100us in init.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix the setting of Tx Random Backoff Register.
- Check the hardware config words and print them.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind(). Fixes PR#47716.
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Set DMA watermark depend on the PCI max payload size.
- Set BGE_JUMBO_CAPABLE correctly.
- Fix a link detect bug on non-autopoll systems.
- Change the TX ring size for 5717 series and 57764 series.
- Set maximum read byte count to 2048 for PCI-X BCM5703/5704 devices.
- For PCI-X BCM5704, set maximum outstanding split transactions to 0.
- Add 40bit DMA bug workaround(BGEF_40BIT_BUG) from FreeBSD.
This workaround is for 5714/5715 controllers and is not actually a
MAC controller bug but an issue with the embedded PCIe to PCI-X
bridge in the device. This change uses bus_dmatag_subregion(),
so this workaround won't work on some archs which doesn't support
bus_dmatag_subregion().
- Add 2500SX support (not tested).
- Don't use the PHY Auto Poll Mode on many chips. This fixes a bug
that MII Fiber NIC drop packet about 50%. Tested on HP Moonshot.
- Add workaround for PR#48451. Some BCM5717-5720 based systems getNMI
on boot. This problem doesn't occur when we don't use prefetchable
memory in the APE area. Tested with HP MicroServer Gen8.
- In the BCM5703, the DMA read watermark should be set to less than
or equal to the maximum memory read byte count of the PCI-X command
register.
- Fix a bug that BGE_PHY_TEST_CTRL_REG isn't set correctly on some
PCIe devices.
- Use another firmware command in bge_asf_driver_up(). Same as Linux.
This change fixes a bug that watchdog timeout occurs every 25-30
minutes on HP ML110 G6 reported enami@ in PR#49657.
- Fix mbuf leak on failure.
- Remove PCI_PRODUCT_BROADCOM_BCM5724 and
PCI_PRODUCT_BROADCOM_BCM5750M. These devices have not released to
public.
- Add some workaround code for BGE_ASICREV_BCM5784 from Linux.
- Change some printf() to aprint_*().
- Fix typo in comments.
- Cleanup.
brgphy(4):
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
- Add BCM5481, BCM5709S, BCM5756, BCM5717C, BCM5720C, BCM5785,
BCM57765(PR#46961), BCM57780
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this
commit, only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK
calls MI mii_phy_auto(). That was not intended.
- Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
bnx(4):
- Add missing ifmedia_delete_instance() in bnx_detach().
- Fix a bug that BNX_NO_WOL_FLAG isn't correctly set on some chips.
Reported by From Henning Petersen in PR#44151.
- Fix SERDES initialization.
- Get out of the interrupt handler early if !IFF_RUNNING.
 1.3.4.1 04-Aug-2009  snj Apply patch (requested by msaitoh in ticket #866):
For bge:
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the 'link changed' bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
For brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2 and BCM5722.
 1.3.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.4.4.1 05-Mar-2011  rmind sync with head
 1.5.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.18.1 23-Jun-2013  tls resync from head
 1.5.14.2 07-Dec-2014  martin Pull up the following, requested by msaitoh in #1207:

sys/dev/mii/brgphy.c 1.69, 1.71-1.76 via patch
sys/dev/mii/brgphyreg.h 1.6-1.7, 1.9
sys/dev/pci/if_bge.c 1.259,1.267-1.276 via patch
sys/dev/pci/if_bgereg.h 1.87-1.88
sys/dev/pci/if_bnx.c 1.48, 1.49, 1.52-1.57 via patch
sys/dev/pci/if_bnxreg.h 1.15-1.18
sys/dev/pci/if_bnxvar.h 1.4-1.6

Changes for bge(4), bnx(4) and brgphy(4):
- Add device IDs for Broadcom BCM57710, BCM57711(E), BCM57712(E) and
BCM5719 into pcidevs.
- Change BCM5720's device ID from 0x1658 to 0x165f. 0x1658 is only for
the pre-product and not released to public.
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Fix typo in comment.
- KNF
- brgphy(4):
- Add BCM5708S support.
- Add 2500SX support.
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
- Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
- Fix media detect on some Fiber chips.
- Add BCM5706.
- bge(4):
- Print yet another hardware config word in SRAM(BGE_SRAM_DATA_CFG_5)
for BCM5717 and newer devices.
- Fix a trivial bug in #ifdef NOTYET.
- Add BGEPHYF_NO_WIRESPEED flag for fiber devices.
- Print APE firmware correctly.
- Don't use the PHY Auto Poll Mode on many chips. This fixes a bug
that MII Fiber NIC drop packets about 50%. Same as {Free,Open}BSD.
Tested on HP Moonshot.
- Add workaround for PR#48451. Some BCM5717-5720 based systems get
NMI on boot. This problem doesn't occur when we don't use
prefetchable memory in the APE area. I don't know the reason...
Tested with HP MicroServer Gen8.
- Fix a bug that bge can't be initialized correctly on some sparc64
systems (PR#49018).
- Change initializaton order as the same as the document, Linux tg3
and FreeBSD (part of r241436).
- In the BCM5703, the DMA read watermark should be set to less than
or equal to the maximum memory read byte count of the PCI-X command
register. Same as FreeBSD r204978 and Linux tg3 driver.
- bnx(4):
- Enclose #ifdef BNX_DEBUG correctly.
- Add 2500SX support.
- Print some information (ASCI revision, PCI status, etc).
From FreeBSD.
 1.5.14.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.5.8.1 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.6.8.1 10-Aug-2014  tls Rebase.
 1.9.28.1 10-Jun-2019  christos Sync with HEAD
 1.9.26.1 18-Jan-2019  pgoyette Synch with HEAD
 1.42 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.41 24-Aug-2020  msaitoh branches: 1.41.20;
Don't do full initialization for autonego when just restarting autonego
because it's not required.

This change reduce extra initialization which include PHY_RESET() which
caused long delay(max 500ms).
 1.40 07-Jul-2020  msaitoh - Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.39 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.38 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.37 17-Oct-2019  msaitoh - Match a lot of Cicada and Vitesse devices correctly. This change also fixes
a bug that ciphy_fixup() didn't work.
- Match VSC8221, VSC8234 and VSC8641.
 1.36 11-Oct-2019  msaitoh Call mii_phy_flowstatus() to show the flow setting.
 1.35 11-Oct-2019  msaitoh - Indicat master mode if the negotiated result say so.
- KNF
 1.34 11-Apr-2019  msaitoh branches: 1.34.4;
KNF. No functional change.
 1.33 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. Same as a part of
FreeBSD r217413.
 1.32 25-Mar-2019  msaitoh KNF. No functional change.
 1.31 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.30 13-Feb-2019  msaitoh Add CS8204, CS8244 VSC8211 and VSC8601 support from {Free,Open}BSD.
 1.29 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.28 16-Jan-2019  msaitoh CIPHY_MII_BMCR -> MII_BMCR in #ifdef foo.
 1.27 16-Jan-2019  msaitoh The register bit definitions from register 0 to 15 in ciphyreg.h conform to
the 802.3 spec, so remove them and use mii.h's definition.
No functional change.
 1.26 07-Jul-2016  msaitoh branches: 1.26.10; 1.26.16; 1.26.18;
KNF. Remove extra spaces. No functional change.
 1.25 16-Jun-2014  msaitoh branches: 1.25.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.24 11-Jun-2013  msaitoh branches: 1.24.6;
Update link status quickly. This change is a part of mii_physubr.c rev.
1.77-1.78.
 1.23 09-Jun-2013  msaitoh Update link status quickly. This change is a part of FreeBSD's mii_physubr.c
r158649.
 1.22 09-Jun-2013  msaitoh ciphy is gigabit PHY, so use MII_ANEGTICKS_GIGE instead of MII_ANEGTICKS.
 1.21 09-Jun-2013  msaitoh atphy, ciphy, ihphy and rgephy are gigabit PHY, so not only check IFM_AUTO
for autonegotiation but also check IFM_1000_T, too.
 1.20 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.19 12-May-2009  cegger branches: 1.19.12; 1.19.18; 1.19.22;
struct device * -> device_t, no functional changes intended.
 1.18 12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.17 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.16 17-Nov-2008  dyoung branches: 1.16.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.15 04-May-2008  xtraeme branches: 1.15.6; 1.15.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.14 08-Apr-2008  cegger branches: 1.14.2; 1.14.4;
use aprint_*_dev and device_xname
 1.13 09-Dec-2007  jmcneill branches: 1.13.10;
Merge jmcneill-pm branch.
 1.12 19-Oct-2007  ad branches: 1.12.4; 1.12.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.11 26-Nov-2006  tsutsui branches: 1.11.8; 1.11.22; 1.11.24; 1.11.28;
Include <sys/device.h> for struct device.
 1.10 16-Nov-2006  christos - don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.9 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.8 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.7 14-May-2006  elad branches: 1.7.8; 1.7.10;
integrate kauth.
 1.6 29-Mar-2006  thorpej Use device_private().
 1.5 12-Mar-2006  chs branches: 1.5.2;
from OpenBSD:
We need to special case ciphy to ask for RGMII interface at 2.5V for nfe.
This makes Cicada/Vitesse PHYs attached to nfe work.
Many thanks to Bill Paul for diagnosing the problem and suggesting a solution.
 1.4 01-Dec-2005  riz branches: 1.4.4; 1.4.6; 1.4.8; 1.4.10;
Match all model numbers with both Cicada OUIs; this allows the proper PHY to
attach on my ZyXEL GN650-T.
 1.3 16-Mar-2005  briggs branches: 1.3.2; 1.3.4; 1.3.6; 1.3.8;
Changes to match xxCICADA 8201B found in a VT6122.
Match at > 1 (10) to ensure we get ciphy instead of ukphy.
Use aprint(9) on attach.
Minor stylistic changes.
All from Tomokazu HARADA in PR kern/29705.
 1.2 27-Feb-2005  perry branches: 1.2.2;
nuke trailing whitespace
 1.1 20-Feb-2005  jdolecek Add driver for 10/100/1000 copper PHY integrated on VIA Networking Technologies
VT6122 gigabit ethernet chips

From FreeBSD
 1.2.2.4 11-Dec-2005  christos Sync with head.
 1.2.2.3 01-Apr-2005  skrll Sync with HEAD.
 1.2.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.1 27-Feb-2005  skrll file ciphy.c was added on branch ktrace-lwp on 2005-03-04 16:44:57 +0000
 1.3.8.4 21-Jan-2008  yamt sync with head
 1.3.8.3 27-Oct-2007  yamt sync with head.
 1.3.8.2 30-Dec-2006  yamt sync with head.
 1.3.8.1 21-Jun-2006  yamt sync with head.
 1.3.6.2 29-Apr-2005  kent sync with -current
 1.3.6.1 16-Mar-2005  kent file ciphy.c was added on branch kent-audio2 on 2005-04-29 11:29:04 +0000
 1.3.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.4.1 16-Mar-2005  yamt file ciphy.c was added on branch yamt-km on 2005-03-19 08:34:59 +0000
 1.3.2.1 20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/dev/mii/ciphyreg.h: revision 1.4 via patch
sys/dev/mii/ciphy.c: revision 1.5 via patch
from OpenBSD:
We need to special case ciphy to ask for RGMII interface at 2.5V for nfe.
This makes Cicada/Vitesse PHYs attached to nfe work.
Many thanks to Bill Paul for diagnosing the problem and suggesting a solution.
 1.4.10.1 19-Apr-2006  elad sync with head.
 1.4.8.2 01-Apr-2006  yamt sync with head.
 1.4.8.1 13-Mar-2006  yamt sync with head.
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.7.10.2 10-Dec-2006  yamt sync with head.
 1.7.10.1 22-Oct-2006  yamt sync with head
 1.7.8.2 12-Jan-2007  ad Sync with head.
 1.7.8.1 18-Nov-2006  ad Sync with head.
 1.11.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.11.24.2 09-Jan-2008  matt sync with HEAD
 1.11.24.1 06-Nov-2007  matt sync with HEAD
 1.11.22.3 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.11.22.2 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.11.22.1 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.11.8.1 23-Oct-2007  ad Sync with head.
 1.12.6.1 11-Dec-2007  yamt sync with head.
 1.12.4.1 26-Dec-2007  ad Sync with head.
 1.13.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.13.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.4.3 16-May-2009  yamt sync with head
 1.14.4.2 04-May-2009  yamt sync with head.
 1.14.4.1 16-May-2008  yamt sync with head.
 1.14.2.1 18-May-2008  yamt sync with head.
 1.15.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.15.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.15.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.16.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.22.3 03-Dec-2017  jdolecek update from HEAD
 1.19.22.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.22.1 23-Jun-2013  tls resync from head
 1.19.18.2 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.19.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.19.12.1 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.24.6.1 10-Aug-2014  tls Rebase.
 1.25.4.1 09-Jul-2016  skrll Sync with HEAD
 1.26.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.26.18.1 10-Jun-2019  christos Sync with HEAD
 1.26.16.2 26-Jan-2019  pgoyette Sync with HEAD
 1.26.16.1 18-Jan-2019  pgoyette Synch with HEAD
 1.26.10.3 24-Oct-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1414:

sys/dev/mii/ciphy.c 1.34-1.37 via patch
sys/dev/mii/miidevs 1.158

- Indicate master mode if the negotiated result say so.
- Call mii_phy_flowstatus() to show the flow setting.
- Match a lot of Cicada and Vitesse devices correctly.
- Add support for VSC8221, VSC8234 and VSC8641.
- KNF
 1.26.10.2 01-Sep-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1350:

sys/dev/mii/ciphy.c 1.27-1.28, 1.30, 1.32
via patch
sys/dev/mii/ciphyreg.h 1.6

- The register bit definitions from register 0 to 15 in ciphyreg.h
conform to the 802.3 spec, so remove them and use mii.h's definition.
No functional change.
- Add CS8204, CS8244 VSC8211 and VSC8601 support from {Free,Open}BSD.
- KNF.
 1.26.10.1 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.34.4.3 24-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #378):

sys/dev/mii/ciphy.c: revision 1.36

Call mii_phy_flowstatus() to show the flow setting.
 1.34.4.2 23-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #372):

sys/dev/mii/miidevs: revision 1.158
sys/dev/mii/ciphy.c: revision 1.37

- All of Cicada and Vitesse devices' OUI are not bit-reversed, so use "xx".
- Rename CS82xx -> CIS82xx
- Add Vitesse VSC8224, VSC8234, VSC8641 and VSC8501.
- Match a lot of Cicada and Vitesse devices correctly. This change also fixes
a bug that ciphy_fixup() didn't work.
- Match VSC8221, VSC8234 and VSC8641.
 1.34.4.1 17-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #347):

sys/dev/mii/ciphy.c: revision 1.35
sys/dev/mii/rgephy.c: revision 1.56
sys/dev/mii/rgephy.c: revision 1.57

Make new rgephy_linkup() function and share it like FreeBSD.
No functional change intended.

- Indicate master mode if the negotiated result say so.
- KNF
 1.41.20.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.7 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.6 16-Jan-2019  msaitoh The register bit definitions from register 0 to 15 in ciphyreg.h conform to
the 802.3 spec, so remove them and use mii.h's definition.
No functional change.
 1.5 16-Jun-2014  msaitoh branches: 1.5.20; 1.5.26; 1.5.28;
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.4 12-Mar-2006  chs branches: 1.4.106; 1.4.110; 1.4.126;
from OpenBSD:
We need to special case ciphy to ask for RGMII interface at 2.5V for nfe.
This makes Cicada/Vitesse PHYs attached to nfe work.
Many thanks to Bill Paul for diagnosing the problem and suggesting a solution.
 1.3 11-Dec-2005  christos branches: 1.3.4; 1.3.6; 1.3.8; 1.3.10;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8; 1.2.10;
nuke trailing whitespace
 1.1 20-Feb-2005  jdolecek Add driver for 10/100/1000 copper PHY integrated on VIA Networking Technologies
VT6122 gigabit ethernet chips

From FreeBSD
 1.2.10.1 21-Jun-2006  yamt sync with head.
 1.2.8.2 29-Apr-2005  kent sync with -current
 1.2.8.1 27-Feb-2005  kent file ciphyreg.h was added on branch kent-audio2 on 2005-04-29 11:29:04 +0000
 1.2.6.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.6.1 27-Feb-2005  yamt file ciphyreg.h was added on branch yamt-km on 2005-03-19 08:34:59 +0000
 1.2.4.1 20-Apr-2006  snj Pull up following revision(s) (requested by tron in ticket #1266):
sys/dev/mii/ciphyreg.h: revision 1.4 via patch
sys/dev/mii/ciphy.c: revision 1.5 via patch
from OpenBSD:
We need to special case ciphy to ask for RGMII interface at 2.5V for nfe.
This makes Cicada/Vitesse PHYs attached to nfe work.
Many thanks to Bill Paul for diagnosing the problem and suggesting a solution.
 1.2.2.2 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.2.2.1 27-Feb-2005  skrll file ciphyreg.h was added on branch ktrace-lwp on 2005-03-04 16:44:57 +0000
 1.3.10.1 19-Apr-2006  elad sync with head.
 1.3.8.1 13-Mar-2006  yamt sync with head.
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.4.126.1 10-Aug-2014  tls Rebase.
 1.4.110.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.106.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.5.28.1 10-Jun-2019  christos Sync with HEAD
 1.5.26.1 18-Jan-2019  pgoyette Synch with HEAD
 1.5.20.1 01-Sep-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1350:

sys/dev/mii/ciphy.c 1.27-1.28, 1.30, 1.32
via patch
sys/dev/mii/ciphyreg.h 1.6

- The register bit definitions from register 0 to 15 in ciphyreg.h
conform to the 802.3 spec, so remove them and use mii.h's definition.
No functional change.
- Add CS8204, CS8244 VSC8211 and VSC8601 support from {Free,Open}BSD.
- KNF.
 1.12 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.11 04-Aug-2020  uwe branches: 1.11.6;
mii_knowndevs[] is de facto const, define it as such.

This time for real. On my first try I did it in the generated
miidevs_data.h file.
 1.10 02-Dec-2019  uwe Fix s/product/model/ search-and-destroy accident that affected license.

Back in 1998 thorpej@ adapted this from one of the several versions we
have in the tree but needed s/product/model/ in the text of the
script. Unfortunately that also affected the license text: "This
model includes software..." and "...or promote models".
 1.9 25-Mar-2019  msaitoh branches: 1.9.4;
Fix compile error when MIIVERBOSE is set. Reported by Kurt Schreiner.
 1.8 03-Jun-2017  christos branches: 1.8.10;
remove my copyright.
 1.7 02-May-2008  martin branches: 1.7.44; 1.7.64;
Move TNF licenses to 2 clause form
 1.6 11-Dec-2005  christos branches: 1.6.70; 1.6.72; 1.6.74;
merge ktrace-lwp.
 1.5 27-Feb-2005  perry Don't leave blanks at the end of the "generated from:"
Also, don't print a space after "},"s at the end of line in one of the
files.
 1.4 15-Dec-2003  jmc branches: 1.4.8; 1.4.10;
Fixes from PR#23177. Various lint/logic fixes:
Fix some non-initialized variables
close the output files when done
Redo the printing for RCS strings so they don't expand in the awk script too
Do proper tests for variables existance before accessing

Verified output from all scripts is identical to original versions
 1.3 08-May-2000  augustss branches: 1.3.28;
Allow a verbose description to be printed with the option MIIVERBOSE.
 1.2 05-Sep-1998  christos branches: 1.2.12;
Assign copyright to TNF.
 1.1 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.2.12.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.3.28.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.28.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.28.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.28.1 03-Aug-2004  skrll Sync with HEAD
 1.4.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.8.1 29-Apr-2005  kent sync with -current
 1.6.74.1 16-May-2008  yamt sync with head.
 1.6.72.1 18-May-2008  yamt sync with head.
 1.6.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.64.1 28-Aug-2017  skrll Sync with HEAD
 1.7.44.1 03-Dec-2017  jdolecek update from HEAD
 1.8.10.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.8.10.1 10-Jun-2019  christos Sync with HEAD
 1.9.4.1 09-Dec-2019  martin Pull up following revision(s) (requested by uwe in ticket #521):

sys/dev/mii/devlist2h.awk: revision 1.10

Fix s/product/model/ search-and-destroy accident that affected license.

Back in 1998 thorpej@ adapted this from one of the several versions we
have in the tree but needed s/product/model/ in the text of the
script. Unfortunately that also affected the license text: "This
model includes software..." and "...or promote models".
 1.11.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.47 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.46 14-Feb-2020  nisimura unbreak the previous commit error
 1.45 14-Feb-2020  nisimura determine FDX flow control abilities
 1.44 27-Nov-2019  msaitoh branches: 1.44.2;
- Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.43 25-Mar-2019  msaitoh KNF. No functional change.
 1.42 25-Mar-2019  msaitoh KNF. No functional change.
 1.41 18-Mar-2019  msaitoh Add Davicom DM9161,DM9161A,DM9161B and DM9601 support.
 1.40 25-Feb-2019  msaitoh Fix previos to not to duplicate DM9101 entry. One is DAVICOM and another
is xxDAVICOM.
 1.39 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.38 18-Feb-2019  msaitoh Fix typo in comment.
 1.37 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.36 07-Jul-2016  msaitoh branches: 1.36.16; 1.36.18;
KNF. Remove extra spaces. No functional change.
 1.35 16-Jun-2014  msaitoh branches: 1.35.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.34 19-Oct-2009  bouyer branches: 1.34.18; 1.34.22; 1.34.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.33 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.32 04-May-2008  xtraeme branches: 1.32.6; 1.32.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.31 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.30 08-Apr-2008  cegger branches: 1.30.2; 1.30.4;
use aprint_*_dev and device_xname
 1.29 29-Dec-2007  dyoung branches: 1.29.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.28 09-Dec-2007  jmcneill branches: 1.28.2;
Merge jmcneill-pm branch.
 1.27 16-Nov-2006  christos branches: 1.27.22; 1.27.24; 1.27.30; 1.27.34; 1.27.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.26 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.25 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.24 29-Mar-2006  thorpej branches: 1.24.8; 1.24.10;
Use device_private().
 1.23 20-Feb-2006  thorpej branches: 1.23.2; 1.23.4; 1.23.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.22 11-Dec-2005  christos branches: 1.22.2; 1.22.4; 1.22.6;
merge ktrace-lwp.
 1.21 28-Aug-2005  kiyohara Add DAVICOM DM9102.
 1.20 27-Feb-2005  perry branches: 1.20.2; 1.20.4;
nuke trailing whitespace
 1.19 23-Aug-2004  thorpej branches: 1.19.4; 1.19.6;
Make use of static.
 1.18 29-Apr-2003  thorpej branches: 1.18.2;
Use aprint*().
 1.17 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.16 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.15 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.14 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.13 25-Mar-2002  thorpej branches: 1.13.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.12 13-Nov-2001  lukem add RCSID
 1.11 25-Aug-2001  thorpej ANSI'ify.
 1.10 02-Jun-2001  thorpej branches: 1.10.2;
Make PHY matching all table-driven.
 1.9 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.8 04-Jul-2000  thorpej branches: 1.8.2; 1.8.4;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.7 02-Apr-2000  tsutsui branches: 1.7.4;
Make to match also MII_OUI_DAVICOM.
(This seems to work, but any GENERIC does not have dmphy...)
 1.6 06-Mar-2000  thorpej Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.5 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.4 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.3 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.2 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.1 02-Feb-2000  thorpej Driver for the Davicom DM9101 10/100 Ethernet PHY. This PHY is found
on several inexpensive 10/100 Ethernet boards (e.g. D-Link DFE-530TX,
Winbond 10/100 boards), and is also the built-in PHY on the DM9102
10/100 Ethernet chip.
 1.7.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.8.4.6 18-Oct-2002  nathanw Catch up to -current.
 1.8.4.5 01-Aug-2002  nathanw Catch up to -current.
 1.8.4.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.8.4.3 14-Nov-2001  nathanw Catch up to -current.
 1.8.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.8.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.8.2.2 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.8.2.1 04-Jul-2000  bouyer file dmphy.c was added on branch thorpej_scsipi on 2000-11-20 11:42:09 +0000
 1.10.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.10.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.10.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.10.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.10.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.13.2.1 15-Jul-2002  gehenna catch up with -current.
 1.18.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.18.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.18.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.18.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.18.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.19.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.4.1 29-Apr-2005  kent sync with -current
 1.20.4.3 21-Jan-2008  yamt sync with head
 1.20.4.2 30-Dec-2006  yamt sync with head.
 1.20.4.1 21-Jun-2006  yamt sync with head.
 1.20.2.1 12-Sep-2005  tron Pull up following revision(s) (requested by kiyohara in ticket #760):
sys/dev/mii/dmphy.c: revision 1.21
sys/dev/mii/miidevs: revision 1.60
Add DAVICOM DM9102.
 1.22.6.1 22-Apr-2006  simonb Sync with head.
 1.22.4.1 09-Sep-2006  rpaulo sync with head
 1.22.2.1 01-Mar-2006  yamt sync with head.
 1.23.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.23.4.1 19-Apr-2006  elad sync with head.
 1.23.2.1 01-Apr-2006  yamt sync with head.
 1.24.10.2 10-Dec-2006  yamt sync with head.
 1.24.10.1 22-Oct-2006  yamt sync with head
 1.24.8.1 18-Nov-2006  ad Sync with head.
 1.27.36.1 11-Dec-2007  yamt sync with head.
 1.27.34.1 26-Dec-2007  ad Sync with head.
 1.27.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.27.24.1 09-Jan-2008  matt sync with HEAD
 1.27.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.27.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.28.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.29.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.29.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.30.4.3 11-Mar-2010  yamt sync with head
 1.30.4.2 04-May-2009  yamt sync with head.
 1.30.4.1 16-May-2008  yamt sync with head.
 1.30.2.1 18-May-2008  yamt sync with head.
 1.32.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.32.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.34.36.1 10-Aug-2014  tls Rebase.
 1.34.22.2 03-Dec-2017  jdolecek update from HEAD
 1.34.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.35.4.1 09-Jul-2016  skrll Sync with HEAD
 1.36.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.36.18.1 10-Jun-2019  christos Sync with HEAD
 1.36.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.44.2.1 29-Feb-2020  ad Sync with head.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 02-Feb-2000  thorpej branches: 1.1.6; 1.1.128; 1.1.130; 1.1.132;
Driver for the Davicom DM9101 10/100 Ethernet PHY. This PHY is found
on several inexpensive 10/100 Ethernet boards (e.g. D-Link DFE-530TX,
Winbond 10/100 boards), and is also the built-in PHY on the DM9102
10/100 Ethernet chip.
 1.1.132.1 16-May-2008  yamt sync with head.
 1.1.130.1 18-May-2008  yamt sync with head.
 1.1.128.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.2 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.6.1 02-Feb-2000  bouyer file dmphyreg.h was added on branch thorpej_scsipi on 2000-11-20 11:42:09 +0000
 1.3 28-Dec-2018  msaitoh - Backout some changes done in rev. 1.44. OK'd by jdolecek@:
- Remove e1000phyreg.h and use makphyreg.h again.
- Remove Energy detect stuff. Leave it by default.
- Remove MDI crossover configuraton. Leave it by default. I think it's OK to
add new API to change the mode.
- PHY_RESET() is used to commit some changes, so I think it's not good to
always clear BMCR_AUTOEN before reset in makphy_reset().
- It's not required to read MII_100T2SR twice because this register has no
any bit which is latched.
- Use mii_phy_reset() instead of extracted code.
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Add some "XXX FIXME" comment. Non GMII mode uses different page except
very old chip. Some bits are at the same location but others are not.
- Remove obsolete comment.
- s/MII_MAKPHY_/MAKPHY_/

XXX rev. 1.44 changed the setting of mii_media_active when the interface is
set to other than auto. I suspect the intention of the change is to reflect
the link up/down status. But, it didn't work because non auto setting makes
PSSR_LINK bit alwasy set "without modifing some registers".
This commit won't fix the change and it'll be fixed in the next commit.
 1.2 18-Jun-2018  msaitoh branches: 1.2.2; 1.2.4;
- All of Marvell PHY's registers from addr 0x0 to 0xf conforms IEEE 802.3
specification, so those register definitions are not required. Use mii.h's
definitions. Note that E1000_ER_PAR_DETECT_FAULT should be 0x0010 instead of
0x0100(typo).
- Restore code for BMCR_ISO which was removed in makphy.c rev. 1.44
- Whitespace fix.
 1.1 16-Jun-2018  jdolecek switch to using OpenBSD eehpy(4) code to drive maphy(4), synchronizing support
for several special PHY conditions, particularly:
- Properly re-initialise the PHY upon resume
- Store next page in the Link Partner Next Page register for compatibility
with 802.3ab on 88E3016 PHYs. Fixes some autonegotiation problems on msk(4)
- Make 88E3016 actually work
- Make sure page 0 is selected when we initialize the PHY. Fixes problems
with the eephy(4) that attaches to nfe(4) on machines like the Sun Ultra 40.
(we had condition for this, now the page 0 is selected for any PHY type)
- Disable fiber/copper auto-selection on the 88E1111 if it is in RGMII mode, to
work around the fact that the onboard PHYs attached to nfe(4) on the Sun
X4100 M2 have fiber/copper auto-selection enabled even though the interfaces
are clearly copper-only

make sure to also add appropriate licenses, since basically nothing
really significant remains out of previous code

use FreeBSD <dev/mii/e1000reg.h> for register definitions as a base instead
of OpenBSD <dev/mii/eephyreg.h>, since it has some extra definitions for some
3016 bits, but add the several extra bits from OpenBSD needed by the code;
removed no longed used <dev/mii/makphyreg.h>

tested with PHY 88E1111, there no particular change observed - the
link status works as it did before, just now it does media nego
even before the interface is up

should however fix 88E3016 support and hence PR kern/49270 and PR kern/53301
 1.2.4.1 10-Jun-2019  christos Sync with HEAD
 1.2.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.2.2.2 25-Jun-2018  pgoyette Sync with HEAD
 1.2.2.1 18-Jun-2018  pgoyette file e1000phyreg.h was added on branch pgoyette-compat on 2018-06-25 07:25:51 +0000
 1.9 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.8 28-Feb-2020  msaitoh Move PHY_RESET() in the media change path from if_et.c to etphy.c.

I don't know if the reset is required or not. I tested some media
transitions without the reset and it worked. It might be OK to remove
but Linux does it only in et1011c_config_aneg(). So move the reset to
etphy_service(,,MII_MEDIACHG)'s autonego case. This change is also
required for future locking changes.
 1.7 27-Nov-2019  msaitoh branches: 1.7.2;
- Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.6 16-Aug-2019  msaitoh From FreeBSD:
- Support ET1011.
- Use mii_phy_flowstatus() to reflect flow status from negotiated result.
 1.5 16-Aug-2019  msaitoh No functional change:
- Use static.
- KNF.
 1.4 25-Mar-2019  msaitoh branches: 1.4.4;
KNF. No functional change.
 1.3 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.2 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.1 13-Nov-2010  jnemeth branches: 1.1.6; 1.1.54; 1.1.60; 1.1.62;
PR/39094 - Kaspar Brand -- Add et (Agere ET1310/ET1301) network driver

The et(4) driver supports PCI Express Ethernet adapters based on
the Agere/LSI ET1310/ET1301 integrated MAC/PHY.

The et(4) driver was written by Sepherosa Ziehau for DragonFlyBSD,
ported to OpenBSD by Jonathan Gray and subsequently ported to NetBSD
by Kaspar Brand.
 1.1.62.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.62.1 10-Jun-2019  christos Sync with HEAD
 1.1.60.1 26-Jan-2019  pgoyette Sync with HEAD
 1.1.54.1 14-Apr-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1529:

sys/dev/mii/miidevs 1.154, 1.162-1.167
sys/dev/mii/atphy.c 1.28 via patch
sys/dev/mii/brgphy.c 1.87 via patch
sys/dev/mii/etphy.c 1.5, 1.6 via patch
sys/dev/mii/rdcphy.c 1.6, 1.8 via patch

- Add support Broadcom BCM54213PE and some new RDC devices.
- Rename RDC to xxRDC.
- Use xxVIA instead of VIA.
- etphy(4):
- Rename ET1011 to ET1011C and add ET1011 support.
- Use mii_phy_flowstatus() to reflect flow status from negotiated
result.
- Use static.
- KNF.
 1.1.6.2 05-Mar-2011  rmind sync with head
 1.1.6.1 13-Nov-2010  rmind file etphy.c was added on branch rmind-uvmplock on 2011-03-05 20:53:31 +0000
 1.4.4.1 01-Sep-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #144):

sys/dev/mii/miidevs: revision 1.154
sys/dev/mii/etphy.c: revision 1.5
sys/dev/mii/etphy.c: revision 1.6

No functional change:
- Use static.
- KNF.

From FreeBSD:
- Rename ET1011 to ET1011C
- Add ET1011

From FreeBSD:
- Support ET1011.
- Use mii_phy_flowstatus() to reflect flow status from negotiated result.
 1.7.2.1 29-Feb-2020  ad Sync with head.
 1.58 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.57 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.56 25-Mar-2019  msaitoh KNF. No functional change.
 1.55 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.54 07-Jul-2016  msaitoh branches: 1.54.16; 1.54.18;
KNF. Remove extra spaces. No functional change.
 1.53 09-Jun-2013  msaitoh branches: 1.53.10;
Don't "return" but "break" in MII_TICK when the interface isn't doing
autonegotiaton or the link is up to update the status.
 1.52 19-Oct-2009  bouyer branches: 1.52.12; 1.52.22;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.51 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.50 04-May-2008  xtraeme branches: 1.50.6; 1.50.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.49 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.48 14-Apr-2008  spz branches: 1.48.2; 1.48.4;
pretty up if_ex: pmf'ify, device split, and improve printing a bit too.

Reviewed and function-tested on if_ex_cardbus by cube (thanks).
Function-tested on if_ex_pci by myself.
 1.47 08-Apr-2008  cegger use aprint_*_dev and device_xname
 1.46 29-Dec-2007  dyoung branches: 1.46.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.45 09-Dec-2007  jmcneill branches: 1.45.2;
Merge jmcneill-pm branch.
 1.44 16-Nov-2006  christos branches: 1.44.22; 1.44.24; 1.44.30; 1.44.34; 1.44.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.43 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.42 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.41 29-Mar-2006  thorpej branches: 1.41.8; 1.41.10;
Use device_private().
 1.40 28-Feb-2006  kleink branches: 1.40.2; 1.40.4; 1.40.6;
Reduce previous (!is(...) != 0) to (!is(...)).
 1.39 27-Feb-2006  thorpej Use device_is_a().
 1.38 20-Feb-2006  thorpej Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.37 11-Dec-2005  christos branches: 1.37.2; 1.37.4; 1.37.6;
merge ktrace-lwp.
 1.36 23-Aug-2004  thorpej branches: 1.36.12;
Make use of static.
 1.35 29-Apr-2003  thorpej branches: 1.35.2;
Use aprint*().
 1.34 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.33 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.32 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.31 27-Sep-2002  thorpej Rather than referencing the cfdriver directly in the cfdata entries,
instead use a string naming the driver. The cfdriver is then looked
up in a list which is built at run-time.
 1.30 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.29 25-Mar-2002  thorpej branches: 1.29.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.28 13-Nov-2001  lukem add RCSID
 1.27 25-Aug-2001  thorpej ANSI'ify.
 1.26 31-May-2001  thorpej branches: 1.26.2;
Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.25 04-Jul-2000  thorpej branches: 1.25.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.24 06-Mar-2000  thorpej branches: 1.24.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.23 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.22 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.21 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.20 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.19 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.18 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.17 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.16 23-Apr-1999  thorpej branches: 1.16.2; 1.16.4; 1.16.8;
Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.15 05-Nov-1998  thorpej branches: 1.15.6;
Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.14 04-Nov-1998  thorpej Routines common between the Uknown PHY driver (forthcoming) and other
PHY drivers. This file has ukphy_status(), which is what PHY drivers
should use if media detection is done by decoding NWay.
 1.13 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.12 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.11 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.10 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.9 03-Nov-1998  thorpej 3Com PHY can't be isolated, so don't allow IFM_NONE.
 1.8 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.7 23-Oct-1998  thorpej Don't print the revision of the 3c905B-TX's internal PHY; it's meaningless.
 1.6 23-Oct-1998  thorpej Make sure the parent is an `ex'. The 3c905B-TX's internal PHY isn't
the only one w/ non-existent ID registers. SIGH.
 1.5 28-Aug-1998  fvdl Add ETHER|NONE to default capabilities, or we'll panic when attaching
the forthcoming ex driver.
 1.4 12-Aug-1998  thorpej Make a variable name reflect a register name.
 1.3 12-Aug-1998  thorpej If autonegotiation is enabled in the BMSR, and the BMCR doens't claim
that it has completed, report "none" as the active media type.
 1.2 12-Aug-1998  thorpej Ugh, don't print out "autonegotiation failed to complete" if it did.
We get these once a second if we're in auto mode, the interface is up,
and there's no carrier.
 1.1 12-Aug-1998  thorpej Driver for the 3Com internal PHY, found on 3c905B-TX cards (and maybe
some 3c905-TX?). Partially from Frank van der Linden.
 1.15.6.1 23-Apr-1999  perry branches: 1.15.6.1.2;
pullup 1.15->1.16 (thorpej): Fix PR7361
 1.15.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.16.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.4.1 15-Nov-1999  fvdl Sync with -current
 1.16.2.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.24.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.25.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.25.2.5 01-Aug-2002  nathanw Catch up to -current.
 1.25.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.25.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.25.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.25.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.26.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.26.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.26.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.26.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.26.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.29.2.1 15-Jul-2002  gehenna catch up with -current.
 1.35.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.35.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.35.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.36.12.3 21-Jan-2008  yamt sync with head
 1.36.12.2 30-Dec-2006  yamt sync with head.
 1.36.12.1 21-Jun-2006  yamt sync with head.
 1.37.6.1 22-Apr-2006  simonb Sync with head.
 1.37.4.1 09-Sep-2006  rpaulo sync with head
 1.37.2.1 01-Mar-2006  yamt sync with head.
 1.40.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.40.4.1 19-Apr-2006  elad sync with head.
 1.40.2.1 01-Apr-2006  yamt sync with head.
 1.41.10.2 10-Dec-2006  yamt sync with head.
 1.41.10.1 22-Oct-2006  yamt sync with head
 1.41.8.1 18-Nov-2006  ad Sync with head.
 1.44.36.1 11-Dec-2007  yamt sync with head.
 1.44.34.1 26-Dec-2007  ad Sync with head.
 1.44.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.44.24.1 09-Jan-2008  matt sync with HEAD
 1.44.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.44.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.45.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.46.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.46.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.48.4.3 11-Mar-2010  yamt sync with head
 1.48.4.2 04-May-2009  yamt sync with head.
 1.48.4.1 16-May-2008  yamt sync with head.
 1.48.2.1 18-May-2008  yamt sync with head.
 1.50.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.50.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.52.22.2 03-Dec-2017  jdolecek update from HEAD
 1.52.22.1 23-Jun-2013  tls resync from head
 1.52.12.1 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.53.10.1 09-Jul-2016  skrll Sync with HEAD
 1.54.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.54.18.1 10-Jun-2019  christos Sync with HEAD
 1.54.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.55 03-Jan-2022  jmcneill Add driver for Motorcomm YT8511 GbE PHY
 1.54 11-Dec-2019  msaitoh Add ukphy_subr flag to ipgphy to make kernel compilable with ipgphy and
without ukphy. Pointed out by Hauke.
 1.53 01-Nov-2019  msaitoh Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.52 30-Oct-2019  msaitoh Add jmphy(4) from OpenBSD.
 1.51 07-Oct-2019  msaitoh Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by
Tomokazu HARADA and patch provided by Andrius V.
 1.50 15-Nov-2014  christos branches: 1.50.20; 1.50.26;
centralize the dialout/call unit macros.
 1.49 26-Feb-2014  ozaki-r Add Micrel PHY (KSZ9021RN)

The new driver micphy is almost same as ukphy except that
micphy has a fixup for cpsw; a PHY with cpsw has to adjust
RGMII signal timing.

Reviewed by christos@
 1.48 26-Jan-2011  bouyer branches: 1.48.4; 1.48.14; 1.48.18;
Add a driver for the RDC Semiconductor RDC R6040 10/100 Ethernet controller,
as found in the vortex86 SoCs (http://www.vortex86dx.com).
Ported from freebsd.
Not added to amd64's GENERIC because this CPU is 32bit only.

thanks to DM&P Electronics, Inc for providing documentation and sample
devices for this work.
 1.47 27-Nov-2010  christos branches: 1.47.2; 1.47.4;
PR/44080: Grégoire Sutre: Support for the i82577 ethernet PHY
 1.46 13-Nov-2010  jnemeth PR/39094 - Kaspar Brand -- Add et (Agere ET1310/ET1301) network driver

The et(4) driver supports PCI Express Ethernet adapters based on
the Agere/LSI ET1310/ET1301 integrated MAC/PHY.

The et(4) driver was written by Sepherosa Ziehau for DragonFlyBSD,
ported to OpenBSD by Jonathan Gray and subsequently ported to NetBSD
by Kaspar Brand.
 1.45 30-May-2010  pgoyette Extract MIIVERBOSE into a kernel module. The module can be builtin
by defining 'options MIIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.
 1.44 19-Apr-2009  msaitoh branches: 1.44.2; 1.44.4;
Oooops. Back out some of previous my commit.
 1.43 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.42 16-Jan-2009  cegger branches: 1.42.2;
Driver for Attansic Technology F1 10/100/1000 Ethernet PHY.

Written by Pyun YongHyeon for FreeBSD, ported to OpenBSD by Kevin Lo, ported to
NetBSD by me.
 1.41 02-Jan-2008  dyoung branches: 1.41.6; 1.41.10; 1.41.18; 1.41.20; 1.41.26;
Fix XEN2_DOMU (and amd64?) builds: move ether_mediastatus(),
ether_mediachange() to their own module that we compile only if
the kernel configuration demands support for both MII buses and
ethernet. Thanks to Tom Spindler for suggesting that these routines
move to dev/mii/.
 1.40 17-Feb-2007  jmcneill branches: 1.40.18; 1.40.24; 1.40.30;
Enable mvphy(4)
 1.39 21-Oct-2006  bouyer branches: 1.39.4;
Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.38 04-Jan-2006  xtraeme branches: 1.38.18; 1.38.20;
Add rlphy(4) (Realtek 8139/8201L PHY) from OpenBSD.
 1.37 11-Dec-2005  christos branches: 1.37.2;
merge ktrace-lwp.
 1.36 20-Feb-2005  jdolecek branches: 1.36.2; 1.36.4;
Add driver for 10/100/1000 copper PHY integrated on VIA Networking Technologies
VT6122 gigabit ethernet chips

From FreeBSD
 1.35 30-Dec-2004  jonathan branches: 1.35.2; 1.35.4;
Add rgephy driver to sys/dev/mii/files.mii. Supports integrated PHY
in Realtek 8169S.
 1.34 28-Oct-2003  fvdl Add a driver for the Intel IGPE1000 PHY as found on 82541 and 82547 chips.
Not yet enabled anywhere.
 1.33 17-Apr-2002  thorpej branches: 1.33.10;
* Move the mii_bitbang attribute into dev/mii/files.mii
* Pull in dev/mii/files.mii from conf/files, rather than playing
the magic "files include order" dance in N machine-dependent
configuration definitions.
 1.32 29-Mar-2002  ichiro add urlphy
 1.31 17-Mar-2002  chs lxtphy needs the ukphy_subr attribute now.
 1.30 28-Nov-2001  lukem - convert usage of "defopt" to "defflag" where the relevant option does
not support a value (e.g., it's to be used as "options FOO" instead of
"options FOO=xxx"). options that take a value were converted to
defparam recently.
- minor whitespace & formatting cleanups
 1.29 20-Nov-2001  lukem - replace "defopt" with "defparam" for options which must take a value,
as config(8) will warn for value-less defparam options
- minor whitespace/formatting cleanup
- consolidate opt_tcp_recvspace.h and opt_tcp_sendspace.h into opt_tcp_space.h
 1.28 25-Aug-2001  thorpej Driver for the 10BASE-T portion of the AMD 79c901 PHY.
 1.27 25-Aug-2001  thorpej Add a driver for generic HomePNA PHYs. Currently supports the HomePNA
portion of the AMD Am79c901.
 1.26 24-Aug-2001  thorpej Driver for the Altima AC101 10/100 Ethernet PHY.
 1.25 12-Jul-2001  thorpej Driver for the Level One LXT-1000 10/100/1000 PHY.
 1.24 12-Jul-2001  thorpej Code to handle generic ten-bit interfaces (1000BASE-{LX,SX} fiber
interfaces).
 1.23 12-Jul-2001  thorpej Driver for the Marvell 88E1000 ``Alaska'' 10/100/1000 PHY.
 1.22 02-Jun-2001  thorpej branches: 1.22.2;
Driver for the Broadcom BCM5201/BCM5202 "Mini-Theta" Ethernet
PHYs. This is also the same PHY core as in the 3Com 3c905C.
The PHY is documented in the 3c905C manual.
 1.21 01-Jun-2001  thorpej Driver for Broadcom BCM5400-family Gig-E PHYs. Programming
information gleaned from FreeBSD.
 1.20 31-May-2001  thorpej Add a driver for the NatSemi DP83891 and DP83861 Gig PHYTER
10/100/1000 PHYs.
 1.19 24-Feb-2001  lukem branches: 1.19.2;
whitespace police
 1.18 11-Jun-2000  sommerfeld defopt MIIVERBOSE
 1.17 02-Feb-2000  thorpej branches: 1.17.2;
Driver for the Davicom DM9101 10/100 Ethernet PHY. This PHY is found
on several inexpensive 10/100 Ethernet boards (e.g. D-Link DFE-530TX,
Winbond 10/100 boards), and is also the built-in PHY on the DM9102
10/100 Ethernet chip.
 1.16 07-Dec-1999  thorpej Add a driver for the National Semiconductor DP83843 `PHYTER' 10/100
Ethernet PHY.
 1.15 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.14 04-Sep-1999  soren branches: 1.14.2; 1.14.4; 1.14.8;
Add Intel 82553 and TSC 78Q2120.
 1.13 05-Nov-1998  thorpej Add a driver for "generic unknown PHYs", meant as a catch-all for
PHYs we don't have specific drivers for. While this will not give
optimum operation, it will allow network interface drivers to at least
function while drivers for their specific PHYs are written.
 1.12 04-Nov-1998  thorpej Routines common between the Uknown PHY driver (forthcoming) and other
PHY drivers. This file has ukphy_status(), which is what PHY drivers
should use if media detection is done by decoding NWay.
 1.11 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.10 03-Nov-1998  thorpej Driver for Seeq 80220/80221/80223 10/100 Ethernet PHYs.
 1.9 02-Nov-1998  thorpej Driver for the Integrated Circuit Systems ICS1980 10/100 PHY.
 1.8 24-Oct-1998  thorpej Driver for the Level One LXT-970 10/100 Ethernet PHY.
 1.7 12-Aug-1998  thorpej Driver for the 3Com internal PHY, found on 3c905B-TX cards (and maybe
some 3c905-TX?). Partially from Frank van der Linden.
 1.6 11-Aug-1998  thorpej Change the name of the attribute to "mii".
 1.5 11-Aug-1998  thorpej Adapt to MII layer changes.
 1.4 16-Feb-1998  thorpej Remove "class" declarations, and add "devclass" declarations where
appropriate. Fix several inconsistencies between device class and
attributes. Mostly from Chris Demetriou.
 1.3 12-Jan-1998  thorpej Adjust for config changes.
 1.2 05-Jan-1998  perry RCSID Police.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.14.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.4.1 15-Nov-1999  fvdl Sync with -current
 1.14.2.2 12-Mar-2001  bouyer Sync with HEAD.
 1.14.2.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.17.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.2.7 20-Jun-2002  nathanw Catch up to -current.
 1.19.2.6 01-Apr-2002  nathanw Pull up urlphy addition so GENERIC configures.
 1.19.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.19.2.4 08-Jan-2002  nathanw Catch up to -current.
 1.19.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.19.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.19.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.22.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.22.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.22.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.22.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.22.2.1 03-Aug-2001  lukem update to -current
 1.33.10.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.33.10.4 17-Jan-2005  skrll Sync with HEAD.
 1.33.10.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.10.2 18-Sep-2004  skrll Sync with HEAD.
 1.33.10.1 03-Aug-2004  skrll Sync with HEAD
 1.35.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.35.2.1 29-Apr-2005  kent sync with -current
 1.36.4.4 21-Jan-2008  yamt sync with head
 1.36.4.3 26-Feb-2007  yamt sync with head.
 1.36.4.2 30-Dec-2006  yamt sync with head.
 1.36.4.1 21-Jun-2006  yamt sync with head.
 1.36.2.2 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.36.2.1 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.37.2.1 15-Jan-2006  yamt sync with head.
 1.38.20.1 22-Oct-2006  yamt sync with head
 1.38.18.1 18-Nov-2006  ad Sync with head.
 1.39.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.40.30.1 02-Jan-2008  bouyer Sync with HEAD
 1.40.24.1 18-Feb-2008  mjf Sync with HEAD.
 1.40.18.1 09-Jan-2008  matt sync with HEAD
 1.41.26.1 21-Apr-2010  matt sync to netbsd-5
 1.41.20.2 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.41.20.1 03-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #735):
sys/dev/pci/if_age.c: revisions 1.1-1.28
sys/dev/pci/if_agereg.h: revisions 1.1-1.2
sys/dev/pci/if_ale.c: revisions 1.1-1.3
sys/dev/pci/if_alereg.h: revisions 1.1-1.2
sys/dev/pci/files.pci: revisions 1.310-1.313
sys/dev/mii/atphy.c: revisions 1.1-1.5
sys/dev/mii/files.mii: revision 1.42
share/man/man4/age.4: revisions 1.1-1.3
share/man/man4/ale.4: revisions 1.1-1.2
share/man/man4/atphy.4: revisions 1.1-1.2
share/man/man4/Makefile: revisions 1.486, 1.489
distrib/sets/lists/man/mi: revisions 1.1118, 1.1132
sys/arch/i386/conf/GENERIC: revisions 1.928, 1.933
sys/arch/i386/conf/XEN2_DOM0: revisions 1.57, 1.60
sys/arch/amd64/conf/GENERIC: revisions 1.239, 1.241
sys/arch/amd64/conf/XEN3_DOM0: revisions 1.38, 1.42
Add the age(4) and ale(4) drivers for Attansic L1 and Atheros
AR8121/AR8113/AR8114 devices respectively.
 1.41.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.41.10.2 11-Aug-2010  yamt sync with head.
 1.41.10.1 04-May-2009  yamt sync with head.
 1.41.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.42.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.44.4.2 05-Mar-2011  rmind sync with head
 1.44.4.1 03-Jul-2010  rmind sync with head
 1.44.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.47.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.47.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.48.18.1 18-May-2014  rmind sync with head
 1.48.14.2 03-Dec-2017  jdolecek update from HEAD
 1.48.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.4.1 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.50.26.3 11-Dec-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #543):

sys/dev/mii/files.mii: revision 1.54

Add ukphy_subr flag to ipgphy to make kernel compilable with ipgphy and
without ukphy. Pointed out by Hauke.
 1.50.26.2 25-Nov-2019  martin Regen for ticket 479
 1.50.26.1 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #476):

sys/dev/pci/if_stgereg.h: revision 1.6
sys/arch/amd64/conf/ALL: revision 1.124
sys/dev/mii/files.mii: revision 1.51
share/man/man4/vge.4: revision 1.8
share/man/man4/vge.4: revision 1.9
distrib/sets/lists/man/mi: revision 1.1656
sys/arch/i386/conf/ALL: revision 1.471
share/man/man4/mii.4: revision 1.28
sys/dev/pci/if_stge.c: revision 1.71
sys/dev/mii/ipgphy.c: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.2
share/man/man4/Makefile: revision 1.684
sys/dev/mii/ipgphy.c: revision 1.3
sys/dev/mii/ipgphyreg.h: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.4
sys/dev/mii/ipgphyreg.h: revision 1.2
sys/dev/mii/ipgphy.c: revision 1.5
sys/dev/mii/ipgphyreg.h: revision 1.3
sys/dev/DEVNAMES: revision 1.322
sys/arch/i386/conf/GENERIC: revision 1.1211
sys/arch/amd64/conf/GENERIC: revision 1.537
share/man/man4/ipgphy.4: revision 1.1
share/man/man4/ipgphy.4: revision 1.2

Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by

Tomokazu HARADA and patch provided by Andrius V.

New sentence, new line.
Fix date. Add RCS Id.

KNF. No functional change.

STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.

- Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
- Define IPGPHY_SCR's address.
- Whitespace fix.

Add missing NetBSD RCS Id. Reported by Andrius V.
 1.50.20.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.2 17-Nov-1997  thorpej KNF.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.4 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.3 17-Nov-1997  thorpej Fix RCS ID.
 1.2 17-Nov-1997  thorpej Cosmetic changes.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.32 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.31 15-Mar-2020  thorpej branches: 1.31.8;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.30 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.29 25-Mar-2019  msaitoh KNF. No functional change.
 1.28 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.27 16-Jun-2014  msaitoh branches: 1.27.26; 1.27.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.26 16-Jun-2014  msaitoh No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.25 11-Jun-2014  msaitoh Print vendor and model like ukphy(4).
 1.24 19-Oct-2009  bouyer branches: 1.24.18; 1.24.22; 1.24.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.23 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.22 04-May-2008  xtraeme branches: 1.22.6; 1.22.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.21 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.20 08-Apr-2008  cegger branches: 1.20.2; 1.20.4;
use aprint_*_dev and device_xname
 1.19 09-Dec-2007  jmcneill branches: 1.19.10;
Merge jmcneill-pm branch.
 1.18 16-Nov-2006  christos branches: 1.18.22; 1.18.24; 1.18.34; 1.18.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.17 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.16 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.15 29-Mar-2006  thorpej branches: 1.15.8; 1.15.10;
Use device_private().
 1.14 11-Dec-2005  christos branches: 1.14.4; 1.14.6; 1.14.8; 1.14.10; 1.14.12;
merge ktrace-lwp.
 1.13 23-Aug-2004  thorpej branches: 1.13.12;
Make use of static.
 1.12 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.11 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.10 29-Apr-2003  thorpej branches: 1.10.2;
Use aprint*().
 1.9 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.8 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.7 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.6 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.5 25-Mar-2002  thorpej branches: 1.5.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.4 13-Nov-2001  lukem add RCSID
 1.3 25-Aug-2001  thorpej ANSI'ify.
 1.2 25-Jul-2001  thorpej branches: 1.2.2; 1.2.4;
Fix 1000BASE-X duplex negotiation. That'll teach me to read the
manual more carefully next time.
 1.1 12-Jul-2001  thorpej Code to handle generic ten-bit interfaces (1000BASE-{LX,SX} fiber
interfaces).
 1.2.4.7 18-Oct-2002  nathanw Catch up to -current.
 1.2.4.6 01-Aug-2002  nathanw Catch up to -current.
 1.2.4.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.4.4 14-Nov-2001  nathanw Catch up to -current.
 1.2.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.2.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.2.4.1 25-Jul-2001  nathanw file gentbi.c was added on branch nathanw_sa on 2001-08-24 00:09:58 +0000
 1.2.2.7 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.2.2 03-Aug-2001  lukem update to -current
 1.2.2.1 25-Jul-2001  lukem file gentbi.c was added on branch kqueue on 2001-08-03 04:13:13 +0000
 1.5.2.1 15-Jul-2002  gehenna catch up with -current.
 1.10.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.13.12.3 21-Jan-2008  yamt sync with head
 1.13.12.2 30-Dec-2006  yamt sync with head.
 1.13.12.1 21-Jun-2006  yamt sync with head.
 1.14.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.14.10.1 19-Apr-2006  elad sync with head.
 1.14.8.1 01-Apr-2006  yamt sync with head.
 1.14.6.1 22-Apr-2006  simonb Sync with head.
 1.14.4.1 09-Sep-2006  rpaulo sync with head
 1.15.10.2 10-Dec-2006  yamt sync with head.
 1.15.10.1 22-Oct-2006  yamt sync with head
 1.15.8.1 18-Nov-2006  ad Sync with head.
 1.18.36.1 11-Dec-2007  yamt sync with head.
 1.18.34.1 26-Dec-2007  ad Sync with head.
 1.18.24.1 09-Jan-2008  matt sync with HEAD
 1.18.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.18.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.19.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.19.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.3 11-Mar-2010  yamt sync with head
 1.20.4.2 04-May-2009  yamt sync with head.
 1.20.4.1 16-May-2008  yamt sync with head.
 1.20.2.1 18-May-2008  yamt sync with head.
 1.22.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.22.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.36.1 10-Aug-2014  tls Rebase.
 1.24.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.27.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27.28.1 10-Jun-2019  christos Sync with HEAD
 1.27.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.31.8.1 01-Aug-2021  thorpej Sync with HEAD.
 1.32 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.31 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.30 26-Nov-2019  msaitoh Fix typo in comment.
 1.29 25-Mar-2019  msaitoh KNF. No functional change.
 1.28 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.27 19-Feb-2019  msaitoh Fix duplicated LEVEL1_LXT1000_OLD entry. I suspect one of them is
LEVEL1_LXT1000.
 1.26 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.25 07-Jul-2016  msaitoh branches: 1.25.16; 1.25.18;
KNF. Remove extra spaces. No functional change.
 1.24 16-Jun-2014  msaitoh branches: 1.24.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.23 19-Oct-2009  bouyer branches: 1.23.18; 1.23.22; 1.23.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.22 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.21 04-May-2008  xtraeme branches: 1.21.6; 1.21.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.20 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.19 08-Apr-2008  cegger branches: 1.19.2; 1.19.4;
use aprint_*_dev and device_xname
 1.18 09-Dec-2007  jmcneill branches: 1.18.10;
Merge jmcneill-pm branch.
 1.17 16-Nov-2006  christos branches: 1.17.22; 1.17.24; 1.17.34; 1.17.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.16 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.15 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.14 29-Mar-2006  thorpej branches: 1.14.8; 1.14.10;
Use device_private().
 1.13 11-Dec-2005  christos branches: 1.13.4; 1.13.6; 1.13.8; 1.13.10; 1.13.12;
merge ktrace-lwp.
 1.12 23-Aug-2004  thorpej branches: 1.12.12;
Make use of static.
 1.11 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.10 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.9 29-Apr-2003  thorpej branches: 1.9.2;
Use aprint*().
 1.8 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.7 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.6 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.5 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.4 25-Mar-2002  thorpej branches: 1.4.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.3 13-Nov-2001  lukem add RCSID
 1.2 25-Aug-2001  thorpej ANSI'ify.
 1.1 12-Jul-2001  thorpej branches: 1.1.2; 1.1.4;
Driver for the Level One LXT-1000 10/100/1000 PHY.
 1.1.4.7 18-Oct-2002  nathanw Catch up to -current.
 1.1.4.6 01-Aug-2002  nathanw Catch up to -current.
 1.1.4.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.4.4 14-Nov-2001  nathanw Catch up to -current.
 1.1.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 12-Jul-2001  nathanw file glxtphy.c was added on branch nathanw_sa on 2001-08-24 00:09:58 +0000
 1.1.2.7 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.6 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.2.5 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.2.2 03-Aug-2001  lukem update to -current
 1.1.2.1 12-Jul-2001  lukem file glxtphy.c was added on branch kqueue on 2001-08-03 04:13:13 +0000
 1.4.2.1 15-Jul-2002  gehenna catch up with -current.
 1.9.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.9.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.9.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.12.3 21-Jan-2008  yamt sync with head
 1.12.12.2 30-Dec-2006  yamt sync with head.
 1.12.12.1 21-Jun-2006  yamt sync with head.
 1.13.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.13.10.1 19-Apr-2006  elad sync with head.
 1.13.8.1 01-Apr-2006  yamt sync with head.
 1.13.6.1 22-Apr-2006  simonb Sync with head.
 1.13.4.1 09-Sep-2006  rpaulo sync with head
 1.14.10.2 10-Dec-2006  yamt sync with head.
 1.14.10.1 22-Oct-2006  yamt sync with head
 1.14.8.1 18-Nov-2006  ad Sync with head.
 1.17.36.1 11-Dec-2007  yamt sync with head.
 1.17.34.1 26-Dec-2007  ad Sync with head.
 1.17.24.1 09-Jan-2008  matt sync with HEAD
 1.17.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.17.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.18.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.18.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.19.4.3 11-Mar-2010  yamt sync with head
 1.19.4.2 04-May-2009  yamt sync with head.
 1.19.4.1 16-May-2008  yamt sync with head.
 1.19.2.1 18-May-2008  yamt sync with head.
 1.21.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.21.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.23.36.1 10-Aug-2014  tls Rebase.
 1.23.22.2 03-Dec-2017  jdolecek update from HEAD
 1.23.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.24.4.1 09-Jul-2016  skrll Sync with HEAD
 1.25.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.25.18.1 10-Jun-2019  christos Sync with HEAD
 1.25.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 12-Jul-2001  thorpej branches: 1.1.2; 1.1.4; 1.1.122; 1.1.124; 1.1.126;
Driver for the Level One LXT-1000 10/100/1000 PHY.
 1.1.126.1 16-May-2008  yamt sync with head.
 1.1.124.1 18-May-2008  yamt sync with head.
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 12-Jul-2001  nathanw file glxtphyreg.h was added on branch nathanw_sa on 2001-08-24 00:09:58 +0000
 1.1.2.2 03-Aug-2001  lukem update to -current
 1.1.2.1 12-Jul-2001  lukem file glxtphyreg.h was added on branch kqueue on 2001-08-03 04:13:13 +0000
 1.37 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.36 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.35 26-Nov-2019  msaitoh Fix typo in comment.
 1.34 21-Nov-2019  msaitoh Whitespace.
 1.33 25-Mar-2019  msaitoh KNF. No functional change.
 1.32 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.31 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.30 07-Jul-2016  msaitoh branches: 1.30.16; 1.30.18;
KNF. Remove extra spaces. No functional change.
 1.29 16-Jun-2014  msaitoh branches: 1.29.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.28 07-Jan-2010  jdc branches: 1.28.18; 1.28.22; 1.28.36;
Add DP83865 to the supported PHY list (from OpenBSD).
 1.27 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.26 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.25 05-May-2008  tsutsui branches: 1.25.6; 1.25.8;
Use device_private() where appropriate.
 1.24 04-May-2008  xtraeme device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.23 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.22 08-Apr-2008  cegger branches: 1.22.2; 1.22.4;
use aprint_*_dev and device_xname
 1.21 20-Jan-2008  msaitoh branches: 1.21.6;
mii_physubr.c::mii_phy_reset() has gphyter and nsphyter specific delay(500).
This delay cause 500us loops under splnet() per linkdown port per mii_tick.
It causes periodically drop packets. It's not acceptable for other devices.

Move gphyter and nsphyter specific delay(500) into the drivers from
mii_physubr.c.
 1.20 09-Dec-2007  jmcneill branches: 1.20.2;
Merge jmcneill-pm branch.
 1.19 16-Nov-2006  christos branches: 1.19.22; 1.19.24; 1.19.30; 1.19.34; 1.19.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.18 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.17 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.16 11-Dec-2005  christos branches: 1.16.20; 1.16.22;
merge ktrace-lwp.
 1.15 23-Aug-2004  thorpej branches: 1.15.12;
Make use of static.
 1.14 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.13 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.12 29-Apr-2003  thorpej branches: 1.12.2;
Use aprint*().
 1.11 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.10 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.9 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.8 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.7 25-Mar-2002  thorpej branches: 1.7.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.6 13-Nov-2001  lukem add RCSID
 1.5 25-Aug-2001  thorpej ANSI'ify.
 1.4 30-Jun-2001  bjh21 branches: 1.4.2;
IFM_1000_TX -> IFM_1000_T, as (breifly) discussed on tech-net.
 1.3 02-Jun-2001  thorpej branches: 1.3.2;
Make PHY matching all table-driven.
 1.2 31-May-2001  thorpej On the Gig PHYTER, For whatever reason, the 10baseT-related bits of the
BMSR are wired to 0, yet the PHY supports 10baseT. So, to get around
this, we test the ANAR 10baseT bits after a PHY reset. These bits are
set according to input pin 180. If we see the 10baseT ANAR bits set,
we fake them in the BMSR so that we can actually autonegotiate 10baseT.
 1.1 31-May-2001  thorpej Add a driver for the NatSemi DP83891 and DP83861 Gig PHYTER
10/100/1000 PHYs.
 1.3.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.3.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.3.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.3.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.3.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.3.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.2.1 02-Jun-2001  nathanw file gphyter.c was added on branch nathanw_sa on 2001-06-21 20:04:18 +0000
 1.4.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.4.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.4.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.4.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.7.2.1 15-Jul-2002  gehenna catch up with -current.
 1.12.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.12.2 21-Jan-2008  yamt sync with head
 1.15.12.1 30-Dec-2006  yamt sync with head.
 1.16.22.2 10-Dec-2006  yamt sync with head.
 1.16.22.1 22-Oct-2006  yamt sync with head
 1.16.20.1 18-Nov-2006  ad Sync with head.
 1.19.36.1 11-Dec-2007  yamt sync with head.
 1.19.34.1 26-Dec-2007  ad Sync with head.
 1.19.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.19.24.2 23-Mar-2008  matt sync with HEAD
 1.19.24.1 09-Jan-2008  matt sync with HEAD
 1.19.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.19.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.20.2.1 20-Jan-2008  bouyer Sync with HEAD
 1.21.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.21.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.4.3 11-Mar-2010  yamt sync with head
 1.22.4.2 04-May-2009  yamt sync with head.
 1.22.4.1 16-May-2008  yamt sync with head.
 1.22.2.1 18-May-2008  yamt sync with head.
 1.25.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.25.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.28.36.1 10-Aug-2014  tls Rebase.
 1.28.22.2 03-Dec-2017  jdolecek update from HEAD
 1.28.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.29.4.1 09-Jul-2016  skrll Sync with HEAD
 1.30.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.30.18.1 10-Jun-2019  christos Sync with HEAD
 1.30.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 31-May-2001  thorpej branches: 1.1.2; 1.1.122; 1.1.124; 1.1.126;
Add a driver for the NatSemi DP83891 and DP83861 Gig PHYTER
10/100/1000 PHYs.
 1.1.126.1 16-May-2008  yamt sync with head.
 1.1.124.1 18-May-2008  yamt sync with head.
 1.1.122.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.2.1 31-May-2001  nathanw file gphyterreg.h was added on branch nathanw_sa on 2001-06-21 20:04:19 +0000
 1.56 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.55 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.54 25-Mar-2019  msaitoh KNF. No functional change.
 1.53 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.52 13-Feb-2019  msaitoh Add ICS1893C support from FreeBSD.
 1.51 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.50 07-Jul-2016  msaitoh branches: 1.50.16; 1.50.18;
KNF. Remove extra spaces. No functional change.
 1.49 16-Jun-2014  msaitoh branches: 1.49.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.48 19-Oct-2009  bouyer branches: 1.48.18; 1.48.22; 1.48.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.47 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.46 04-May-2008  xtraeme branches: 1.46.6; 1.46.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.45 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.44 08-Apr-2008  cegger branches: 1.44.2; 1.44.4;
use aprint_*_dev and device_xname
 1.43 29-Dec-2007  dyoung branches: 1.43.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.42 09-Dec-2007  jmcneill branches: 1.42.2;
Merge jmcneill-pm branch.
 1.41 16-Nov-2006  christos branches: 1.41.22; 1.41.24; 1.41.30; 1.41.34; 1.41.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.40 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.39 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.38 29-Mar-2006  thorpej branches: 1.38.8; 1.38.10;
Use device_private().
 1.37 20-Feb-2006  thorpej branches: 1.37.2; 1.37.4; 1.37.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.36 11-Dec-2005  christos branches: 1.36.2; 1.36.4; 1.36.6;
merge ktrace-lwp.
 1.35 27-Feb-2005  perry branches: 1.35.4;
nuke trailing whitespace
 1.34 23-Aug-2004  thorpej branches: 1.34.4; 1.34.6;
Make use of static.
 1.33 01-Jul-2003  msaitoh branches: 1.33.2;
- last commit (rev. 1.32) fixes icsphy_reset()'s problem. ICSphys don't
restart auto negotiation, so it kick.
- add comment in icsphy_reset()
 1.32 01-Jul-2003  msaitoh Add ICS1889 and 1892
 1.31 29-Apr-2003  thorpej Use aprint*().
 1.30 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.29 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.28 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.27 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.26 25-Mar-2002  thorpej branches: 1.26.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.25 10-Feb-2002  wiz Match ICS 1893.
 1.24 13-Nov-2001  lukem add RCSID
 1.23 25-Aug-2001  thorpej ANSI'ify.
 1.22 02-Jun-2001  thorpej branches: 1.22.2;
Make PHY matching all table-driven.
 1.21 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.20 28-Mar-2001  drochner update for miidevs changes
 1.19 04-Jul-2000  thorpej branches: 1.19.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.18 06-Mar-2000  thorpej branches: 1.18.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.17 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.16 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.15 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.14 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.13 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.12 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.11 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.10 14-May-1999  drochner branches: 1.10.2; 1.10.4; 1.10.8;
use the new "xx" prefixed OUIs because the mapping to the ID register
bits differs from the MII_OUI() way
 1.9 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.8 05-Nov-1998  thorpej branches: 1.8.6;
Common code for media-from-bmcr.
 1.7 05-Nov-1998  thorpej In the status routine, always use the media selected in the BMCR if
autonegotiation is not enabled. This is more reliable on many PHYs,
and requires fewer register reads.
 1.6 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.5 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.4 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.3 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.2 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.1 02-Nov-1998  thorpej Driver for the Integrated Circuit Systems ICS1980 10/100 PHY.
 1.8.6.1 23-Apr-1999  perry branches: 1.8.6.1.2;
pullup 1.8->1.9 (thorpej): Fix PR7361
 1.8.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.10.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.10.4.1 15-Nov-1999  fvdl Sync with -current
 1.10.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.10.2.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.18.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.19.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.19.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.19.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.19.2.5 28-Feb-2002  nathanw Catch up to -current.
 1.19.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.19.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.19.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.19.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.22.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.22.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.22.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.22.2.3 16-Mar-2002  jdolecek Catch up with -current.
 1.22.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.22.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.26.2.1 15-Jul-2002  gehenna catch up with -current.
 1.33.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.33.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.33.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.34.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.34.4.1 29-Apr-2005  kent sync with -current
 1.35.4.3 21-Jan-2008  yamt sync with head
 1.35.4.2 30-Dec-2006  yamt sync with head.
 1.35.4.1 21-Jun-2006  yamt sync with head.
 1.36.6.1 22-Apr-2006  simonb Sync with head.
 1.36.4.1 09-Sep-2006  rpaulo sync with head
 1.36.2.1 01-Mar-2006  yamt sync with head.
 1.37.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.37.4.1 19-Apr-2006  elad sync with head.
 1.37.2.1 01-Apr-2006  yamt sync with head.
 1.38.10.2 10-Dec-2006  yamt sync with head.
 1.38.10.1 22-Oct-2006  yamt sync with head
 1.38.8.1 18-Nov-2006  ad Sync with head.
 1.41.36.1 11-Dec-2007  yamt sync with head.
 1.41.34.1 26-Dec-2007  ad Sync with head.
 1.41.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.41.24.1 09-Jan-2008  matt sync with HEAD
 1.41.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.41.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.42.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.43.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.43.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.44.4.3 11-Mar-2010  yamt sync with head
 1.44.4.2 04-May-2009  yamt sync with head.
 1.44.4.1 16-May-2008  yamt sync with head.
 1.44.2.1 18-May-2008  yamt sync with head.
 1.46.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.46.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.48.36.1 10-Aug-2014  tls Rebase.
 1.48.22.2 03-Dec-2017  jdolecek update from HEAD
 1.48.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.49.4.1 09-Jul-2016  skrll Sync with HEAD
 1.50.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.18.1 10-Jun-2019  christos Sync with HEAD
 1.50.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4 06-Jun-2024  andvar s/dupled/duplex/ in comments.
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 01-Jul-2003  msaitoh branches: 1.2.100; 1.2.102; 1.2.104;
Add ICS1889 and 1892
 1.1 02-Nov-1998  thorpej Driver for the Integrated Circuit Systems ICS1980 10/100 PHY.
 1.2.104.1 16-May-2008  yamt sync with head.
 1.2.102.1 18-May-2008  yamt sync with head.
 1.2.100.1 02-Jun-2008  mjf Sync with HEAD.
 1.37 04-Nov-2020  msaitoh Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.36 03-Aug-2020  msaitoh branches: 1.36.2;
Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.
 1.35 03-Aug-2020  msaitoh s/MII_IGPHY_/IGPHY_/. No functional change.
 1.34 07-Jul-2020  msaitoh - Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.33 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.32 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.31 25-Mar-2019  msaitoh branches: 1.31.4;
KNF. No functional change.
 1.30 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.29 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.28 08-Jan-2019  msaitoh Whitespace fixes. No functional change.
 1.27 06-Jul-2017  msaitoh branches: 1.27.4; 1.27.6;
Update comment. SmartSpeed workaroud code was added in rev. 1.5. No functional
change.
 1.26 07-Jul-2016  msaitoh branches: 1.26.10;
KNF. Remove extra spaces. No functional change.
 1.25 30-Oct-2015  msaitoh igphy(4),ukphy(4): Set mii_mpd_* entries.
wm(4): check PHY type correctly.
 1.24 24-Aug-2015  pooka add some _KERNEL_OPT as the finishing touch
 1.23 16-Jun-2014  msaitoh branches: 1.23.2; 1.23.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.22 18-Oct-2012  msaitoh branches: 1.22.10;
Style fix. No functional change.
 1.21 07-Mar-2010  msaitoh branches: 1.21.10; 1.21.16; 1.21.20;
Add two workarounds for ICH8 with igp3.
- Workaround for 82566 Kumeran PCS lock loss.
- WOL from S5 stops working.
 1.20 16-Dec-2009  msaitoh branches: 1.20.2;
Sync with Intel's original em driver:
- Add dspcode for igp3 and use it when the EEPROM isn't available.
- Add some delays.
- Stop the PHY transmitter before patching the DSP code and restart it after wrote.
- Save and restore register 0x2f5b.
 1.19 16-Dec-2009  msaitoh Re-enable igphy's 82566 support.
- Patch for the DSP code is only for 8254[17] and we have to apply the
different patches between rev. 1 and rev. 2.
- The workaround for analog fuse is only for 82547 rev. 1.
- The workaround for smartspeed is only for 8254[17]

see http://mail-index.netbsd.org/tech-net/2009/08/05/msg001546.html
 1.18 06-Aug-2009  kml Later generation 82566 IGP PHYs have problems with media changes to 100Mb and
10Mb; it appears that the SmartSpeed workaround and dspcode in this PHY are
aimed at earlier generation IGPs. Remove reference to 82566s, allowing
them to fall through to choose other PHYs.
 1.17 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.16 04-May-2008  xtraeme branches: 1.16.6; 1.16.8; 1.16.10; 1.16.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.15 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.14 08-Apr-2008  cegger branches: 1.14.2; 1.14.4;
use aprint_*_dev and device_xname
 1.13 09-Dec-2007  jmcneill branches: 1.13.10;
Merge jmcneill-pm branch.
 1.12 28-Aug-2007  msaitoh branches: 1.12.8; 1.12.10;
add I82566
 1.11 23-Feb-2007  msaitoh branches: 1.11.4; 1.11.12; 1.11.16; 1.11.18;
fix some negotiation problems on wm(4).

will fix PR#30078, PR#30490, PR#30906, PR#33429, PR#35386.
 1.10 16-Nov-2006  christos branches: 1.10.2; 1.10.4;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.9 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.8 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.7 29-Mar-2006  thorpej branches: 1.7.8; 1.7.10;
Use device_private().
 1.6 11-Dec-2005  christos branches: 1.6.4; 1.6.6; 1.6.8; 1.6.10; 1.6.12;
merge ktrace-lwp.
 1.5 05-Oct-2004  thorpej branches: 1.5.10; 1.5.12;
Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.4 23-Aug-2004  thorpej Make use of static.
 1.3 11-Apr-2004  thorpej branches: 1.3.2;
gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.2 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.1 28-Oct-2003  fvdl branches: 1.1.2; 1.1.4;
Add a driver for the Intel IGPE1000 PHY as found on 82541 and 82547 chips.
Not yet enabled anywhere.
 1.1.4.1 07-Jan-2005  jdc Pull up revision 1.5 (requested by thorpej in ticket #897)

Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.1.2.1 07-Jan-2005  jdc Pull up revision 1.5 (requested by thorpej in ticket #897)

Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.3.2.6 19-Oct-2004  skrll Sync with HEAD
 1.3.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 11-Apr-2004  skrll file igphy.c was added on branch ktrace-lwp on 2004-08-03 10:48:49 +0000
 1.5.12.5 21-Jan-2008  yamt sync with head
 1.5.12.4 03-Sep-2007  yamt sync with head.
 1.5.12.3 26-Feb-2007  yamt sync with head.
 1.5.12.2 30-Dec-2006  yamt sync with head.
 1.5.12.1 21-Jun-2006  yamt sync with head.
 1.5.10.1 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.6.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.6.10.1 19-Apr-2006  elad sync with head.
 1.6.8.1 01-Apr-2006  yamt sync with head.
 1.6.6.1 22-Apr-2006  simonb Sync with head.
 1.6.4.1 09-Sep-2006  rpaulo sync with head
 1.7.10.2 10-Dec-2006  yamt sync with head.
 1.7.10.1 22-Oct-2006  yamt sync with head
 1.7.8.1 18-Nov-2006  ad Sync with head.
 1.10.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.10.2.2 29-Aug-2007  liamjfoy Pull up following revision(s) (requested by masanobu in ticket #850):

sys/dev/pci/if_wm.c 1.137
sys/dev/pci/if_wm.c 1.138
sys/dev/pci/if_wm.c 1.141
sys/dev/pci/if_wm.c 1.144
sys/dev/pci/if_wmreg.h 1.23
sys/dev/pci/pcidevs 1.893
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphy.c 1.12
sys/dev/mii/miidevs 1.72
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/wm.4 1.18

Fix for 82541 and 82547's reset bug.
Modify wm_reset() to make some device stable.
Add ICH9 support to wm.
Add I82566 support to igphy.

Pulled done via patch.
 1.10.2.1 26-Mar-2007  jdc branches: 1.10.2.1.2;
Pull up revision 1.11 (requested by msaitoh in ticket #514).

fix some negotiation problems on wm(4).

will fix PR#30078, PR#30490, PR#30906, PR#33429, PR#35386.
 1.10.2.1.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.11.18.2 09-Jan-2008  matt sync with HEAD
 1.11.18.1 06-Nov-2007  matt sync with HEAD
 1.11.16.3 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.11.16.2 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.11.16.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.11.12.1 03-Sep-2007  skrll Sync with HEAD.
 1.11.4.1 09-Oct-2007  ad Sync with head.
 1.12.10.1 11-Dec-2007  yamt sync with head.
 1.12.8.1 26-Dec-2007  ad Sync with head.
 1.13.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.13.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.4.4 11-Mar-2010  yamt sync with head
 1.14.4.3 19-Aug-2009  yamt sync with head.
 1.14.4.2 04-May-2009  yamt sync with head.
 1.14.4.1 16-May-2008  yamt sync with head.
 1.14.2.1 18-May-2008  yamt sync with head.
 1.16.14.1 21-Apr-2010  matt sync to netbsd-5
 1.16.10.2 19-Nov-2010  riz Pull up revisions (requested by msaitoh in ticket #1358):
sys/dev/pci/if_wm.c 1.196-1.199,1.202,1.205
sys/dev/pci/if_wmvar.h 1.9
sys/dev/pci/if_wmreg.h 1.36-1.39
sys/dev/pci/pcireg.h 1.61-1.64
sys/dev/pci/pcidevs 1.1023
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
mii/igphy.c 1.21
mii/igphyvar.h 1.1
mii/inbmphyreg.h 1.2

- Count Receive error, CRC error, Alignment error, Symbol error, Sequence
error, Carrier extension error and Receive length error into ierror.
Fixes PR#30349 reported by UMEZAWA Takeshi.
- Add support for 82575, 82576 and 82580(ER).
- Apply the patch for 82575 from Wolfgang Stukenbrock (PR#42422). We use
only one RX ring and with the legacy mode.
- Add support for 82576.
- Partial support for 82580.
- Partial support for the serdes systems.
- Add two workarounds for ICH8 with igp3.
- Workaround for 82566 Kumeran PCS lock loss.
- WOL from S5 stops working.
- (pcireg.h) Add PCIe config register definitions.
- Note that the changes to count Missed packet (rx fifo overflow) and Receive
no buffers (rx ring full) into iqdrops in rev. 1.196 of if_wm.c is not
pulled up.
 1.16.10.1 23-Dec-2009  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1203):
sys/dev/pci/if_wm.c: 1.176-1.179, 1.181-1.183
sys/dev/pci/if_wmreg.h: 1.28
sys/dev/pci/if_wmvar.h: 1.1-1.4
sys/dev/mii/igphy.c: 1.18-1.20 via patch

Many bugfixes:
- Some fixes for i80003 and ICH{8,9,10} from e1000 driver and document:
- Add setting for KABGTXD register for ICH{8,9,10}.
- ICH9 and ICH10 has no FCAL, FCAH and FCT like ICH8.
- Add special setting for FCTTV and TCTL_EXT register for i80003
- The special setting for TIPG is only for i80003.
- Some of kumeran settings are only for i80003's bugs.
- Add some ICH10 fixes.
- Fix the bug that another lock mechanism is used to access Kumeran
registers on i80003 and ICHs.
- Fix yet another i80003 ONLY workaround. The code to modifing TIPG
register is only for i80003.
- Set the Re-Transmit on Late Collision(RTLC) flag for all devices.
- Fix a typo in a printf message.
- If the difference bettween last flag and new flag is only IFF_PROMISC
or IFF_ALLMULTI, set multicast filter only to prevent link down.
Tested by Mark Davies and me. Fixes PR#29126 for wm.
- Cleanup interrupt establish error messages. Do not mix
aprint_error/aprint_normal/printf calls for a single line.
- Fix igphy's 82566 support.
- Patch for the DSP code is only for 8254[17] and we have to apply
the different patches between rev. 1 and rev. 2.
- The workaround for analog fuse is only for 82547 rev. 1.
- The workaround for smartspeed is only for 8254[17]
- Sync with Intel's original em driver:
- Check PCI-X mode as e1000 driver.
- Add dspcode for igp3 and use it when the EEPROM isn't available.
- Add some delays.
- Stop the PHY transmitter before patching the DSP code and
restart it after writing.
- Save and restore register 0x2f5b.
 1.16.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.16.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.20.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.21.20.3 03-Dec-2017  jdolecek update from HEAD
 1.21.20.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.20.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.21.16.2 06-May-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1366):
sys/dev/pci/if_wm.c: 1.281, 1.318, 1.320, 1.324-1.332, 1.334, 1.336, 1.343-1.344, 1.347-1.348, 1.350, 1.376-1.382, 1.386-1.387, 1.389 via patch
sys/dev/pci/if_wmreg.h: 1.68-1.70, 1.73-1.77, 1.79-1.80, 1.82, 1.86-1.88 via patch
sys/dev/pci/if_wmvar.h: 1.22-1.23, 1.25-1.30 via patch
sys/dev/mii/igphy.c: 1.25
sys/dev/mii/ukphy.c: 1.48
Sync wm(4) as of if_wm.c rev 1.389 except SERDES, MSI/MSI-X, multiqueue
and NET_MPSAFE:
- Set ICH9 and ICH10's PBA size to 14K if the RX buffer size is more
than 4096. Almost the same as other OSes.
- For 82576 and newer devices, the PBA register is deleted. Don't write
PBA for those chips. Also change the calculation of RX packet buffer
size in new way.
- Print NVM image version and option ROM version.
- Add workaround for I210 Errata 25 and I211 Errata 10 (PLL bug). This
workaround is required if the NVM image version < 3.25.
- Fix a bug that wm_detach() didn't unmap the FHASH's area. Now
"drvctl -d wm0" -> "drvctl -r pci0" works on ICH* and PCH*.
- Add workaround for 82574 Errata 25 and 82583 Errata 12 "Dropped RX
packets" and for 82573 (unknown). Set GCR_L1_ACT_WITHOUT_L0S_RX bit.
The NVM Image version 2.1.4 and newer have this workaround.
- Check PHY type correctly. This change is required to use igphy(4)
device correctly.
- Disable LPLU (Low Power Link Up) on D0 state on 82574, 82583 and ICH*
too.
- Call wm_get_hw_control() correctly. This change fixes a bug that some
AMT based systems doesn't linkup at 1000BaseT. The problem was
observed on HP Compaq dc7700. A lot of fixes have been done for wm(4)
and igphy(4), so now PR#44893 should be fixed.
- Call wm_get_wakeup(sc) before checking WM_F_HAS_AMT. It's required to
check the existence of AMT correctly.
- Fix a problem that wm_gate_hw_phy_config_ich8lan() isn't called in
wm_reset() on PCH2.
- Clear WMREG_WUC in wm_reset() if the chip >= 82544. This might fix
the behavior on suspend/resume.
- Fix logic of wm_check_reset_block() on ICH* and PCH*. This change
might fix a problem that PHY's read/write functions can't get
semaphore.
- On ICH8, call wm_gig_downshift_workaround_ich8lan() when link changed
down.
- Drop PHY_CTRL_GBE_DIS explicitly in wm_lplu_d0_disable() in case BIOS
sets this bit.
- Fix two bugs in wm_kmrn_lock_loss_workaround_ich8lan(). Now the
function checks the status correctly but it causes linkdown up to 10
times, so it's disabled for the time being.
- PR/50527: David Binderman: Fix impossible code. Odd offsets need
special treatment.
- Fix RAL table's size of PCH2 and PCH_LPT.
- PCH_LPT (and newer device) is required to check FWSM_WLOCK_MAC bit to
determine the range of the RAL.
- Use sc->sc_itr instead of hard-coded number.
- Rename wm_tbi_check_link() to wm_tbi_tick() because this function
acts as mii_tick().
- ACK Accelerate Disable in the RFCTL register is not bit 13 but 12.
No binary change because this definition has not used yet.
- Add ACK data Disable bit's definition (not used yet).
- PHY_CTRL_GBE_DIS is not bit 4 but bit 6. This change has no any
effect by default because WM_WOL is not defined yet and
m_kmrn_lock_loss_workaround_ich8lan() is broken.
- Fix wm_check_mng_mode_ich8lan(). This function is used only when
WM_WOL is defined and it's disabled by default.
- Rename wm_check_reset_block() to wm_phy_resetisblocked() and make it
returns bool. No functional change.
- Reorder function definitions and macro definitions. No functional
change.
- Fix comment. Add comment. Update comment.
- KNF.
 1.21.16.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.21.10.1 30-Oct-2012  yamt sync with head
 1.22.10.1 10-Aug-2014  tls Rebase.
 1.23.4.4 28-Aug-2017  skrll Sync with HEAD
 1.23.4.3 09-Jul-2016  skrll Sync with HEAD
 1.23.4.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.23.4.1 22-Sep-2015  skrll Sync with HEAD
 1.23.2.1 26-Feb-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1102):
sys/dev/mii/igphy.c: 1.25
sys/dev/mii/ukphy.c: 1.48
sys/dev/pci/if_wm.c: revisions 1.308, 1.318, 1.320, 1.324-1.332, 1.334, 1.336, 1.343-1.344, 1.347-1.348, 1.350, 1.376-1.382, 1.386-1.389 via patch
sys/dev/pci/if_wmreg.h: revisions 1.68-1.70, 1.73-1.77, 1.79-1.80, 1.82, 1.86-1.88 via patch
sys/dev/pci/if_wmvar.h: revisions 1.22-1.23, 1.25-1.30 via patch
Sync wm(4) as of if_wm.c rev 1.389 except MSI/MSI-X, multiqueue and NET_MPSAFE:
- Add C2000 KX and 2.5G support.
- Set ICH9 and ICH10's PBA size to 14K if the RX buffer size is more than
4096. Almost the same as other OSes.
- For 82576 and newer devices, the PBA register is deleted. Don't write PBA
for those chips. Also change the calculation of RX packet buffer size in
new way.
- Fix a lot of bugs to make 82575 and newer SERDES based systems work.
- Print NVM image version and option ROM version.
- Add workaround for I210 Errata 25 and I211 Errata 10 (PLL bug). This
workaround is required if the NVM image version < 3.25.
- Fix a bug that wm_detach() didn't unmap the FHASH's area. Now
"drvct -d wm0" -> "drvctl -r pci0" works on ICH* and PCH*.
- Add workaround for 82574 Errata 25 and 82583 Errata 12 "Dropped RX packets"
and for 82573 (unknown). Set GCR_L1_ACT_WITHOUT_L0S_RX bit. The NVM Image
version 2.1.4 and newer have this workaround.
- Check PHY type correctly. This change is required to use igphy(4) device
correctly.
- Disable LPLU (Low Power Link Up) on D0 state on 82574, 82583 and ICH* too.
- Call wm_get_hw_control() correctly. This change fixes a bug that some AMT
based systems doesn't linkup at 1000BaseT. The problem was observed on HP
Compaq dc7700. A lot of fixes have been done for wm(4) and igphy(4), so now
PR#44893 should be fixed.
- Call wm_get_wakeup(sc) before checking WM_F_HAS_AMT. It's required to
check the existence of AMT correctly.
- Fix a problem that wm_gate_hw_phy_config_ich8lan() isn't called in
wm_reset() on PCH2.
- Clear WMREG_WUC in wm_reset() if the chip >= 82544. This might fix the
behavior on suspend/resume.
- Fix logic of wm_check_reset_block() on ICH* and PCH*. This change might fix
a problem that PHY's read/write functions can't get semaphore.
- On ICH8, call wm_gig_downshift_workaround_ich8lan() when link changed down.
- Drop PHY_CTRL_GBE_DIS explicitly in wm_lplu_d0_disable() in case BIOS sets
this bit.
- Fix two bugs in wm_kmrn_lock_loss_workaround_ich8lan(). Now the function
checks the status correctly but it causes linkdown up to 10 times, so it's
disabled for the time being.
- PR/50527: David Binderman: Fix impossible code. Odd offsets need special
treatment.
- Fix RAL table's size of PCH2 and PCH_LPT.
- PCH_LPT (and newer device) is required to check FWSM_WLOCK_MAC bit to
determine the range of the RAL.
- Use sc->sc_itr instead of hard-coded number.
- Rename wm_tbi_check_link() to wm_tbi_tick() because this function acts as
mii_tick().
- ACK Accelerate Disable in the RFCTL register is not bit 13 but 12.
No binary change because this definition has not used yet.
- Add ACK data Disable bit's definition (not used yet).
- PHY_CTRL_GBE_DIS is not bit 4 but bit 6. This change has no any effect by
default because WM_WOL is not defined yet and
m_kmrn_lock_loss_workaround_ich8lan() is broken.
- Fix wm_check_mng_mode_ich8lan(). This function is used only when WM_WOL is
defined and it's disabled by default.
- Rename wm_check_reset_block() to wm_phy_resetisblocked() and make it returns
bool. No functional change.
- Reorder function definitions and macro definitions. No functional change.
- Fix comment. Add comment. Update comment.
- KNF.
 1.26.10.3 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1726):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.26.10.2 05-Aug-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1594:

sys/dev/pci/if_wm.c 1.655-1.658, 1.660,
1.662, 1.664-1.668,
1.671-1.674, 1.678,
1.680-1.685 via patch
sys/dev/pci/if_wmreg.c 1.118-1.119 via patch
sys/dev/pci/if_wmvar.c 1.45 via patch
sys/dev/mii/igphy.c 1.35-1.36 via patch
sys/dev/mii/igphyreg.h 1.12-1.13
sys/dev/mii/makphy.c 1.66 via patch
sys/dev/mii/makphyreg.h 1.11

- Add SFP support. Module insertion/removal is not supported yet.
Currently, SFP detection is only done in the driver's attach phase.
- Detect the Media Auto Sense feature. Not supported yet.
- Fix SFF_SFP_ETH_FLAGS_100FX. It's not 0x10 but 0x20.
- Add extra delay in wm_serdes_power_up_link_82575().
- Add Intel I219 LM10-LM15 and V10-V14.
- wm(4) can use workqueue as deferred Rx/Tx handler).
Set hw.wm*.txrx_workqueue=1 to use workqueue instead of softint.
The default value of hw.wm*.txrx_workqueue is 0 which use softint
as before.
- Unset RSS UDP flags like ixg(4) and other OSes. To handle IP
fragmented UDP, first packet and second packet should be processed
in the same Rx queue.
- It's useless to not to set PCI_PMCSR_PME_STS bit when writing because
the bit is W1C. Instead, always write PCI_PMCSR_PME_STS bit to clear
in case it's already set.
- Actually writing always the checksum offload context descriptor
makes the HW do extra processing, avoid doing that if possible.
- Fix a bug that the WMREG_EEARBC_I210 register is incorrectly set if
the system uses iNVM.
- "wmX: 0" on 82542 is difficult to understand, so don't print it.
- Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID to avoid undefined behavior.
- Set if_baudrate for non-MII device.
- Rename some macros and function.
- KNF. Add comment.
 1.26.10.1 01-Aug-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #173):
sys/dev/pci/if_wmreg.h: 1.99-1.103
sys/dev/pci/if_wmvar.h: 1.34-1.37
sys/dev/pci/if_wm.c: 1.510-1.537
sys/dev/mii/ihphyreg.h: 1.2
sys/dev/mii/inbmphyreg.h: 1.10
sys/dev/mii/igphy.c: 1.27
Sync wm(4) up to if_wm.c rev. 1.537:
- Set WMREG_KABGTXD not in wm_init_locked() but in wm_reset().
- If a legacy interrupt is a spurious interrupt, don't print debug
message.
- Don't print the Image Unique ID if an NVM is iNVM (i210 and I211).
- Fix a bug that a RAL was written at incorrect address when the index
number is more than 16 on 82544 and newer.
- The layout of RAL on PCH* are different from others. Fix it.
- Flush every MTA write. Same as Linux.
- Move the location of calling wm_set_filter. Same as some other OSes.
- Flush writing WMREG_CTRL in wm_gmii_mediachange().
- Make new wm_phy_post_reset() and use this function at all location
after resetting phy.
- Add I219 specific workaround for legacy interrupt. From OpenBSD.
- Move the location of calling wm_lplu_d0_disable().
- Disable D0 LPLU on 8257[12356], 82580, I350 and I21[01], too. Before
this commit, above devices and non-PCIe devices accessed wrong
register.
- Fix latency calculation in wm_platform_pm_pch_lpt().
- Set OBFF water mark and enable OBFF on PCH_LPT and newer.
- Fix a bug that wm_gmii_i82544_{read,write}reg() didn't take care of
page select. PHY access from igphy() automatically did it, but
accessing from wm(4) for workaround didn't work correctly. This
change affects 8254[17], 8257[12] ICH8, ICH9 and ICH10.
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- IF TX is not required to flush, RX is also not required to flush in
wm_flush_desc_rings(). Same as other OSes.
- Remove wrong semaphore access in wm_nvm_{read,write}_{ich8,spt} to
prevent hangup. A semaphore is get/put in wm_nvm_{read,write}.
- Move some initialization stuff in wm_attach() before wm_reset().
Some flags and callback function is required to set correctly before
wm_reset() because wm_reset() and some helper functions refer them.
- Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access
HV_SMB_ADDR correctly.
- Configure the LCD with the extended configuration region in NVM if
it's required. Tested with Thinkpad X220.
- 8257[12]: Don't directly access SPI but use EERD register.
- 82575-I354: If the size of SPI ROM >= 32K words, use direct SPI
access instead of EERD register access.
- Add wm_nvm_eec_clock_raise() and wm_nvm_eec_clock_lower() and use
them for Microwire/SPI bus control. Same as Linux and FreeBSD.
- Reduce timeout value for 80003 in wm_get_swfw_semaphore(). Same as
Linux and FreeBSD.
- Change API of kmrn_{read,write}reg() and check the return value.
- Check whether it's required to use MDIC workaround for 80003 or not
in wm_reset(). If the workaround isn't required, don't use the
workaround code in wm_gmii_i80003_{read,write}reg.
- Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers
say "In rare circumstances, the SW semaphore may already be held
unintentionally." on I21[01]. PXE boot is one of the case.
- Qemu's e1000e emulation (82574L)'s SPI has only 64 words. I've never
seen on real 82574 hardware with such small SPI ROM. Check
NVM word size before accessing higher address words to prevent
timeout.
- Check some wm_nvm_read()'s return vale.
- Use device_printf() instead of aprint_error_dev() for PHY read/write
functions because those are used not only in device attach.
- Print internal driver flags when attaching.
- Add debug printf()s.
- Rename variables.
- Add comment, update comment and remove wrong comment.
 1.27.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27.6.1 10-Jun-2019  christos Sync with HEAD
 1.27.4.2 26-Jan-2019  pgoyette Sync with HEAD
 1.27.4.1 18-Jan-2019  pgoyette Synch with HEAD
 1.31.4.2 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1409):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.31.4.1 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1040):

sys/dev/mii/igphy.c: revision 1.35
sys/dev/mii/igphy.c: revision 1.36
sys/dev/mii/igphyreg.h: revision 1.12
sys/dev/mii/igphyreg.h: revision 1.13
sys/dev/mii/makphyreg.h: revision 1.11
sys/dev/pci/if_wm.c: revision 1.682
sys/dev/pci/if_wm.c: revision 1.683
sys/dev/pci/if_wm.c: revision 1.684
sys/dev/pci/if_wm.c: revision 1.685
sys/dev/mii/makphy.c: revision 1.66

s/MII_IGPHY_/IGPHY_/. No functional change.

Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.

Setup PCS and SGMII for SFP correctly. It still doesn't support SFP
insertion/removal.

Copper:
wm2: SGMII(SFP)
wm2: 0x1043c440<SPI,IOH_VALID,PCIE,SGMII,NEWQUEUE,ASF_FIRM,EEE,SFP>
makphy0 at wm2 phy 6: Marvell 88E1111 Gigabit PHY, rev. 1

Fiber:
wm3: SERDES(SFP)
wm3: 0x10034440<SPI,IOH_VALID,PCIE,NEWQUEUE,ASF_FIRM,SFP>
wm3: 1000baseSX, 1000baseSX-FDX, auto

Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID. Found by kUBSan.

Set if_baudrate for non-MII device. Before this commit, it was 0.
 1.36.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.13 03-Aug-2020  msaitoh Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.
 1.12 03-Aug-2020  msaitoh s/MII_IGPHY_/IGPHY_/. No functional change.
 1.11 22-Jan-2019  msaitoh branches: 1.11.4;
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.10 07-Nov-2016  msaitoh branches: 1.10.8; 1.10.14; 1.10.16;
Fix previous (s/MII_MAXREGADDR/MII_ADDRMASK/).
 1.9 28-Oct-2016  msaitoh - Use MII_ADDRMASK.
- Remove debug printf().
 1.8 26-Oct-2015  msaitoh branches: 1.8.2;
No binary change:
- s/IGPPHY/IGPHY/
- Fix the definition of PLHR_VALID_CHANNEL_*
- Fix the definition of MSE_CHANNEL_*
- Add MII_IGPHY_POWER_MGMT
 1.7 23-Oct-2015  msaitoh - PSCR_TP_LOOPBACK is not bit 0 but bit 4. No binary change because
this macro is not used.
- Rename MII_IGPPHY_PORT_CONFIG's bit definitions from PSCR_ to PSCFR_
to avoid confusion. PSCR_ is for MII_IGPHY_PORT_CTRL.
 1.6 07-Mar-2010  msaitoh branches: 1.6.20; 1.6.36; 1.6.38; 1.6.42;
- Add code for WOL, ASF, IPMI and Intel AMT.
- wm_enable_wakeup() is disabled by default. If you want to use WOL with
the Magic Packet, define WM_WOL.
- Add the following flags:
WM_F_ASF_FIRMWARE_PRESENT
WM_F_ARC_SUBSYSTEM_VALID
WM_F_HAS_AMT
WM_F_HAS_MANAGE
WM_F_WOL
- Add wm_suspend() and wm_resume(). Give/get the control to/from the
firmware.
- Need more work for PCH. See wm_enable_phy_wakeup().
- Enable wm_get_hw_control() for 82574 and 82583.
- Add Yet another workaround for ICH8.
- Add wm_igp3_phy_powerdown_workaround_ich8lan() for power down problem
on D3.
 1.5 12-Jan-2010  msaitoh branches: 1.5.2;
Add some macros
 1.4 11-Dec-2005  christos branches: 1.4.74; 1.4.86; 1.4.94;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 05-Oct-2004  thorpej branches: 1.2.4; 1.2.6;
Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.1 28-Oct-2003  fvdl branches: 1.1.2; 1.1.4; 1.1.6;
Add a driver for the Intel IGPE1000 PHY as found on 82541 and 82547 chips.
Not yet enabled anywhere.
 1.1.6.1 07-Jan-2005  jdc Pull up revision 1.2 (requested by thorpej in ticket #897)

Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.1.4.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.5 19-Oct-2004  skrll Sync with HEAD
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 28-Oct-2003  skrll file igphyreg.h was added on branch ktrace-lwp on 2004-08-03 10:48:49 +0000
 1.1.2.1 07-Jan-2005  jdc Pull up revision 1.2 (requested by thorpej in ticket #897)

Enable the SmartSpeed work-around code for the IGP phy, with some
minor adjustments.
 1.2.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.4.1 29-Apr-2005  kent sync with -current
 1.4.94.1 21-Apr-2010  matt sync to netbsd-5
 1.4.86.2 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.4.86.1 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1277):
sys/dev/pci/if_wm.c 1.184-1.192, 1.194
sys/dev/pci/if_wmreg.h 1.29-1.35
sys/dev/pci/if_wmvar.h 1.5-1.8
sys/dev/pci/pcidevs 1.1006,1.1009-1.1010, 1.1012-1.1013 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.5
sys/dev/mii/inbmphyreg.h 1.1

- Add support for i82583V.
- Add some ICH9 and ICH10 devices.
- Add support for PCH.
- Fix the bug that ICH9 can't found a PHY. Fixes PR#42237
- Fix an incorrect test for WM_F_EEPROM_INVALID since rev. 1.183. Some old
chips don't set EECD_EE_PRES.
- Fix a bug that both WM_F_EEPROM_SPI and WM_F_EEPROM_FLASH are set.
- Add a missing decrement for a timeout reported by Wolfgang Stukenbrock
in PR#42422.
- PBA setting for i82574 is not 12K but 20K.
- Enable checking the management mode on 82574.
- Fix the length of the delay() in wm_gmii_reset(). It fixed the problem that
sometimes the driver misunderstood PHYs in mii_attach(). It was reported
by MATSUI Yoshihiro. We observed it on ICH9.
- Fix the checking of jumbo frame function
- Remove the extra macro definition for the offset 0x1a in EEPROM.
- Add missing break in wm_reset()...
- Fix the offset of WMREG_PBS...
- Make wm_reset() and wm_gmii_reset() close to e1000 driver.
At least, this change make wm_attach() stable on ICH9.
- Reset GMII interface after wm_reset() in wm_init().
- Rework for assigning mii_{read,write}reg(). Use PCI product ID to identify
the PHY.
- Add code about LPLU(Low Power Link Up) function. It seems that we have to
do the same work for ICH9.
- Fixes the rx stall problem on 82578 by MANY workaround code. We need more
work for 82577.
 1.4.74.1 11-Mar-2010  yamt sync with head
 1.5.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.6.42.1 18-Jan-2017  skrll Sync with netbsd-5
 1.6.38.2 05-Dec-2016  skrll Sync with HEAD
 1.6.38.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.6.36.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1302):
sys/dev/mii/igphyreg.h: revisions 1.7-1.10
sys/dev/mii/ikphyreg.h: revisions 1.3
sys/dev/mii/inbmphyreg.h: revisions 1.4-1.9
sys/dev/mii/mii.h: revisions 1.19-1.20
sys/dev/pci/if_wm.c: revisions 1.390, 1.392-1.395, 1.397, 1.419-1.425, 1.427-1.428, 1.430-1.435, 1.437-1.453 via patch
sys/dev/pci/if_wmreg.: revisions 1.89-1.93 via patch
sys/dev/pci/if_wmvar.h: revisions 1.31-1.32
Update wm(4) up to if_wm.c rev. 1.453 except MSI/MSI-X, multiqueue and
NET_MPSAFE:
- Add I219 support. It's not stable so it's disabled by default.
- wm_gate_hw_phy_config_ich8lan() is for younger than PCH2.
- Drop the host wakeup bit after resetting PHY on PCH and newer
devices.
- Increase delay while toggling LANPHYPC
- Move call of wm_reset() in wm_attach() after setting PHY and NVM
related flags because those flags are used in wm_reset().
- Use mutex for NVM access on ICH8 and newer devices. Same as FreeBSD.
- Rewrite PHY related lock stuff. Almost the same as FreeBSD.
This change will fix a bug that PHY read/write fail on some cases.
- Increase delay in wm_phy_resetisblocked(). Same as FreeBSD.
- Use semaphore in wm_hv_phy_workaround_ich8lan() and
wm_k1_gig_workaround_hv()
- Use wm_gii_mdic_readreg/writereg() in wm_access_phy_wakeup_reg_bm()
because these functions are called with taking lock.
- 82567V_3 is BME1000_E_2(bm). Tested with Advantech AIMB-212 1st
Ethernet port.
- Use wm_gmii_82544_{read,write}reg() on non-82567 ICH8, 9 and 10.
- Remove an 82578 workaround which was for PCH rev < 3. FreeBSD
removed this workaround in r228386.
- Add an 82578 workaround which is for PHY rev < 2. From FreeBSD and
Linux.
- Fix wm(4) input drop packet counter. WMREG_RNBC is incremented when
there is no available buffers in host memory. However, ethernet
controller can receive packets in such case if there is space in
phy's FIFO. That is, ethernet controller drops packet only if there
is no available buffers *and* there is no space in phy's FIFO. So,
the number of dropped packets should be added WMREG_MPC only.
- Use MII_ADDRMASK.
- Define WMPHY_I217, WMPHY_VF and WMPHY_210.
- Use BME1000_PHY_PAGE_SELECT in wm_gmii_bm_{read,write}reg(). This
change has no effect because GG82563_PHY_PAGE_SELECT and
BME1000_PHY_PAGE_SELECT have the same value.
- Fix PHY access on 82567(ICH8 or ICH10), 82574 and 82583:
- Use wm_gmii_bm_{read,write}reg() on 82574 and 82573.
- Issue page select correctly on BM PHYs.
- Fix workaround which did dummy read BM_WUC register. This code was
changed to drop BM_WUC_HOST_WU_BIT of BM_PROT_GEN_CFG register in
FreeBSD r228386. The code was added rev. 1.149, but the location was
not the best.
- wm_gmii_hv_{read/write}reg*(): USE PHY address 1 for some special
registers.
- Add check code for an 82578 workaround. Not completed yet.
- wm_release_hw_control(): Remove extra line. No any effect.
- Add "10/100" into non-gigabit devices' name.
- Call wm_enable_wakeup() in wm_detach() and wm_suspend(). Now wake on
lan works on Thinkpad X61(ICH8).
- Fix wm_access_phy_wakeup_reg_bm(). This change has no effect because
this function is used for WUC register and our driver currenlty
doesn't access to it.
- Call wm_enable_phy_wakeup() on PCH2 and newer, too. Now these devices
can do WOL. Tested with Thinkpad X220(PCH2).
- Set CTRL_MEHE correctly (PCH_{LPT,SPT} only).
- Add three workarounds for PCH_{LPT,SPT}.
- Fix a bug that 8257[56], 82580, I35[04] and I21[01] didn't use
wm_{get,release}_hw_control() correctly.
- Sync wm_smbustopci() with Linux and FreeBSD. This change effects PCH
and newer devices.
- Move the location of wm_smbustopci() call.
- Fix flag check in wm_get_wakeup()
- 8254[17]* and 8257[124] should not set WM_F_ARC_SUBSYS_VALID.
- Add missing WM_T_82541_2 and WM_T_82547_2.
- Fix WOL related setting of the WUC register for other than PCH* in
wm_enable_wakeup(). Tested with 82567V(ICH8) and 82583V.
- Use common MII_ADDRMASK.
- igphy(4): No binary change:
- s/IGPPHY/IGPHY/
- Fix the definition of PLHR_VALID_CHANNEL_*
- Fix the definition of MSE_CHANNEL_*
- Add MII_IGPHY_POWER_MGMT.
- Add some KASSERT.
- Add comment. Modify comment.
- Add debug code.
 1.6.20.1 03-Dec-2017  jdolecek update from HEAD
 1.8.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.8.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.10.16.1 10-Jun-2019  christos Sync with HEAD
 1.10.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.10.8.1 05-Aug-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1594:

sys/dev/pci/if_wm.c 1.655-1.658, 1.660,
1.662, 1.664-1.668,
1.671-1.674, 1.678,
1.680-1.685 via patch
sys/dev/pci/if_wmreg.c 1.118-1.119 via patch
sys/dev/pci/if_wmvar.c 1.45 via patch
sys/dev/mii/igphy.c 1.35-1.36 via patch
sys/dev/mii/igphyreg.h 1.12-1.13
sys/dev/mii/makphy.c 1.66 via patch
sys/dev/mii/makphyreg.h 1.11

- Add SFP support. Module insertion/removal is not supported yet.
Currently, SFP detection is only done in the driver's attach phase.
- Detect the Media Auto Sense feature. Not supported yet.
- Fix SFF_SFP_ETH_FLAGS_100FX. It's not 0x10 but 0x20.
- Add extra delay in wm_serdes_power_up_link_82575().
- Add Intel I219 LM10-LM15 and V10-V14.
- wm(4) can use workqueue as deferred Rx/Tx handler).
Set hw.wm*.txrx_workqueue=1 to use workqueue instead of softint.
The default value of hw.wm*.txrx_workqueue is 0 which use softint
as before.
- Unset RSS UDP flags like ixg(4) and other OSes. To handle IP
fragmented UDP, first packet and second packet should be processed
in the same Rx queue.
- It's useless to not to set PCI_PMCSR_PME_STS bit when writing because
the bit is W1C. Instead, always write PCI_PMCSR_PME_STS bit to clear
in case it's already set.
- Actually writing always the checksum offload context descriptor
makes the HW do extra processing, avoid doing that if possible.
- Fix a bug that the WMREG_EEARBC_I210 register is incorrectly set if
the system uses iNVM.
- "wmX: 0" on 82542 is difficult to understand, so don't print it.
- Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID to avoid undefined behavior.
- Set if_baudrate for non-MII device.
- Rename some macros and function.
- KNF. Add comment.
 1.11.4.1 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1040):

sys/dev/mii/igphy.c: revision 1.35
sys/dev/mii/igphy.c: revision 1.36
sys/dev/mii/igphyreg.h: revision 1.12
sys/dev/mii/igphyreg.h: revision 1.13
sys/dev/mii/makphyreg.h: revision 1.11
sys/dev/pci/if_wm.c: revision 1.682
sys/dev/pci/if_wm.c: revision 1.683
sys/dev/pci/if_wm.c: revision 1.684
sys/dev/pci/if_wm.c: revision 1.685
sys/dev/mii/makphy.c: revision 1.66

s/MII_IGPHY_/IGPHY_/. No functional change.

Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.

Setup PCS and SGMII for SFP correctly. It still doesn't support SFP
insertion/removal.

Copper:
wm2: SGMII(SFP)
wm2: 0x1043c440<SPI,IOH_VALID,PCIE,SGMII,NEWQUEUE,ASF_FIRM,EEE,SFP>
makphy0 at wm2 phy 6: Marvell 88E1111 Gigabit PHY, rev. 1

Fiber:
wm3: SERDES(SFP)
wm3: 0x10034440<SPI,IOH_VALID,PCIE,NEWQUEUE,ASF_FIRM,SFP>
wm3: 1000baseSX, 1000baseSX-FDX, auto

Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID. Found by kUBSan.

Set if_baudrate for non-MII device. Before this commit, it was 0.
 1.1 07-Mar-2010  msaitoh branches: 1.1.2; 1.1.6; 1.1.8;
Add two workarounds for ICH8 with igp3.
- Workaround for 82566 Kumeran PCS lock loss.
- WOL from S5 stops working.
 1.1.8.2 19-Nov-2010  riz Pull up revisions (requested by msaitoh in ticket #1358):
sys/dev/pci/if_wm.c 1.196-1.199,1.202,1.205
sys/dev/pci/if_wmvar.h 1.9
sys/dev/pci/if_wmreg.h 1.36-1.39
sys/dev/pci/pcireg.h 1.61-1.64
sys/dev/pci/pcidevs 1.1023
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
mii/igphy.c 1.21
mii/igphyvar.h 1.1
mii/inbmphyreg.h 1.2

- Count Receive error, CRC error, Alignment error, Symbol error, Sequence
error, Carrier extension error and Receive length error into ierror.
Fixes PR#30349 reported by UMEZAWA Takeshi.
- Add support for 82575, 82576 and 82580(ER).
- Apply the patch for 82575 from Wolfgang Stukenbrock (PR#42422). We use
only one RX ring and with the legacy mode.
- Add support for 82576.
- Partial support for 82580.
- Partial support for the serdes systems.
- Add two workarounds for ICH8 with igp3.
- Workaround for 82566 Kumeran PCS lock loss.
- WOL from S5 stops working.
- (pcireg.h) Add PCIe config register definitions.
- Note that the changes to count Missed packet (rx fifo overflow) and Receive
no buffers (rx ring full) into iqdrops in rev. 1.196 of if_wm.c is not
pulled up.
 1.1.8.1 07-Mar-2010  riz file igphyvar.h was added on branch netbsd-5 on 2010-11-19 23:40:29 +0000
 1.1.6.2 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.6.1 07-Mar-2010  uebayasi file igphyvar.h was added on branch uebayasi-xip on 2010-04-30 14:43:28 +0000
 1.1.2.2 11-Mar-2010  yamt sync with head
 1.1.2.1 07-Mar-2010  yamt file igphyvar.h was added on branch yamt-nfs-mp on 2010-03-11 15:03:41 +0000
 1.20 05-Nov-2021  msaitoh Don't power down the PHY when the interface goes down.

- All of other PHY drivers don't power down the PHY. Do the same way.
- At least, keeping the link is required for Intel AMT and WoL.
 1.19 04-Nov-2020  msaitoh Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.18 28-Mar-2020  thorpej branches: 1.18.4;
Don't set DVF_DETACH_SHUTDOWN. The MII layer wants to manage the lifecycle
of the PHY devices, and if a NIC driver chooses not to detach its PHYs
at shutdown, that's the driver's business.

PR kern/55121.
 1.17 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.16 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.15 18-Nov-2019  msaitoh Remove extra 10ms delay in ihphy_reset(). The delay are in if_wm.c side.
It's required for hardware full reset and it't not requred on soft reset.
When ihphy.c was added in 9 years ago, some workaround code were not in
if_wm.c yet and the initialization code was not good.
 1.14 25-Mar-2019  msaitoh branches: 1.14.4;
KNF. No functional change.
 1.13 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.12 19-Feb-2019  msaitoh Match 82580(I340) and I350.
 1.11 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.10 02-Nov-2016  msaitoh branches: 1.10.8; 1.10.14; 1.10.16;
Set mii_mpd_{oui,model,rev}.
 1.9 07-Jul-2016  msaitoh branches: 1.9.2;
KNF. Remove extra spaces. No functional change.
 1.8 16-Jun-2014  msaitoh branches: 1.8.2; 1.8.4; 1.8.8;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.7 19-Jun-2013  msaitoh branches: 1.7.6;
Use ihphy(4) for I21[78].
 1.6 11-Jun-2013  msaitoh branches: 1.6.2;
Remove duplicated code. The code to check IFF_UP and autonegotiation
is in mii_phy_tick(), too.
 1.5 09-Jun-2013  msaitoh Update link status quickly. This change is a part of FreeBSD's mii_physubr.c
r158649.
 1.4 09-Jun-2013  msaitoh Don't "return" but "break" in MII_TICK when the interface isn't doing
autonegotiaton or the link is up to update the status.
 1.3 09-Jun-2013  msaitoh atphy, ciphy, ihphy and rgephy are gigabit PHY, so not only check IFM_AUTO
for autonegotiation but also check IFM_1000_T, too.
 1.2 20-May-2011  msaitoh branches: 1.2.4; 1.2.10; 1.2.14;
82579 support.
 1.1 27-Nov-2010  christos branches: 1.1.2; 1.1.6;
PR/44080: Grégoire Sutre: Support for the i82577 ethernet PHY
 1.1.6.3 31-May-2011  rmind sync with head
 1.1.6.2 05-Mar-2011  rmind sync with head
 1.1.6.1 27-Nov-2010  rmind file ihphy.c was added on branch rmind-uvmplock on 2011-03-05 20:53:32 +0000
 1.1.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.2.14.3 03-Dec-2017  jdolecek update from HEAD
 1.2.14.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.14.1 23-Jun-2013  tls resync from head
 1.2.10.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.2.4.1 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.6.2.2 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.6.2.1 11-Jun-2013  bouyer file ihphy.c was added on branch netbsd-5 on 2013-06-19 07:50:15 +0000
 1.7.6.1 10-Aug-2014  tls Rebase.
 1.8.8.1 18-Jan-2017  skrll Sync with netbsd-5
 1.8.4.2 05-Dec-2016  skrll Sync with HEAD
 1.8.4.1 09-Jul-2016  skrll Sync with HEAD
 1.8.2.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1301):
sys/dev/mii/inphy.c: revision 1.55
sys/dev/mii/makphy.c: revision 1.42
sys/dev/mii/ikphy.c: revision 1.12
sys/dev/mii/atphy.c: revision 1.18
sys/dev/mii/ihphy.c: revision 1.10
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,rev}.
 1.9.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.10.16.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10.16.1 10-Jun-2019  christos Sync with HEAD
 1.10.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.10.8.4 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1726):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.10.8.3 20-Nov-2021  martin Pull up the following, requested by msaitoh in ticket #1707:

sys/dev/pci/if_wm.c 1.716-1.718 via patch
sys/dev/pci/if_wmreg.h 1.121
sys/dev/mii/ihphy.c 1.20

- Fix a bug that device timeout still happens when the link is down
on ICH/PCH. Fixes PR kern/56478.
- Add some sysctl info for debugging.
- ihphy(4): Don't power down the PHY when the interface goes down.
- Use macro. Fix comment.
 1.10.8.2 24-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1491):

sys/dev/mii/ihphy.c: revision 1.15

Remove extra 10ms delay in ihphy_reset(). The delay are in if_wm.c side.
It's required for hardware full reset and it's not required on soft reset.

When ihphy.c was added in 9 years ago, some workaround code were not in
if_wm.c yet and the initialization code was not good.
 1.10.8.1 01-Aug-2019  martin Pull up the following revision, requested by msaitoh in ticket #1316:

sys/dev/mii/makphy.c 1.54,1.57-1.60 via patch
sys/dev/mii/makphyvar.h 1.1-1.2
sys/dev/mii/ihphy.c 1.12,1.14 via patch

- Support Intel I21[01].
- 88E1000(S) has no page select register, so don't access it.
Note that qemu doesn't implement the register and the access fails.
- Check the result of the ESSR register access because Qemu doesn't
implement the register.
- KNF.
 1.14.4.3 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1409):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.14.4.2 20-Nov-2021  martin Pull up the following, requested by msaitoh in ticket #1373:

sys/dev/pci/if_wm.c 1.716-1.718 via patch
sys/dev/pci/if_wmreg.h 1.121
sys/dev/mii/ihphy.c 1.20

- Fix a bug that device timeout still happens when the link is down
on ICH/PCH. Fixes PR kern/56478.
- Add some sysctl info for debugging.
- ihphy(4): Don't power down the PHY when the interface goes down.
- Use macro. Fix comment.
 1.14.4.1 26-Jan-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #649):

sys/dev/mii/ihphy.c: revision 1.15

Remove extra 10ms delay in ihphy_reset(). The delay are in if_wm.c side.
It's required for hardware full reset and it't not requred on soft reset.

When ihphy.c was added in 9 years ago, some workaround code were not in
if_wm.c yet and the initialization code was not good.
 1.18.4.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.3 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.2 18-Jul-2017  msaitoh - Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access HV_SMB_ADDR
correctly.
- Enable wm_init_lcd_from_nvm() again. Tested by Thinkpad X220.
 1.1 27-Nov-2010  christos branches: 1.1.6; 1.1.20; 1.1.32; 1.1.38; 1.1.40; 1.1.56;
PR/44080: Grégoire Sutre: Support for the i82577 ethernet PHY
 1.1.56.1 01-Aug-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #173):
sys/dev/pci/if_wmreg.h: 1.99-1.103
sys/dev/pci/if_wmvar.h: 1.34-1.37
sys/dev/pci/if_wm.c: 1.510-1.537
sys/dev/mii/ihphyreg.h: 1.2
sys/dev/mii/inbmphyreg.h: 1.10
sys/dev/mii/igphy.c: 1.27
Sync wm(4) up to if_wm.c rev. 1.537:
- Set WMREG_KABGTXD not in wm_init_locked() but in wm_reset().
- If a legacy interrupt is a spurious interrupt, don't print debug
message.
- Don't print the Image Unique ID if an NVM is iNVM (i210 and I211).
- Fix a bug that a RAL was written at incorrect address when the index
number is more than 16 on 82544 and newer.
- The layout of RAL on PCH* are different from others. Fix it.
- Flush every MTA write. Same as Linux.
- Move the location of calling wm_set_filter. Same as some other OSes.
- Flush writing WMREG_CTRL in wm_gmii_mediachange().
- Make new wm_phy_post_reset() and use this function at all location
after resetting phy.
- Add I219 specific workaround for legacy interrupt. From OpenBSD.
- Move the location of calling wm_lplu_d0_disable().
- Disable D0 LPLU on 8257[12356], 82580, I350 and I21[01], too. Before
this commit, above devices and non-PCIe devices accessed wrong
register.
- Fix latency calculation in wm_platform_pm_pch_lpt().
- Set OBFF water mark and enable OBFF on PCH_LPT and newer.
- Fix a bug that wm_gmii_i82544_{read,write}reg() didn't take care of
page select. PHY access from igphy() automatically did it, but
accessing from wm(4) for workaround didn't work correctly. This
change affects 8254[17], 8257[12] ICH8, ICH9 and ICH10.
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- IF TX is not required to flush, RX is also not required to flush in
wm_flush_desc_rings(). Same as other OSes.
- Remove wrong semaphore access in wm_nvm_{read,write}_{ich8,spt} to
prevent hangup. A semaphore is get/put in wm_nvm_{read,write}.
- Move some initialization stuff in wm_attach() before wm_reset().
Some flags and callback function is required to set correctly before
wm_reset() because wm_reset() and some helper functions refer them.
- Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access
HV_SMB_ADDR correctly.
- Configure the LCD with the extended configuration region in NVM if
it's required. Tested with Thinkpad X220.
- 8257[12]: Don't directly access SPI but use EERD register.
- 82575-I354: If the size of SPI ROM >= 32K words, use direct SPI
access instead of EERD register access.
- Add wm_nvm_eec_clock_raise() and wm_nvm_eec_clock_lower() and use
them for Microwire/SPI bus control. Same as Linux and FreeBSD.
- Reduce timeout value for 80003 in wm_get_swfw_semaphore(). Same as
Linux and FreeBSD.
- Change API of kmrn_{read,write}reg() and check the return value.
- Check whether it's required to use MDIC workaround for 80003 or not
in wm_reset(). If the workaround isn't required, don't use the
workaround code in wm_gmii_i80003_{read,write}reg.
- Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers
say "In rare circumstances, the SW semaphore may already be held
unintentionally." on I21[01]. PXE boot is one of the case.
- Qemu's e1000e emulation (82574L)'s SPI has only 64 words. I've never
seen on real 82574 hardware with such small SPI ROM. Check
NVM word size before accessing higher address words to prevent
timeout.
- Check some wm_nvm_read()'s return vale.
- Use device_printf() instead of aprint_error_dev() for PHY read/write
functions because those are used not only in device attach.
- Print internal driver flags when attaching.
- Add debug printf()s.
- Rename variables.
- Add comment, update comment and remove wrong comment.
 1.1.40.1 28-Aug-2017  skrll Sync with HEAD
 1.1.38.1 11-Aug-2018  martin Pull up the following, requested by msaitoh in ticket #1628:

share/man/man4/wm.4 1.40 via patch
sys/dev/mii/ihphyreg.h 1.2
sys/dev/mii/inbmphyreg.h 1.10
sys/dev/pci/if_wm.c 1.504, 1.506, 1.510-1.535, 1.539-1.540, 1.546, 1.548, 1.551-1.552, 1.558, 1.565-1.573, 1.575, 1.579, 1.582, 1.584 via patch
sys/dev/pci/if_wmreg.h 1.99-1.103, 1.106-1.107 via patch
sys/dev/pci/if_wmvar.h 1.34-1.39 via patch
sys/dev/pci/pcidevs 1.1327 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/pci/pcireg.h patch

Sync wm(4) up to 2018/08/08 except MSI/MSI-X and NET_MPSAFE:
- remove extra "+"
- Fix a bug that non-GMII devices don't send a routing message when
the link status is changed.
- Set WMREG_KABGTXD not in wm_init_locked() but in wm_reset(). Same as
other OSes.
- If a interrupt is a spurious interrupt, don't print debug message.
- Don't print the Image Unique ID if an NVM is iNVM (i210 and I211).
- Print sc_flags with snprintb().
- Fix a bug that a RAL was written at incorrect address when the index
number is more than 16 on 82544 and newer.
- The layout of RAL on PCH* are different from others. Fix it.
- Flush every MTA write. Same as Linux.
- Move the location of calling wm_set_filter. Same as some other OSes.
- Add CSR_WRITE_FLUSH() after writing WMREG_CTRL in
wm_gmii_mediachange().
- Add missing "else" in wm_nvm_release().
- Make new wm_phy_post_reset() and use this function at all location
after resetting phy.
- Move the location of calling wm_get_hw_control. Same as Linux.
- Add I219 specific wokaround for legacy interrupt. From OpenBSD.
- Move the location of calling wm_lplu_d0_disable().
- Fix latency calculation in wm_platform_pm_pch_lpt().
- Set OBFF water mark and enable OBFF on PCH_LPT and newer.
- Disable D0 LPLU on 8257[12356], 82580, I350 and I21[01], too. Before
this commit, above devices and non-PCIe devices accessed wrong
register.
- Use device_printf() instead of aprint_error_dev() for PHY read/write
functions because those are used not only in device attach.
- Fix a bug that wm_gmii_i82544_{read,write}reg() didn't take care of
page select. PHY access from igphy() automatically did it, but
accessing from wm(4) for wrokaround didn't work correctly. This
change affects 8254[17], 8257[12] ICH8, ICH9 and ICH10.
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- Configure the LCD with the extended configuration region in NVM if
it's required.
- If TX is not required to flush, RX is also not required to flush
in wm_flush_desc_rings(). Same as other OSes.
- Remove wrong semaphore access in wm_nvm_{read,write}_{ich8,spt} to
prevent hangup. A semaphore is get/put in wm_nvm_{read,write}.
- Move some initialization stuff in wm_attach() before wm_reset(). Some
flags and callback function are required to set correctly before
wm_reset() because wm_reset() and some helper functions refer them.
- Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access
HV_SMB_ADDR correctly.
- Use new nvm.{acquire,release}() for semaphore.
- Our MII readreg/writereg API has not way to detect an error.
kmrn_{read,write}reg() are not used for MII API, so it's not required
for these functions to use the same API. So,
- Change return value as error code.
- Change register value from int to uint16_t.
- read: pass pointer for uint16_t as an argument.
- Check return value on caller side.
- Check whether it's required to use MDIC workaround for 80003 or not
in wm_reset(). If the workaround isn't required, don't use the
workaround code in wm_gmii_i80003_{read,write}reg.
- Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers
say "In rare circumstances, the SW semaphore may already be held
unintentionally on I21[01]". PXE boot is one of the case.
- Qemu's e1000e emulation (82574L)'s SPI has only 64 words. I've never
seen on real 82574 hardware with such small SPI ROM. Check
sc->sc_nvm_wordsize before accessing higher address words to prevent
timeout.
- Check some wm_nvm_read()'s return vale.
- Print NVM offset and word count when EERD polling failed.
- On I219, drop TARC0 bit 28 for DMA hang workaround (from Linux).
- 82583 supports jumbo frame. Fixes PR#52773 reported by
Shinichi Doyashiki.
- Fix typo in comment. Reported by Shinichi Doyashiki in PR#52885.
- Add ASPM workaround for 8257[1234] and 82583 to prevent device
timeout or hangup. Fixes PR#52818 reported by Shinichi Doyashiki.
- CID-1427779: Fix uninitialized variables.
- Fix a bug that wm_pll_workaround_i210() is not called when
a) Chip is I211 or b) Chip is I210 and it uses iNVM (not FLASH).
- Do wm_reset_mdicnfg_82580() on 82580 only.
- Fix FLASH access on PCH_SPT and newer. Their FLASH access should be
done by 32bit. Especially for ICH_FLASH_HSFCTL register, it's located
at 0x0006, so it must be accessed via ICH_FLASH_HSFSTS(0x0004) and
use shift or mask.
- Make wm_nvm_valid_bank_detect_ich8lan() the same as other OSes.
- If the extended configuration size in the EXTCNFSIZE register is 0,
don't continue in wm_init_lcd_from_nvm().
- Add PCH_CNP support (I219 with Intel 300 series chipset).
- Enable I219 support.
- I354 uses an external PHY, so don't use wm_set_eee_i350().
- Fix a bug that the link can't detect in link interrupt function for
non-SERDES fiber.
- Fix a bug that 82542 misunderstand fiber's signal detection.
- Add debug printf()s.
- Update comment.
- Rename functions and variables.
- Add diagnostic code.
- Sort registers.
- Lowercase hexadecimal values.
- KNF.
 1.1.32.2 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.1.32.1 27-Nov-2010  bouyer file ihphyreg.h was added on branch netbsd-5 on 2013-06-19 07:50:15 +0000
 1.1.20.1 03-Dec-2017  jdolecek update from HEAD
 1.1.6.2 05-Mar-2011  rmind sync with head
 1.1.6.1 27-Nov-2010  rmind file ihphyreg.h was added on branch rmind-uvmplock on 2011-03-05 20:53:32 +0000
 1.19 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.18 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.17 26-Nov-2019  msaitoh Fix typo in comment.
 1.16 04-Sep-2019  msaitoh KNF. No functional change.
 1.15 25-Mar-2019  msaitoh KNF. No functional change.
 1.14 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.13 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.12 02-Nov-2016  msaitoh branches: 1.12.14; 1.12.16;
Set mii_mpd_{oui,model,rev}.
 1.11 07-Jul-2016  msaitoh branches: 1.11.2;
KNF. Remove extra spaces. No functional change.
 1.10 16-Jun-2014  msaitoh branches: 1.10.2; 1.10.4; 1.10.8;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.9 19-Oct-2009  bouyer branches: 1.9.18; 1.9.22; 1.9.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.8 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.7 04-May-2008  xtraeme branches: 1.7.6; 1.7.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.6 08-Apr-2008  cegger branches: 1.6.2; 1.6.4;
use aprint_*_dev and device_xname
 1.5 29-Dec-2007  dyoung branches: 1.5.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.4 09-Dec-2007  jmcneill branches: 1.4.2;
Merge jmcneill-pm branch.
 1.3 16-Nov-2006  christos branches: 1.3.2; 1.3.6; 1.3.18; 1.3.28; 1.3.30; 1.3.36; 1.3.40; 1.3.42;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.2 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.1 21-Oct-2006  bouyer branches: 1.1.2;
Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.1.2.3 10-Dec-2006  yamt sync with head.
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 21-Oct-2006  yamt file ikphy.c was added on branch yamt-splraiseipl on 2006-10-22 06:06:12 +0000
 1.3.42.1 11-Dec-2007  yamt sync with head.
 1.3.40.1 26-Dec-2007  ad Sync with head.
 1.3.36.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.30.1 09-Jan-2008  matt sync with HEAD
 1.3.28.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.3.28.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.3.18.2 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.3.18.1 16-Nov-2006  bouyer file ikphy.c was added on branch netbsd-3 on 2007-03-31 15:25:35 +0000
 1.3.6.3 21-Jan-2008  yamt sync with head
 1.3.6.2 30-Dec-2006  yamt sync with head.
 1.3.6.1 16-Nov-2006  yamt file ikphy.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:38 +0000
 1.3.2.2 18-Nov-2006  ad Sync with head.
 1.3.2.1 16-Nov-2006  ad file ikphy.c was added on branch newlock2 on 2006-11-18 21:34:26 +0000
 1.4.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.5.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.5.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.4.3 11-Mar-2010  yamt sync with head
 1.6.4.2 04-May-2009  yamt sync with head.
 1.6.4.1 16-May-2008  yamt sync with head.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.7.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.7.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.9.36.1 10-Aug-2014  tls Rebase.
 1.9.22.2 03-Dec-2017  jdolecek update from HEAD
 1.9.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.10.8.1 18-Jan-2017  skrll Sync with netbsd-5
 1.10.4.2 05-Dec-2016  skrll Sync with HEAD
 1.10.4.1 09-Jul-2016  skrll Sync with HEAD
 1.10.2.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1301):
sys/dev/mii/inphy.c: revision 1.55
sys/dev/mii/makphy.c: revision 1.42
sys/dev/mii/ikphy.c: revision 1.12
sys/dev/mii/atphy.c: revision 1.18
sys/dev/mii/ihphy.c: revision 1.10
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,rev}.
 1.11.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.12.16.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.12.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.16.1 10-Jun-2019  christos Sync with HEAD
 1.12.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4 11-Dec-2019  msaitoh s/enalbe/enable/
 1.3 28-Oct-2016  msaitoh branches: 1.3.16;
- Use MII_ADDRMASK.
- Remove debug printf().
 1.2 29-Nov-2010  jym branches: 1.2.18; 1.2.34; 1.2.36; 1.2.40; 1.2.42;
Fix typo.
 1.1 21-Oct-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.20; 1.1.84;
Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.1.84.1 05-Mar-2011  rmind sync with head
 1.1.20.2 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.1.20.1 21-Oct-2006  bouyer file ikphyreg.h was added on branch netbsd-3 on 2007-03-31 15:25:35 +0000
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 21-Oct-2006  yamt file ikphyreg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:38 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 21-Oct-2006  ad file ikphyreg.h was added on branch newlock2 on 2006-11-18 21:34:26 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 21-Oct-2006  yamt file ikphyreg.h was added on branch yamt-splraiseipl on 2006-10-22 06:06:12 +0000
 1.2.42.1 18-Jan-2017  skrll Sync with netbsd-5
 1.2.40.1 04-Nov-2016  pgoyette Sync with HEAD
 1.2.36.1 05-Dec-2016  skrll Sync with HEAD
 1.2.34.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1302):
sys/dev/mii/igphyreg.h: revisions 1.7-1.10
sys/dev/mii/ikphyreg.h: revisions 1.3
sys/dev/mii/inbmphyreg.h: revisions 1.4-1.9
sys/dev/mii/mii.h: revisions 1.19-1.20
sys/dev/pci/if_wm.c: revisions 1.390, 1.392-1.395, 1.397, 1.419-1.425, 1.427-1.428, 1.430-1.435, 1.437-1.453 via patch
sys/dev/pci/if_wmreg.: revisions 1.89-1.93 via patch
sys/dev/pci/if_wmvar.h: revisions 1.31-1.32
Update wm(4) up to if_wm.c rev. 1.453 except MSI/MSI-X, multiqueue and
NET_MPSAFE:
- Add I219 support. It's not stable so it's disabled by default.
- wm_gate_hw_phy_config_ich8lan() is for younger than PCH2.
- Drop the host wakeup bit after resetting PHY on PCH and newer
devices.
- Increase delay while toggling LANPHYPC
- Move call of wm_reset() in wm_attach() after setting PHY and NVM
related flags because those flags are used in wm_reset().
- Use mutex for NVM access on ICH8 and newer devices. Same as FreeBSD.
- Rewrite PHY related lock stuff. Almost the same as FreeBSD.
This change will fix a bug that PHY read/write fail on some cases.
- Increase delay in wm_phy_resetisblocked(). Same as FreeBSD.
- Use semaphore in wm_hv_phy_workaround_ich8lan() and
wm_k1_gig_workaround_hv()
- Use wm_gii_mdic_readreg/writereg() in wm_access_phy_wakeup_reg_bm()
because these functions are called with taking lock.
- 82567V_3 is BME1000_E_2(bm). Tested with Advantech AIMB-212 1st
Ethernet port.
- Use wm_gmii_82544_{read,write}reg() on non-82567 ICH8, 9 and 10.
- Remove an 82578 workaround which was for PCH rev < 3. FreeBSD
removed this workaround in r228386.
- Add an 82578 workaround which is for PHY rev < 2. From FreeBSD and
Linux.
- Fix wm(4) input drop packet counter. WMREG_RNBC is incremented when
there is no available buffers in host memory. However, ethernet
controller can receive packets in such case if there is space in
phy's FIFO. That is, ethernet controller drops packet only if there
is no available buffers *and* there is no space in phy's FIFO. So,
the number of dropped packets should be added WMREG_MPC only.
- Use MII_ADDRMASK.
- Define WMPHY_I217, WMPHY_VF and WMPHY_210.
- Use BME1000_PHY_PAGE_SELECT in wm_gmii_bm_{read,write}reg(). This
change has no effect because GG82563_PHY_PAGE_SELECT and
BME1000_PHY_PAGE_SELECT have the same value.
- Fix PHY access on 82567(ICH8 or ICH10), 82574 and 82583:
- Use wm_gmii_bm_{read,write}reg() on 82574 and 82573.
- Issue page select correctly on BM PHYs.
- Fix workaround which did dummy read BM_WUC register. This code was
changed to drop BM_WUC_HOST_WU_BIT of BM_PROT_GEN_CFG register in
FreeBSD r228386. The code was added rev. 1.149, but the location was
not the best.
- wm_gmii_hv_{read/write}reg*(): USE PHY address 1 for some special
registers.
- Add check code for an 82578 workaround. Not completed yet.
- wm_release_hw_control(): Remove extra line. No any effect.
- Add "10/100" into non-gigabit devices' name.
- Call wm_enable_wakeup() in wm_detach() and wm_suspend(). Now wake on
lan works on Thinkpad X61(ICH8).
- Fix wm_access_phy_wakeup_reg_bm(). This change has no effect because
this function is used for WUC register and our driver currenlty
doesn't access to it.
- Call wm_enable_phy_wakeup() on PCH2 and newer, too. Now these devices
can do WOL. Tested with Thinkpad X220(PCH2).
- Set CTRL_MEHE correctly (PCH_{LPT,SPT} only).
- Add three workarounds for PCH_{LPT,SPT}.
- Fix a bug that 8257[56], 82580, I35[04] and I21[01] didn't use
wm_{get,release}_hw_control() correctly.
- Sync wm_smbustopci() with Linux and FreeBSD. This change effects PCH
and newer devices.
- Move the location of wm_smbustopci() call.
- Fix flag check in wm_get_wakeup()
- 8254[17]* and 8257[124] should not set WM_F_ARC_SUBSYS_VALID.
- Add missing WM_T_82541_2 and WM_T_82547_2.
- Fix WOL related setting of the WUC register for other than PCH* in
wm_enable_wakeup(). Tested with 82567V(ICH8) and 82583V.
- Use common MII_ADDRMASK.
- igphy(4): No binary change:
- s/IGPPHY/IGPHY/
- Fix the definition of PLHR_VALID_CHANNEL_*
- Fix the definition of MSE_CHANNEL_*
- Add MII_IGPHY_POWER_MGMT.
- Add some KASSERT.
- Add comment. Modify comment.
- Add debug code.
 1.2.18.1 03-Dec-2017  jdolecek update from HEAD
 1.3.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.20 16-Sep-2020  msaitoh Add a workaround for jumbo frame on PCH2 and newer. Tested by chs@.

- Add wm_lv_jumbo_workaround_ich8lan() and use it. From FreeBSD.

XXX For KUMCTRLSTA_OFFSET_HD_CTRL register modification, it's doubtful.
FreeBSD and Linux do the same thing that they set the same value on both
jumbo frame's enable case and the disable case. It seems the default value
is 0x0b0c and it's not changed on the enable case, so it might be a bug
on the enable case or the modification is not required.

- Rename I219_UNKNOWN1 to I82579_UNKNOWN1.
 1.19 11-Dec-2019  msaitoh s/enalbe/enable/
 1.18 31-Jan-2019  msaitoh branches: 1.18.4;
Add yet another PHY workaround. Disable generation of early preamble on 82577
PHY rev. 1 or 2 and 82578 PHY rev. 1.
 1.17 31-Jan-2019  msaitoh Add some workarounds which use EMI register or EEE related:
- PCH only: Add workaround for link disconnects on a busy hub in half duplex.
- PCH and PCH2 only: Set MSE higher to enable link to stay up when noise is
high.
- PCH2 only: Drop link after 5 times MSE threshold was reached.
- PCH2 only: Set EEE LPI Update Timer to 200usec.
- For PCH2 and newer: When connected at 10Mbps half-duplex, some parts are
excessively aggressive resulting in many collisions. To avoid this, increase
the IPG and reduce Rx latency in the PHY.
- For I21[789] and if EEE is enabled: Disable LPLU if both link partners
support 100BaseT EEE and 100Full is advertised on both ends of the link, and
enable Auto Enable LPI since there will be no driver to enable LPI while in
Sx.
 1.16 07-Jan-2019  msaitoh Add EEE(802.3az) support for I350, I210, I211, PCH2 and newer.

Not yet for I354(C2000). It'll be supported after implementing MI MII clause
45 register read/write API.
 1.15 20-Dec-2018  msaitoh - Don't setup WoL on non-WoL capable port.
- Setup PHY wakeup feature on PCH and newer. Tested on Thinkpad X220.
 1.14 13-Dec-2018  msaitoh Fix a wrong access to I217_PROXY_CTRL which was added in inbmphreg.h rev. 1.13
and if_wm.c rev. 1.603.
 1.13 12-Dec-2018  msaitoh Add some code for suspend/resume:
- Rename wm_smbustopci() to wm_init_phy_workarounds_pchlan(). It will also
called when resume.
- Call wm_phy_resetisblocked() after PHY reset in
wm_init_phy_workarounds_pchlan() to wait for the PHY to quiesce to an
accessible state.
- Add new wm_resume_workarounds_pchlan() function and use it in wm_resume().
This workaround is only for PCH2 and newer.
- Don't call wm_disable_aspm() neither in wm_attach() nor in wm_resume()
but in wm_reset().
- Do some initialization in wm_resume() when IFF_UP is NOT set.
- Don't continue when it failed to acquire semaphore in wm_ulp_disable().
- Add comment.
 1.12 22-Nov-2018  msaitoh - Add wm_k1_workaround_lv() from FreeBSD. It's PCH2 specifc:
Workaround to set the K1 beacon duration for 82579 parts in 10Mbps.
Disable K1 for 1000 and 100 speeds.
- Make wm_link_stall_workaround_hv() and move an 82578 specific code into it.
Don't apply the workaround if BMCR_LOOP bit is set. Same as FreeBSD.
- Add comment. Modify comment.
 1.11 02-Nov-2018  msaitoh Add workaround for DMA hang problem which result in TX device timeout on
PCH_LPT with I218. Same as FreeBSD and Linux. This woraround is only for
device ID 0x155a, 0x15a2, 0x1559 and 0x15a3. I observed this problem on my
Shuttle DS57U's I218 port six times in two months.
 1.10 13-Jul-2017  msaitoh branches: 1.10.4; 1.10.6;
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- Configure the LCD with the extended configuration region in NVM if it's
required.
- Add debug printf.
 1.9 16-Nov-2016  msaitoh branches: 1.9.8;
Sync wm_smbustopci() with Linux and FreeBSD. This change effects PCH and
newer devices.
 1.8 08-Nov-2016  msaitoh Fix wm_access_phy_wakeup_reg_bm(). This change has no effect because this
function is used for WUC register and our driver currenlty doesn't access
to it.
 1.7 28-Oct-2016  msaitoh - Use MII_ADDRMASK.
- Remove debug printf().
 1.6 19-Oct-2016  msaitoh - Drop the host wakeup bit after resetting PHY on PCH and newer devices.
- Increase delay while toggling LANPHYPC
 1.5 20-Sep-2016  msaitoh Change page of the OEM_BITS register back to 0 again. The document
(Intel Ethernet Connection I219 Datasheet) says its in page 0.
FreeBSD/Linux code access page 768. WHY?

This change will fix a bug that the LPLU function isn't disabled.

See: http://mail-index.netbsd.org/source-changes-d/2016/09/19/msg008720.html
 1.4 09-Sep-2016  msaitoh HV_OEM_BITS is not page 0 but page 768.
 1.3 20-May-2011  msaitoh branches: 1.3.14; 1.3.30; 1.3.32; 1.3.36; 1.3.38;
82579 support.
 1.2 07-Mar-2010  msaitoh branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8;
Add forgotten commit (IGP3_KMRN_DIAG_PCS_LOCK_LOSS).
 1.1 14-Jan-2010  msaitoh branches: 1.1.2; 1.1.4;
Fixes the rx stall problem on 82578 by MANY workaround code.
We need more work for 82577.
 1.1.4.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.1.2.4 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.1.2.3 19-Nov-2010  riz Pull up revisions (requested by msaitoh in ticket #1358):
sys/dev/pci/if_wm.c 1.196-1.199,1.202,1.205
sys/dev/pci/if_wmvar.h 1.9
sys/dev/pci/if_wmreg.h 1.36-1.39
sys/dev/pci/pcireg.h 1.61-1.64
sys/dev/pci/pcidevs 1.1023
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
mii/igphy.c 1.21
mii/igphyvar.h 1.1
mii/inbmphyreg.h 1.2

- Count Receive error, CRC error, Alignment error, Symbol error, Sequence
error, Carrier extension error and Receive length error into ierror.
Fixes PR#30349 reported by UMEZAWA Takeshi.
- Add support for 82575, 82576 and 82580(ER).
- Apply the patch for 82575 from Wolfgang Stukenbrock (PR#42422). We use
only one RX ring and with the legacy mode.
- Add support for 82576.
- Partial support for 82580.
- Partial support for the serdes systems.
- Add two workarounds for ICH8 with igp3.
- Workaround for 82566 Kumeran PCS lock loss.
- WOL from S5 stops working.
- (pcireg.h) Add PCIe config register definitions.
- Note that the changes to count Missed packet (rx fifo overflow) and Receive
no buffers (rx ring full) into iqdrops in rev. 1.196 of if_wm.c is not
pulled up.
 1.1.2.2 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1277):
sys/dev/pci/if_wm.c 1.184-1.192, 1.194
sys/dev/pci/if_wmreg.h 1.29-1.35
sys/dev/pci/if_wmvar.h 1.5-1.8
sys/dev/pci/pcidevs 1.1006,1.1009-1.1010, 1.1012-1.1013 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.5
sys/dev/mii/inbmphyreg.h 1.1

- Add support for i82583V.
- Add some ICH9 and ICH10 devices.
- Add support for PCH.
- Fix the bug that ICH9 can't found a PHY. Fixes PR#42237
- Fix an incorrect test for WM_F_EEPROM_INVALID since rev. 1.183. Some old
chips don't set EECD_EE_PRES.
- Fix a bug that both WM_F_EEPROM_SPI and WM_F_EEPROM_FLASH are set.
- Add a missing decrement for a timeout reported by Wolfgang Stukenbrock
in PR#42422.
- PBA setting for i82574 is not 12K but 20K.
- Enable checking the management mode on 82574.
- Fix the length of the delay() in wm_gmii_reset(). It fixed the problem that
sometimes the driver misunderstood PHYs in mii_attach(). It was reported
by MATSUI Yoshihiro. We observed it on ICH9.
- Fix the checking of jumbo frame function
- Remove the extra macro definition for the offset 0x1a in EEPROM.
- Add missing break in wm_reset()...
- Fix the offset of WMREG_PBS...
- Make wm_reset() and wm_gmii_reset() close to e1000 driver.
At least, this change make wm_attach() stable on ICH9.
- Reset GMII interface after wm_reset() in wm_init().
- Rework for assigning mii_{read,write}reg(). Use PCI product ID to identify
the PHY.
- Add code about LPLU(Low Power Link Up) function. It seems that we have to
do the same work for ICH9.
- Fixes the rx stall problem on 82578 by MANY workaround code. We need more
work for 82577.
 1.1.2.1 14-Jan-2010  sborrill file inbmphyreg.h was added on branch netbsd-5 on 2010-01-27 22:27:41 +0000
 1.2.8.1 06-Jun-2011  jruoho Sync with HEAD.
 1.2.6.2 21-Apr-2010  matt sync to netbsd-5
 1.2.6.1 07-Mar-2010  matt file inbmphyreg.h was added on branch matt-nb5-mips64 on 2010-04-21 00:27:39 +0000
 1.2.4.1 31-May-2011  rmind sync with head
 1.2.2.2 11-Mar-2010  yamt sync with head
 1.2.2.1 07-Mar-2010  yamt file inbmphyreg.h was added on branch yamt-nfs-mp on 2010-03-11 15:03:41 +0000
 1.3.38.1 18-Jan-2017  skrll Sync with netbsd-5
 1.3.36.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.3.36.1 04-Nov-2016  pgoyette Sync with HEAD
 1.3.32.3 28-Aug-2017  skrll Sync with HEAD
 1.3.32.2 05-Dec-2016  skrll Sync with HEAD
 1.3.32.1 05-Oct-2016  skrll Sync with HEAD
 1.3.30.3 09-Nov-2018  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1648):
sys/dev/mii/inbmphyreg.h 1.11
sys/dev/pci/if_wm.c 1.586-1.588, 1.590-1.596 via patch
sys/dev/pci/if_wmreg.h 1.108

- rename tu event counter to txunderrun.
- Try m_defrag() to reduce the number of DMA segment if bus_dmamap_load_mbuf()
returned EFBIG. When m_defrag() is called, txqNNdefrag event counter is
incremented. If the 2nd try of bus_dmamap_load_mbuf() failed, txqNNtoomanyseg
event counter is incremented.
- Reduce the max number of DMA segments from 256 to 64 (it's the same value
as other BSD's (EM_MAX_SCATTER) and more than before if_wm.c rev. 1.75's
value (40)) because we do m_defrag() now.
- 82574 and newer document says the status field has neither EC
(Excessive Collision) bit nor LC (Late Collision) bit (reserved), so
don't check the bit.
- Add workaround for DMA hang problem which result in TX device timeout
on PCH_LPT with I218. Same as FreeBSD and Linux. This workaround is
only for device ID 0x155a, 0x15a2, 0x1559 and 0x15a3.
- Fix a PCH2 specific bug that wrong PHY register value can be read
when boot. Same as FreeBSD and Linux.
- After writing MDIC register, don't read quickly the same register but
do delay(50). Same as other OSes.
- Add missing wm_gate_hw_phy_config_ich8lan(false) in
wm_phy_post_reset() on PCH2. wm_gate_hw_phy_config_ich8lan(true) is
called in wm_reset(), so wm_gate_hw_phy_config_ich8lan(false) should
be called after reset in wm_phy_post_reset().
- On PCH2, set the phy config counter to 50msec after (PHY) reset.
- KNF & Use macro.
 1.3.30.2 11-Aug-2018  martin Pull up the following, requested by msaitoh in ticket #1628:

share/man/man4/wm.4 1.40 via patch
sys/dev/mii/ihphyreg.h 1.2
sys/dev/mii/inbmphyreg.h 1.10
sys/dev/pci/if_wm.c 1.504, 1.506, 1.510-1.535, 1.539-1.540, 1.546, 1.548, 1.551-1.552, 1.558, 1.565-1.573, 1.575, 1.579, 1.582, 1.584 via patch
sys/dev/pci/if_wmreg.h 1.99-1.103, 1.106-1.107 via patch
sys/dev/pci/if_wmvar.h 1.34-1.39 via patch
sys/dev/pci/pcidevs 1.1327 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/pci/pcireg.h patch

Sync wm(4) up to 2018/08/08 except MSI/MSI-X and NET_MPSAFE:
- remove extra "+"
- Fix a bug that non-GMII devices don't send a routing message when
the link status is changed.
- Set WMREG_KABGTXD not in wm_init_locked() but in wm_reset(). Same as
other OSes.
- If a interrupt is a spurious interrupt, don't print debug message.
- Don't print the Image Unique ID if an NVM is iNVM (i210 and I211).
- Print sc_flags with snprintb().
- Fix a bug that a RAL was written at incorrect address when the index
number is more than 16 on 82544 and newer.
- The layout of RAL on PCH* are different from others. Fix it.
- Flush every MTA write. Same as Linux.
- Move the location of calling wm_set_filter. Same as some other OSes.
- Add CSR_WRITE_FLUSH() after writing WMREG_CTRL in
wm_gmii_mediachange().
- Add missing "else" in wm_nvm_release().
- Make new wm_phy_post_reset() and use this function at all location
after resetting phy.
- Move the location of calling wm_get_hw_control. Same as Linux.
- Add I219 specific wokaround for legacy interrupt. From OpenBSD.
- Move the location of calling wm_lplu_d0_disable().
- Fix latency calculation in wm_platform_pm_pch_lpt().
- Set OBFF water mark and enable OBFF on PCH_LPT and newer.
- Disable D0 LPLU on 8257[12356], 82580, I350 and I21[01], too. Before
this commit, above devices and non-PCIe devices accessed wrong
register.
- Use device_printf() instead of aprint_error_dev() for PHY read/write
functions because those are used not only in device attach.
- Fix a bug that wm_gmii_i82544_{read,write}reg() didn't take care of
page select. PHY access from igphy() automatically did it, but
accessing from wm(4) for wrokaround didn't work correctly. This
change affects 8254[17], 8257[12] ICH8, ICH9 and ICH10.
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- Configure the LCD with the extended configuration region in NVM if
it's required.
- If TX is not required to flush, RX is also not required to flush
in wm_flush_desc_rings(). Same as other OSes.
- Remove wrong semaphore access in wm_nvm_{read,write}_{ich8,spt} to
prevent hangup. A semaphore is get/put in wm_nvm_{read,write}.
- Move some initialization stuff in wm_attach() before wm_reset(). Some
flags and callback function are required to set correctly before
wm_reset() because wm_reset() and some helper functions refer them.
- Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access
HV_SMB_ADDR correctly.
- Use new nvm.{acquire,release}() for semaphore.
- Our MII readreg/writereg API has not way to detect an error.
kmrn_{read,write}reg() are not used for MII API, so it's not required
for these functions to use the same API. So,
- Change return value as error code.
- Change register value from int to uint16_t.
- read: pass pointer for uint16_t as an argument.
- Check return value on caller side.
- Check whether it's required to use MDIC workaround for 80003 or not
in wm_reset(). If the workaround isn't required, don't use the
workaround code in wm_gmii_i80003_{read,write}reg.
- Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers
say "In rare circumstances, the SW semaphore may already be held
unintentionally on I21[01]". PXE boot is one of the case.
- Qemu's e1000e emulation (82574L)'s SPI has only 64 words. I've never
seen on real 82574 hardware with such small SPI ROM. Check
sc->sc_nvm_wordsize before accessing higher address words to prevent
timeout.
- Check some wm_nvm_read()'s return vale.
- Print NVM offset and word count when EERD polling failed.
- On I219, drop TARC0 bit 28 for DMA hang workaround (from Linux).
- 82583 supports jumbo frame. Fixes PR#52773 reported by
Shinichi Doyashiki.
- Fix typo in comment. Reported by Shinichi Doyashiki in PR#52885.
- Add ASPM workaround for 8257[1234] and 82583 to prevent device
timeout or hangup. Fixes PR#52818 reported by Shinichi Doyashiki.
- CID-1427779: Fix uninitialized variables.
- Fix a bug that wm_pll_workaround_i210() is not called when
a) Chip is I211 or b) Chip is I210 and it uses iNVM (not FLASH).
- Do wm_reset_mdicnfg_82580() on 82580 only.
- Fix FLASH access on PCH_SPT and newer. Their FLASH access should be
done by 32bit. Especially for ICH_FLASH_HSFCTL register, it's located
at 0x0006, so it must be accessed via ICH_FLASH_HSFSTS(0x0004) and
use shift or mask.
- Make wm_nvm_valid_bank_detect_ich8lan() the same as other OSes.
- If the extended configuration size in the EXTCNFSIZE register is 0,
don't continue in wm_init_lcd_from_nvm().
- Add PCH_CNP support (I219 with Intel 300 series chipset).
- Enable I219 support.
- I354 uses an external PHY, so don't use wm_set_eee_i350().
- Fix a bug that the link can't detect in link interrupt function for
non-SERDES fiber.
- Fix a bug that 82542 misunderstand fiber's signal detection.
- Add debug printf()s.
- Update comment.
- Rename functions and variables.
- Add diagnostic code.
- Sort registers.
- Lowercase hexadecimal values.
- KNF.
 1.3.30.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1302):
sys/dev/mii/igphyreg.h: revisions 1.7-1.10
sys/dev/mii/ikphyreg.h: revisions 1.3
sys/dev/mii/inbmphyreg.h: revisions 1.4-1.9
sys/dev/mii/mii.h: revisions 1.19-1.20
sys/dev/pci/if_wm.c: revisions 1.390, 1.392-1.395, 1.397, 1.419-1.425, 1.427-1.428, 1.430-1.435, 1.437-1.453 via patch
sys/dev/pci/if_wmreg.: revisions 1.89-1.93 via patch
sys/dev/pci/if_wmvar.h: revisions 1.31-1.32
Update wm(4) up to if_wm.c rev. 1.453 except MSI/MSI-X, multiqueue and
NET_MPSAFE:
- Add I219 support. It's not stable so it's disabled by default.
- wm_gate_hw_phy_config_ich8lan() is for younger than PCH2.
- Drop the host wakeup bit after resetting PHY on PCH and newer
devices.
- Increase delay while toggling LANPHYPC
- Move call of wm_reset() in wm_attach() after setting PHY and NVM
related flags because those flags are used in wm_reset().
- Use mutex for NVM access on ICH8 and newer devices. Same as FreeBSD.
- Rewrite PHY related lock stuff. Almost the same as FreeBSD.
This change will fix a bug that PHY read/write fail on some cases.
- Increase delay in wm_phy_resetisblocked(). Same as FreeBSD.
- Use semaphore in wm_hv_phy_workaround_ich8lan() and
wm_k1_gig_workaround_hv()
- Use wm_gii_mdic_readreg/writereg() in wm_access_phy_wakeup_reg_bm()
because these functions are called with taking lock.
- 82567V_3 is BME1000_E_2(bm). Tested with Advantech AIMB-212 1st
Ethernet port.
- Use wm_gmii_82544_{read,write}reg() on non-82567 ICH8, 9 and 10.
- Remove an 82578 workaround which was for PCH rev < 3. FreeBSD
removed this workaround in r228386.
- Add an 82578 workaround which is for PHY rev < 2. From FreeBSD and
Linux.
- Fix wm(4) input drop packet counter. WMREG_RNBC is incremented when
there is no available buffers in host memory. However, ethernet
controller can receive packets in such case if there is space in
phy's FIFO. That is, ethernet controller drops packet only if there
is no available buffers *and* there is no space in phy's FIFO. So,
the number of dropped packets should be added WMREG_MPC only.
- Use MII_ADDRMASK.
- Define WMPHY_I217, WMPHY_VF and WMPHY_210.
- Use BME1000_PHY_PAGE_SELECT in wm_gmii_bm_{read,write}reg(). This
change has no effect because GG82563_PHY_PAGE_SELECT and
BME1000_PHY_PAGE_SELECT have the same value.
- Fix PHY access on 82567(ICH8 or ICH10), 82574 and 82583:
- Use wm_gmii_bm_{read,write}reg() on 82574 and 82573.
- Issue page select correctly on BM PHYs.
- Fix workaround which did dummy read BM_WUC register. This code was
changed to drop BM_WUC_HOST_WU_BIT of BM_PROT_GEN_CFG register in
FreeBSD r228386. The code was added rev. 1.149, but the location was
not the best.
- wm_gmii_hv_{read/write}reg*(): USE PHY address 1 for some special
registers.
- Add check code for an 82578 workaround. Not completed yet.
- wm_release_hw_control(): Remove extra line. No any effect.
- Add "10/100" into non-gigabit devices' name.
- Call wm_enable_wakeup() in wm_detach() and wm_suspend(). Now wake on
lan works on Thinkpad X61(ICH8).
- Fix wm_access_phy_wakeup_reg_bm(). This change has no effect because
this function is used for WUC register and our driver currenlty
doesn't access to it.
- Call wm_enable_phy_wakeup() on PCH2 and newer, too. Now these devices
can do WOL. Tested with Thinkpad X220(PCH2).
- Set CTRL_MEHE correctly (PCH_{LPT,SPT} only).
- Add three workarounds for PCH_{LPT,SPT}.
- Fix a bug that 8257[56], 82580, I35[04] and I21[01] didn't use
wm_{get,release}_hw_control() correctly.
- Sync wm_smbustopci() with Linux and FreeBSD. This change effects PCH
and newer devices.
- Move the location of wm_smbustopci() call.
- Fix flag check in wm_get_wakeup()
- 8254[17]* and 8257[124] should not set WM_F_ARC_SUBSYS_VALID.
- Add missing WM_T_82541_2 and WM_T_82547_2.
- Fix WOL related setting of the WUC register for other than PCH* in
wm_enable_wakeup(). Tested with 82567V(ICH8) and 82583V.
- Use common MII_ADDRMASK.
- igphy(4): No binary change:
- s/IGPPHY/IGPHY/
- Fix the definition of PLHR_VALID_CHANNEL_*
- Fix the definition of MSE_CHANNEL_*
- Add MII_IGPHY_POWER_MGMT.
- Add some KASSERT.
- Add comment. Modify comment.
- Add debug code.
 1.3.14.1 03-Dec-2017  jdolecek update from HEAD
 1.9.8.4 31-Jan-2019  martin Pull up the following, requested by msaitoh in ticket #1179:

sys/dev/pci/if_wm.c 1.603-1.605,1.607-1.611,
1.613,1.615,1.618-1.620
via patch
sys/dev/pci/if_wmreg.h 1.110-1.111
sys/dev/pci/if_wmvar.h 1.40-1.42
sys/dev/mii/inbmphyreg.h 1.13-1.15

- Add some code for suspend/resume:
- Rename wm_smbustopci() to wm_init_phy_workarounds_pchlan(). It will
also called when resume.
- Call wm_phy_resetisblocked() after PHY reset in
wm_init_phy_workarounds_pchlan() to wait for the PHY to quiesce to
an accessible state.
- Add new wm_resume_workarounds_pchlan() function and use it in
wm_resume(). This workaround is only for PCH2 and newer.
- Don't call wm_disable_aspm() neither in wm_attach() nor in
wm_resume() but in wm_reset().
- Do some initialization in wm_resume() when IFF_UP is NOT set.
- Don't continue when it failed to acquire semaphore in
wm_ulp_disable().
- Print CLSEM workaround bit correctly.
- Fix availability detection of WoL on some chips.
- Print the WUS (WakeUp Status) register bits when resume.
- Don't setup WoL on non-WoL capable port.
- Setup PHY wakeup feature on PCH and newer. Tested on Thinkpad X220.
- Remove an extra register read in
wm_kmrn_lock_loss_workaround_ich8lan().
- Don't leave the MDICNFG register modified when the Power Management
capability offset can't get.
- Reduce indent level of wm_linkintr_gmii(). No functional change.
- 80003's SERDES is not the same as 82575's but the same as legacy
devices. Use the old methods on 80003.
- Use __nothing for null DPRINTF().
- Rename functions. Add comment.
 1.9.8.3 04-Dec-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #1117):

sys/dev/pci/if_wmreg.h: revision 1.109
sys/dev/pci/if_wm.c: revision 1.597
sys/dev/pci/if_wm.c: revision 1.598
sys/dev/mii/inbmphyreg.h: revision 1.12
sys/dev/pci/if_wm.c: revision 1.600
sys/dev/pci/if_wm.c: revision 1.601
sys/dev/pci/if_wm.c: revision 1.602

- Add new wm_gmii_{hv,i82544}_{read,write}reg_locked() and use them in
wm_gmii_{hv,i82544}_{read,write}reg(). *_locked() functions are not
mii(4) API functions, so it's not required to keep the mii API. Change
the PHY register type from int to uint16_t. It also change the usage of
return value. It returns zero on success and non-zero on error.
- Check the return value of *_locked() function and treat it.
- Use *writereg_locked() function to reduce race condition in
wm_init_lcd_from_nvm().
- Add comment.
- Control TX/RX descriptor snooping control bits on ICH8 and newer.
Only on ICH8, No-snoop bits are opposite polarity. On my Thinkpad X61,
the default value of this bits are all zero, so this commit changes
the snoop function enable on the machine. I tested with some other
PCH machines and those bits are all zero (enable snoop by default),
so this commit won't affect to some machines.
- Disable relax ordering on 82546GB(Device ID 0x1099 and 0x10b5) or >= ICH8.
Same as other OSes.
- Add wm_oem_bits_config_ich8lan() to control LPLU and GbE setting base on
the NVM's info.
- Modify wm_enable_wakeup() to reduce difference against FreeBSD and Linux.
This modification affects to ICH8 and newer devices. I217 Rapid Start
Technology support have not written yet (it's TODO).
- Add wm_k1_workaround_lv() from FreeBSD. It's PCH2 specific:
Workaround to set the K1 beacon duration for 82579 parts in 10Mbps.
Disable K1 for 1000 and 100 speeds.
- Make wm_link_stall_workaround_hv() and move an 82578 specific code into it.
Don't apply the workaround if BMCR_LOOP bit is set. Same as FreeBSD.
- Add comment. Modify comment.
Fix comment. No functional change.
 1.9.8.2 08-Nov-2018  martin Pull up the following, requested by msaitoh in tickt #1085:

sys/dev/mii/inbmphyreg.h 1.11
sys/dev/pci/if_wmreg.h 1.108
sys/dev/pci/if_wm.c 1.590-1.596 via patch

- 82574 and newer document says the status field has neither EC
(Excessive Collision) bit nor LC (Late Collision) bit (reserved), so
don't check the bit.
- Add workaround for DMA hang problem which result in TX device timeout
on PCH_LPT with I218. Same as FreeBSD and Linux. This workaround is
only for device ID 0x155a, 0x15a2, 0x1559 and 0x15a3.
- Fix a PCH2 specific bug that wrong PHY register value can be read
when boot. Same as FreeBSD and Linux.
- After writing MDIC register, don't read quickly the same register but
do delay(50). Same as other OSes.
- Add missing wm_gate_hw_phy_config_ich8lan(false) in
wm_phy_post_reset() on PCH2. wm_gate_hw_phy_config_ich8lan(true) is
called in wm_reset(), so wm_gate_hw_phy_config_ich8lan(false) should
be called after reset in wm_phy_post_reset().
- On PCH2, set the phy config counter to 50msec after (PHY) reset.
- KNF & Use macro.
 1.9.8.1 01-Aug-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #173):
sys/dev/pci/if_wmreg.h: 1.99-1.103
sys/dev/pci/if_wmvar.h: 1.34-1.37
sys/dev/pci/if_wm.c: 1.510-1.537
sys/dev/mii/ihphyreg.h: 1.2
sys/dev/mii/inbmphyreg.h: 1.10
sys/dev/mii/igphy.c: 1.27
Sync wm(4) up to if_wm.c rev. 1.537:
- Set WMREG_KABGTXD not in wm_init_locked() but in wm_reset().
- If a legacy interrupt is a spurious interrupt, don't print debug
message.
- Don't print the Image Unique ID if an NVM is iNVM (i210 and I211).
- Fix a bug that a RAL was written at incorrect address when the index
number is more than 16 on 82544 and newer.
- The layout of RAL on PCH* are different from others. Fix it.
- Flush every MTA write. Same as Linux.
- Move the location of calling wm_set_filter. Same as some other OSes.
- Flush writing WMREG_CTRL in wm_gmii_mediachange().
- Make new wm_phy_post_reset() and use this function at all location
after resetting phy.
- Add I219 specific workaround for legacy interrupt. From OpenBSD.
- Move the location of calling wm_lplu_d0_disable().
- Disable D0 LPLU on 8257[12356], 82580, I350 and I21[01], too. Before
this commit, above devices and non-PCIe devices accessed wrong
register.
- Fix latency calculation in wm_platform_pm_pch_lpt().
- Set OBFF water mark and enable OBFF on PCH_LPT and newer.
- Fix a bug that wm_gmii_i82544_{read,write}reg() didn't take care of
page select. PHY access from igphy() automatically did it, but
accessing from wm(4) for workaround didn't work correctly. This
change affects 8254[17], 8257[12] ICH8, ICH9 and ICH10.
- Call wm_kmrn_lock_loss_workaround_ich8lan() before any PHY access in
wm_linkintr_gmii().
- Register access in wm_kmrn_lock_loss_workaround_ich8lan() now works
correctly. Enable this function.
- IF TX is not required to flush, RX is also not required to flush in
wm_flush_desc_rings(). Same as other OSes.
- Remove wrong semaphore access in wm_nvm_{read,write}_{ich8,spt} to
prevent hangup. A semaphore is get/put in wm_nvm_{read,write}.
- Move some initialization stuff in wm_attach() before wm_reset().
Some flags and callback function is required to set correctly before
wm_reset() because wm_reset() and some helper functions refer them.
- Add wm_write_smbus_addr() to set SMBus address by software.
- Modify wm_gmii_hv_{read,write}reg_locked() to make them access
HV_SMB_ADDR correctly.
- Configure the LCD with the extended configuration region in NVM if
it's required. Tested with Thinkpad X220.
- 8257[12]: Don't directly access SPI but use EERD register.
- 82575-I354: If the size of SPI ROM >= 32K words, use direct SPI
access instead of EERD register access.
- Add wm_nvm_eec_clock_raise() and wm_nvm_eec_clock_lower() and use
them for Microwire/SPI bus control. Same as Linux and FreeBSD.
- Reduce timeout value for 80003 in wm_get_swfw_semaphore(). Same as
Linux and FreeBSD.
- Change API of kmrn_{read,write}reg() and check the return value.
- Check whether it's required to use MDIC workaround for 80003 or not
in wm_reset(). If the workaround isn't required, don't use the
workaround code in wm_gmii_i80003_{read,write}reg.
- Add WM_F_WA_I210_CLSEM flag for a workaround. FreeBSD/Linux drivers
say "In rare circumstances, the SW semaphore may already be held
unintentionally." on I21[01]. PXE boot is one of the case.
- Qemu's e1000e emulation (82574L)'s SPI has only 64 words. I've never
seen on real 82574 hardware with such small SPI ROM. Check
NVM word size before accessing higher address words to prevent
timeout.
- Check some wm_nvm_read()'s return vale.
- Use device_printf() instead of aprint_error_dev() for PHY read/write
functions because those are used not only in device attach.
- Print internal driver flags when attaching.
- Add debug printf()s.
- Rename variables.
- Add comment, update comment and remove wrong comment.
 1.10.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10.6.1 10-Jun-2019  christos Sync with HEAD
 1.10.4.3 18-Jan-2019  pgoyette Synch with HEAD
 1.10.4.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.10.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.18.4.1 23-Sep-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1093):

sys/dev/pci/if_wmreg.h: revision 1.120
sys/dev/pci/if_wmvar.h: revision 1.46
sys/dev/pci/if_wm.c: revision 1.686
sys/dev/pci/if_wm.c: revision 1.687
sys/dev/mii/inbmphyreg.h: revision 1.20
sys/dev/pci/if_wm.c: revision 1.688
sys/dev/pci/if_wm.c: revision 1.689

s/ressource/resource/. Found by knakahara.

Add new flag named WM_F_CRC_STRIP and use it. No functional change.

This change also sets the RCTL_SECRC bit on I211 but it doesn't change
the behavior because I211 always strips CRC like I35[04] and I210.

Add a workaround for jumbo frame on PCH2 and newer. Tested by chs@.

- Add wm_lv_jumbo_workaround_ich8lan() and use it. From FreeBSD.
XXX For KUMCTRLSTA_OFFSET_HD_CTRL register modification, it's doubtful.
FreeBSD and Linux do the same thing that they set the same value on both
jumbo frame's enable case and the disable case. It seems the default value
is 0x0b0c and it's not changed on the enable case, so it might be a bug
on the enable case or the modification is not required.
- Rename I219_UNKNOWN1 to I82579_UNKNOWN1.
Use 12K for packet buffer for jumbo frame on PCH2 and newer.

XXX Note that Linux Use 14K.
 1.60 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.59 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.58 25-Mar-2019  msaitoh KNF. No functional change.
 1.57 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.56 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.55 08-Nov-2016  msaitoh branches: 1.55.14; 1.55.16;
Set mii_mpd_{oui,model,rev}.
 1.54 07-Jul-2016  msaitoh branches: 1.54.2;
KNF. Remove extra spaces. No functional change.
 1.53 16-Jun-2014  msaitoh branches: 1.53.2; 1.53.4; 1.53.8;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.52 19-Oct-2009  bouyer branches: 1.52.18; 1.52.22; 1.52.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.51 16-Feb-2009  cegger fix media priorities:

IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:

1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T

Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.

Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html

got no comments, no objections.
 1.50 18-Jan-2009  mrg branches: 1.50.2;
The PCI revision numbers are unique to a PCI vendor/product
ID pair. Misuse of the revision numbers was causing some of the chip
features to be disabled on some integrated Intel chips. So, move the
determination of the features into the bus frontend, where the
vendor/product ID is known. (Note: sc_rev should be removed. The
microcode patch stuff is also busted and needs to be fixed.) Also,
poll the actual flow control status in inphy, rather than making
assumptions.

contributed anonymously.
 1.49 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.48 04-May-2008  xtraeme branches: 1.48.6; 1.48.8; 1.48.10; 1.48.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.47 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.46 08-Apr-2008  cegger branches: 1.46.2; 1.46.4;
use aprint_*_dev and device_xname
 1.45 29-Dec-2007  dyoung branches: 1.45.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.44 09-Dec-2007  jmcneill branches: 1.44.2;
Merge jmcneill-pm branch.
 1.43 16-Nov-2006  christos branches: 1.43.22; 1.43.24; 1.43.30; 1.43.34; 1.43.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.42 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.41 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.40 27-Sep-2006  cube Add support for 82562G.
 1.39 29-Mar-2006  thorpej branches: 1.39.8; 1.39.10;
Use device_private().
 1.38 20-Feb-2006  thorpej branches: 1.38.2; 1.38.4; 1.38.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.37 11-Dec-2005  christos branches: 1.37.2; 1.37.4; 1.37.6;
merge ktrace-lwp.
 1.36 23-Aug-2004  thorpej branches: 1.36.12;
Make use of static.
 1.35 29-Apr-2003  thorpej branches: 1.35.2;
Use aprint*().
 1.34 27-Mar-2003  drochner Before checking the (Intel specific) SCR_T4 register, make
sure the chip implements 100T4 (in BMSR).
The 82562 (which doesn't implement 100T4) has the SCR_T4 bit
(always?) set, which led to wrong media status reports.
approved by thorpej
 1.33 07-Mar-2003  matt Fix C&P tpyo.
 1.32 06-Mar-2003  matt Make the intel phy match the i82562 phys.
 1.31 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.30 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.29 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.28 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.27 25-Mar-2002  thorpej branches: 1.27.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.26 13-Nov-2001  lukem add RCSID
 1.25 25-Aug-2001  thorpej ANSI'ify.
 1.24 06-Aug-2001  enami Advertize pause capability (802.3x flow control) to peer.
 1.23 02-Jun-2001  thorpej branches: 1.23.2;
Make PHY matching all table-driven.
 1.22 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.21 28-Mar-2001  drochner update for miidevs changes
 1.20 04-Jul-2000  thorpej branches: 1.20.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.19 06-Mar-2000  thorpej branches: 1.19.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.18 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.17 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.16 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.15 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.14 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.13 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.12 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.11 23-Apr-1999  thorpej branches: 1.11.2; 1.11.4; 1.11.8;
Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.10 05-Nov-1998  thorpej branches: 1.10.6;
Common code for media-from-bmcr.
 1.9 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.8 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.7 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.6 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.5 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.4 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.3 12-Aug-1998  thorpej If autonegotiation is enabled in the BMSR, and the BMCR doens't claim
that it has completed, report "none" as the active media type.
 1.2 12-Aug-1998  thorpej Ugh, don't print out "autonegotiation failed to complete" if it did.
We get these once a second if we're in auto mode, the interface is up,
and there's no carrier.
 1.1 11-Aug-1998  thorpej Device driver for the Intel i82555 PHY.
 1.10.6.1 23-Apr-1999  perry branches: 1.10.6.1.2;
pullup 1.10->1.11 (thorpej): Fix PR7361
 1.10.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.11.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11.4.1 15-Nov-1999  fvdl Sync with -current
 1.11.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.11.2.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.19.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.20.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.20.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.20.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.20.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.20.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.20.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.20.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.20.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.23.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.23.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.23.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.23.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.27.2.1 15-Jul-2002  gehenna catch up with -current.
 1.35.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.35.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.35.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.36.12.3 21-Jan-2008  yamt sync with head
 1.36.12.2 30-Dec-2006  yamt sync with head.
 1.36.12.1 21-Jun-2006  yamt sync with head.
 1.37.6.1 22-Apr-2006  simonb Sync with head.
 1.37.4.1 09-Sep-2006  rpaulo sync with head
 1.37.2.1 01-Mar-2006  yamt sync with head.
 1.38.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.38.4.1 19-Apr-2006  elad sync with head.
 1.38.2.1 01-Apr-2006  yamt sync with head.
 1.39.10.2 10-Dec-2006  yamt sync with head.
 1.39.10.1 22-Oct-2006  yamt sync with head
 1.39.8.1 18-Nov-2006  ad Sync with head.
 1.43.36.1 11-Dec-2007  yamt sync with head.
 1.43.34.1 26-Dec-2007  ad Sync with head.
 1.43.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.43.24.1 09-Jan-2008  matt sync with HEAD
 1.43.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.43.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.44.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.45.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.45.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.46.4.3 11-Mar-2010  yamt sync with head
 1.46.4.2 04-May-2009  yamt sync with head.
 1.46.4.1 16-May-2008  yamt sync with head.
 1.46.2.1 18-May-2008  yamt sync with head.
 1.48.14.1 21-Apr-2010  matt sync to netbsd-5
 1.48.10.1 01-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #474):
sys/dev/mii/inphy.c: revision 1.51
sys/dev/mii/iophy.c: revision 1.35
sys/dev/mii/nsphy.c: revision 1.56
sys/dev/mii/rlphy.c: revision 1.25
sys/dev/mii/ukphy_subr.c: revision 1.11
sys/dev/pci/if_txp.c: revision 1.28
fix media priorities:
IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:
1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T
Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.
Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html
got no comments, no objections.
 1.48.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.48.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.48.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.50.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.52.36.1 10-Aug-2014  tls Rebase.
 1.52.22.2 03-Dec-2017  jdolecek update from HEAD
 1.52.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.52.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.53.8.1 18-Jan-2017  skrll Sync with netbsd-5
 1.53.4.2 05-Dec-2016  skrll Sync with HEAD
 1.53.4.1 09-Jul-2016  skrll Sync with HEAD
 1.53.2.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1301):
sys/dev/mii/inphy.c: revision 1.55
sys/dev/mii/makphy.c: revision 1.42
sys/dev/mii/ikphy.c: revision 1.12
sys/dev/mii/atphy.c: revision 1.18
sys/dev/mii/ihphy.c: revision 1.10
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,rev}.
 1.54.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.55.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.55.16.1 10-Jun-2019  christos Sync with HEAD
 1.55.14.1 26-Jan-2019  pgoyette Sync with HEAD
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 20-Jun-1999  thorpej branches: 1.2.36;
SCTRL2 register number wrong. PR #7756, Johan Danielsson.
 1.1 11-Aug-1998  thorpej branches: 1.1.6; 1.1.8; 1.1.10;
Device driver for the Intel i82555 PHY.
 1.1.10.1 30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.1.8.1 01-Jul-1999  thorpej Sync w/ -current.
 1.1.6.1 20-Jun-1999  perry pullup 1.1->1.2 (thorpej): Correct a register number.
 1.2.36.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.36.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.36.1 03-Aug-2004  skrll Sync with HEAD
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.43 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.42 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.41 25-Mar-2019  msaitoh KNF. No functional change.
 1.40 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.39 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.38 07-Jul-2016  msaitoh branches: 1.38.16; 1.38.18;
KNF. Remove extra spaces. No functional change.
 1.37 16-Jun-2014  msaitoh branches: 1.37.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.36 19-Oct-2009  bouyer branches: 1.36.18; 1.36.22; 1.36.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.35 16-Feb-2009  cegger fix media priorities:

IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:

1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T

Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.

Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html

got no comments, no objections.
 1.34 17-Nov-2008  dyoung branches: 1.34.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.33 04-May-2008  xtraeme branches: 1.33.6; 1.33.8; 1.33.10; 1.33.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.32 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.31 08-Apr-2008  cegger branches: 1.31.2; 1.31.4;
use aprint_*_dev and device_xname
 1.30 29-Dec-2007  dyoung branches: 1.30.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.29 09-Dec-2007  jmcneill branches: 1.29.2;
Merge jmcneill-pm branch.
 1.28 16-Nov-2006  christos branches: 1.28.22; 1.28.24; 1.28.30; 1.28.34; 1.28.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.27 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.26 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.25 29-Mar-2006  thorpej branches: 1.25.8; 1.25.10;
Use device_private().
 1.24 20-Feb-2006  thorpej branches: 1.24.2; 1.24.4; 1.24.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.23 11-Dec-2005  christos branches: 1.23.2; 1.23.4; 1.23.6;
merge ktrace-lwp.
 1.22 23-Aug-2004  thorpej branches: 1.22.12;
Make use of static.
 1.21 29-Apr-2003  thorpej branches: 1.21.2;
Use aprint*().
 1.20 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.19 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.18 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.17 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.16 25-Mar-2002  thorpej branches: 1.16.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.15 13-Nov-2001  lukem add RCSID
 1.14 25-Aug-2001  thorpej ANSI'ify.
 1.13 02-Jun-2001  thorpej branches: 1.13.2;
Make PHY matching all table-driven.
 1.12 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.11 28-Mar-2001  drochner update for miidevs changes
 1.10 04-Jul-2000  thorpej branches: 1.10.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.9 06-Mar-2000  thorpej branches: 1.9.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.8 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.7 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.6 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.5 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.4 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.3 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.2 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.1 05-Sep-1999  soren branches: 1.1.2; 1.1.4; 1.1.8;
Add PHY driver the the Intel 82553 found on some fxp's.
Some variants of this chip need a little extra MII fix before
being usable, so this is not yet put into GENERIC's.
 1.1.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.4.1 15-Nov-1999  fvdl Sync with -current
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.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.9.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.10.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.10.2.6 01-Aug-2002  nathanw Catch up to -current.
 1.10.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.10.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.10.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.10.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.13.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.13.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.13.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.13.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.13.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.16.2.1 15-Jul-2002  gehenna catch up with -current.
 1.21.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.21.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.21.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.22.12.3 21-Jan-2008  yamt sync with head
 1.22.12.2 30-Dec-2006  yamt sync with head.
 1.22.12.1 21-Jun-2006  yamt sync with head.
 1.23.6.1 22-Apr-2006  simonb Sync with head.
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.23.2.1 01-Mar-2006  yamt sync with head.
 1.24.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.24.4.1 19-Apr-2006  elad sync with head.
 1.24.2.1 01-Apr-2006  yamt sync with head.
 1.25.10.2 10-Dec-2006  yamt sync with head.
 1.25.10.1 22-Oct-2006  yamt sync with head
 1.25.8.1 18-Nov-2006  ad Sync with head.
 1.28.36.1 11-Dec-2007  yamt sync with head.
 1.28.34.1 26-Dec-2007  ad Sync with head.
 1.28.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.28.24.1 09-Jan-2008  matt sync with HEAD
 1.28.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.28.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.29.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.30.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.30.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.31.4.3 11-Mar-2010  yamt sync with head
 1.31.4.2 04-May-2009  yamt sync with head.
 1.31.4.1 16-May-2008  yamt sync with head.
 1.31.2.1 18-May-2008  yamt sync with head.
 1.33.14.1 21-Apr-2010  matt sync to netbsd-5
 1.33.10.1 01-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #474):
sys/dev/mii/inphy.c: revision 1.51
sys/dev/mii/iophy.c: revision 1.35
sys/dev/mii/nsphy.c: revision 1.56
sys/dev/mii/rlphy.c: revision 1.25
sys/dev/mii/ukphy_subr.c: revision 1.11
sys/dev/pci/if_txp.c: revision 1.28
fix media priorities:
IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:
1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T
Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.
Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html
got no comments, no objections.
 1.33.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.33.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.33.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.34.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.36.36.1 10-Aug-2014  tls Rebase.
 1.36.22.2 03-Dec-2017  jdolecek update from HEAD
 1.36.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.36.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.37.4.1 09-Jul-2016  skrll Sync with HEAD
 1.38.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.38.18.1 10-Jun-2019  christos Sync with HEAD
 1.38.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 16-Sep-1999  soren Fix botched RCS IDs.
 1.1 05-Sep-1999  soren Add PHY driver the the Intel 82553 found on some fxp's.
Some variants of this chip need a little extra MII fix before
being usable, so this is not yet put into GENERIC's.
 1.11 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.10 15-Mar-2020  thorpej branches: 1.10.4; 1.10.24;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.9 14-Jan-2020  msaitoh No functional change:

- Move some definitions from if_stgereg.h to if_stge.c again because those are
not chip (registers or descriptors) definitions.
- Use proplib to pass information that loading DSP code is required when
PHY reset.
 1.8 27-Nov-2019  msaitoh branches: 1.8.2;
- Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.7 27-Nov-2019  msaitoh Print dmesg correctly.
 1.6 21-Nov-2019  msaitoh branches: 1.6.2;
Whitespace.
 1.5 21-Nov-2019  msaitoh Add missing NetBSD RCS Id. Reported by Andrius V.
 1.4 14-Nov-2019  msaitoh - Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
 1.3 14-Nov-2019  msaitoh STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.
 1.2 14-Nov-2019  msaitoh KNF. No functional change.
 1.1 07-Oct-2019  msaitoh Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by
Tomokazu HARADA and patch provided by Andrius V.
 1.6.2.3 27-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #490):

sys/dev/mii/ipgphy.c: revision 1.7

Print dmesg correctly.
 1.6.2.2 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #476):

sys/dev/pci/if_stgereg.h: revision 1.6
sys/arch/amd64/conf/ALL: revision 1.124
sys/dev/mii/files.mii: revision 1.51
share/man/man4/vge.4: revision 1.8
share/man/man4/vge.4: revision 1.9
distrib/sets/lists/man/mi: revision 1.1656
sys/arch/i386/conf/ALL: revision 1.471
share/man/man4/mii.4: revision 1.28
sys/dev/pci/if_stge.c: revision 1.71
sys/dev/mii/ipgphy.c: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.2
share/man/man4/Makefile: revision 1.684
sys/dev/mii/ipgphy.c: revision 1.3
sys/dev/mii/ipgphyreg.h: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.4
sys/dev/mii/ipgphyreg.h: revision 1.2
sys/dev/mii/ipgphy.c: revision 1.5
sys/dev/mii/ipgphyreg.h: revision 1.3
sys/dev/DEVNAMES: revision 1.322
sys/arch/i386/conf/GENERIC: revision 1.1211
sys/arch/amd64/conf/GENERIC: revision 1.537
share/man/man4/ipgphy.4: revision 1.1
share/man/man4/ipgphy.4: revision 1.2

Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by

Tomokazu HARADA and patch provided by Andrius V.

New sentence, new line.
Fix date. Add RCS Id.

KNF. No functional change.

STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.

- Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
- Define IPGPHY_SCR's address.
- Whitespace fix.

Add missing NetBSD RCS Id. Reported by Andrius V.
 1.6.2.1 21-Nov-2019  martin file ipgphy.c was added on branch netbsd-9 on 2019-11-25 16:44:31 +0000
 1.8.2.1 17-Jan-2020  ad Sync with head.
 1.10.24.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.10.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10.4.1 15-Mar-2020  martin file ipgphy.c was added on branch phil-wifi on 2020-04-13 08:04:24 +0000
 1.3 21-Nov-2019  msaitoh branches: 1.3.2; 1.3.10;
Add missing NetBSD RCS Id. Reported by Andrius V.
 1.2 12-Nov-2019  msaitoh - Define IPGPHY_SCR's address.
- Whitespace fix.
 1.1 07-Oct-2019  msaitoh Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by
Tomokazu HARADA and patch provided by Andrius V.
 1.3.10.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.10.1 21-Nov-2019  martin file ipgphyreg.h was added on branch phil-wifi on 2020-04-13 08:04:24 +0000
 1.3.2.2 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #476):

sys/dev/pci/if_stgereg.h: revision 1.6
sys/arch/amd64/conf/ALL: revision 1.124
sys/dev/mii/files.mii: revision 1.51
share/man/man4/vge.4: revision 1.8
share/man/man4/vge.4: revision 1.9
distrib/sets/lists/man/mi: revision 1.1656
sys/arch/i386/conf/ALL: revision 1.471
share/man/man4/mii.4: revision 1.28
sys/dev/pci/if_stge.c: revision 1.71
sys/dev/mii/ipgphy.c: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.2
share/man/man4/Makefile: revision 1.684
sys/dev/mii/ipgphy.c: revision 1.3
sys/dev/mii/ipgphyreg.h: revision 1.1
sys/dev/mii/ipgphy.c: revision 1.4
sys/dev/mii/ipgphyreg.h: revision 1.2
sys/dev/mii/ipgphy.c: revision 1.5
sys/dev/mii/ipgphyreg.h: revision 1.3
sys/dev/DEVNAMES: revision 1.322
sys/arch/i386/conf/GENERIC: revision 1.1211
sys/arch/amd64/conf/GENERIC: revision 1.537
share/man/man4/ipgphy.4: revision 1.1
share/man/man4/ipgphy.4: revision 1.2

Add support IC Plus IP1000* PHYs. PR/kern 42314 first reported by

Tomokazu HARADA and patch provided by Andrius V.

New sentence, new line.
Fix date. Add RCS Id.

KNF. No functional change.

STGE_PhyCtrl is not PHY register but MAC register, so use ukphy_status()
for IP1000A device.

- Use auto-negotiation when forcing 1000BASE-T.
- Add XXX comment for strange pause setting code. I suspect this is wrong.
- On my environments, 1000BASE-T half duplex doesn't work, so we might remove
IFM_1000T_HDX from this device in future.
- Define IPGPHY_SCR's address.
- Whitespace fix.

Add missing NetBSD RCS Id. Reported by Andrius V.
 1.3.2.1 21-Nov-2019  martin file ipgphyreg.h was added on branch netbsd-9 on 2019-11-25 16:44:31 +0000
 1.5 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.4 15-Mar-2020  thorpej branches: 1.4.4; 1.4.24;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.3 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.2 26-Nov-2019  msaitoh KNF. No functional change.
 1.1 30-Oct-2019  msaitoh branches: 1.1.2;
Add jmphy(4) from OpenBSD.
 1.1.2.2 25-Nov-2019  martin Regen for ticket 479
 1.1.2.1 30-Oct-2019  martin file jmphy.c was added on branch netbsd-9 on 2019-11-25 16:53:55 +0000
 1.4.24.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.4.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4.4.1 15-Mar-2020  martin file jmphy.c was added on branch phil-wifi on 2020-04-13 08:04:24 +0000
 1.1 30-Oct-2019  msaitoh branches: 1.1.2; 1.1.10;
Add jmphy(4) from OpenBSD.
 1.1.10.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.10.1 30-Oct-2019  martin file jmphyreg.h was added on branch phil-wifi on 2020-04-13 08:04:24 +0000
 1.1.2.2 25-Nov-2019  martin Regen for ticket 479
 1.1.2.1 30-Oct-2019  martin file jmphyreg.h was added on branch netbsd-9 on 2019-11-25 16:53:55 +0000
 1.56 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.55 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.54 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.53 25-Mar-2019  msaitoh KNF. No functional change.
 1.52 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.51 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.50 07-Jul-2016  msaitoh branches: 1.50.16; 1.50.18;
KNF. Remove extra spaces. No functional change.
 1.49 16-Jun-2014  msaitoh branches: 1.49.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.48 19-Oct-2009  bouyer branches: 1.48.18; 1.48.22; 1.48.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.47 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.46 04-May-2008  xtraeme branches: 1.46.6; 1.46.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.45 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.44 08-Apr-2008  cegger branches: 1.44.2; 1.44.4;
use aprint_*_dev and device_xname
 1.43 29-Dec-2007  dyoung branches: 1.43.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.42 09-Dec-2007  jmcneill branches: 1.42.2;
Merge jmcneill-pm branch.
 1.41 16-Nov-2006  christos branches: 1.41.22; 1.41.24; 1.41.30; 1.41.34; 1.41.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.40 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.39 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.38 29-Mar-2006  thorpej branches: 1.38.8; 1.38.10;
Use device_private().
 1.37 20-Feb-2006  thorpej branches: 1.37.2; 1.37.4; 1.37.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.36 11-Dec-2005  christos branches: 1.36.2; 1.36.4; 1.36.6;
merge ktrace-lwp.
 1.35 27-Feb-2005  perry branches: 1.35.4;
nuke trailing whitespace
 1.34 23-Aug-2004  thorpej branches: 1.34.4; 1.34.6;
Make use of static.
 1.33 29-Apr-2003  thorpej branches: 1.33.2;
Use aprint*().
 1.32 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.31 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.30 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.29 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.28 25-Mar-2002  thorpej branches: 1.28.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.27 14-Mar-2002  chs add support for LXT971 PHYs.
 1.26 13-Nov-2001  lukem add RCSID
 1.25 25-Aug-2001  thorpej ANSI'ify.
 1.24 02-Jun-2001  thorpej branches: 1.24.2;
Make PHY matching all table-driven.
 1.23 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.22 17-May-2001  drochner support the fiber output of the PHY device, enabled if the MIIF_HAVEFIBER
flag is passed in from the board driver
 1.21 04-Jul-2000  thorpej branches: 1.21.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.20 06-Mar-2000  thorpej branches: 1.20.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.19 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.18 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.17 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.16 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.15 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.14 21-Dec-1999  pk Use BMSR to test for `negotiation complete'; the alternative bit in the
LXT vendor register 20 is latching high and resets to low on read causing
subsequent status request to return `IFM_NONE'.
 1.13 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.12 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.11 14-May-1999  drochner branches: 1.11.2; 1.11.4; 1.11.8;
use the new "xx" prefixed OUIs because the mapping to the ID register
bits differs from the MII_OUI() way
 1.10 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.9 05-Nov-1998  thorpej branches: 1.9.6;
Common code for media-from-bmcr.
 1.8 05-Nov-1998  thorpej In the status routine, always use the media selected in the BMCR if
autonegotiation is not enabled. This is more reliable on many PHYs,
and requires fewer register reads.
 1.7 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.6 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.5 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.4 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.3 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.2 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.1 24-Oct-1998  thorpej Driver for the Level One LXT-970 10/100 Ethernet PHY.
 1.9.6.1 23-Apr-1999  perry branches: 1.9.6.1.2;
pullup 1.9->1.10 (thorpej): Fix PR7361
 1.9.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.11.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11.4.1 15-Nov-1999  fvdl Sync with -current
 1.11.2.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.20.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.21.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.21.2.5 01-Aug-2002  nathanw Catch up to -current.
 1.21.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.21.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.21.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.21.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.24.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.24.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.24.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.24.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.24.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.28.2.1 15-Jul-2002  gehenna catch up with -current.
 1.33.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.33.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.33.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.34.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.34.4.1 29-Apr-2005  kent sync with -current
 1.35.4.3 21-Jan-2008  yamt sync with head
 1.35.4.2 30-Dec-2006  yamt sync with head.
 1.35.4.1 21-Jun-2006  yamt sync with head.
 1.36.6.1 22-Apr-2006  simonb Sync with head.
 1.36.4.1 09-Sep-2006  rpaulo sync with head
 1.36.2.1 01-Mar-2006  yamt sync with head.
 1.37.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.37.4.1 19-Apr-2006  elad sync with head.
 1.37.2.1 01-Apr-2006  yamt sync with head.
 1.38.10.2 10-Dec-2006  yamt sync with head.
 1.38.10.1 22-Oct-2006  yamt sync with head
 1.38.8.1 18-Nov-2006  ad Sync with head.
 1.41.36.1 11-Dec-2007  yamt sync with head.
 1.41.34.1 26-Dec-2007  ad Sync with head.
 1.41.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.41.24.1 09-Jan-2008  matt sync with HEAD
 1.41.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.41.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.42.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.43.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.43.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.44.4.3 11-Mar-2010  yamt sync with head
 1.44.4.2 04-May-2009  yamt sync with head.
 1.44.4.1 16-May-2008  yamt sync with head.
 1.44.2.1 18-May-2008  yamt sync with head.
 1.46.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.46.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.48.36.1 10-Aug-2014  tls Rebase.
 1.48.22.2 03-Dec-2017  jdolecek update from HEAD
 1.48.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.49.4.1 09-Jul-2016  skrll Sync with HEAD
 1.50.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50.18.1 10-Jun-2019  christos Sync with HEAD
 1.50.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.3 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 24-Oct-1998  thorpej branches: 1.1.144; 1.1.146; 1.1.148;
Driver for the Level One LXT-970 10/100 Ethernet PHY.
 1.1.148.1 16-May-2008  yamt sync with head.
 1.1.146.1 18-May-2008  yamt sync with head.
 1.1.144.1 02-Jun-2008  mjf Sync with HEAD.
 1.73 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.72 06-Jan-2022  msaitoh QEMU e1000's PHY code doesn't reflect the PSSR_LINK bit. Do workaround.

IEEE 802.3 clause 22's PHY device has a link status bit in the BMCR
register, but it's required to read twice to get the correct value.
Almost all PHY devices have the vendor specific register which has
the link status bit that it's not required to read twice. makphy(4)
use the bit in the PSSR register to reduce the access cost.

QEMU's e1000 provides the PHY specific status register at 0x11 but the
link indication bit (PSSR_LINK.) is always 1 because
e1000x_update_regs_on_link_{down,up}() modify MII_SR_LINK_STATUS
(BMSR_LINK in NetBSD) but don't modify PSSR_LINK. It causes
"virsh domif-setlink xxx yyy down" doesn't work.
To avoid this problem, read the BMSR and check the BMSR_LINK bit. Add
MAKPHY_QUIRK_PSSR_LINK bit for this quirk. Set it if MII_EXTSR doesn't
exist because it's one of the case of QEMU.

Found and tested by ozaki-r.
 1.71 28-Dec-2021  msaitoh Reduce the access of the ESSR register.

- makphyattach() have a code to detect the Fiber/Copper auto selection
feature. Save the info to sc_flags to reduce the access
to the ESSR register. One of the reason is that the register is not
implemented on QEMU. Another reason is that it's not required to
access the register if the device is in the copper only mode.
 1.70 28-Dec-2021  msaitoh QEMU e1000's PHY code doesn't implement register 16. Do workaround.

- Marvell 88E1[01]11 (and many other Marvell PHYs) have the Fiber/Copper
auto selection feature. Our makphy(4) implement it but QEMU doesn't.
If it fails, a garbage data is used in the attach function and unexpected
media may be used. Fix this behavior by checking the return value of
PHY_READ(MAKPHY_ESSR). If the access failed, the media is regarded
as copper only. It's just a cosmetic change. It's not affected to the
packet processing.
 1.69 28-Dec-2021  msaitoh QEMU e1000's PHY code doesn't implement page 0 register 15. Do workaround.

- The BMSR register bit 8 (BMSR_EXTSTAT) denote the existence of page 0
register 15. qemu's e1000 sets BMSR_EXTSTAT but the access to register 15
fails. It doesn't conforms to the IEEE standard. Our makphy automatically
check the existence of 1000BASE-T or 1000BASE-SX by accessing the register
15. If the access failed, neither 1000BASE-T nor 1000BASE-SX is set to
the ability(mii_extcapabilities). Set EXTSR_1000TFDX and EXTSR_1000THDX
if the access failed in the attach function. It's just a cosmetic change.
It's not affected to the packet processing.
 1.68 04-Nov-2020  msaitoh Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.67 20-Oct-2020  msaitoh branches: 1.67.2;
Add Intel I347-AT4.
 1.66 03-Aug-2020  msaitoh Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.
 1.65 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.64 28-Jan-2020  msaitoh Fix comment.
 1.63 12-Dec-2019  msaitoh branches: 1.63.2;
- Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is valid only
when the link is up, so it's not good to check in the attach function.
- There is an environment that both copper and fiber bits are set in EXTSR
but it support copper only. To resolve this problem, check the ESSR
register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112 only.
To support other chips documents are required.
 1.62 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.61 26-Nov-2019  msaitoh KNF. No functional change.
 1.60 03-Jul-2019  maxv branches: 1.60.2;
Check the return value of PHY_READ(). Because, if it fails, 'reg' is not
initialized. On Qemu, this read systematically fails.

Print an error in this case, and act as if there was no fiber. Maybe there
is a smarter way to fix this kind of things.
 1.59 25-Mar-2019  msaitoh KNF. No functional change.
 1.58 25-Mar-2019  msaitoh - 88E1000(S) has no page select register, so don't access it.
Note that qemu doesn't implement the register and the access fails.
For I210, we can use the register.
- Don't set PSCR_CRS_ON_TX bit on I210.
 1.57 27-Feb-2019  jakllsch Use symbolic MII_MODEL_xxMARVELL_I210 instead of a literal 0 in makphy_isi210().
 1.56 25-Feb-2019  msaitoh Remove xxMARVELL E1000 and duplicated xxMARVELL E1000S to make functionality
the same as rev. 1.54.
 1.55 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.54 19-Feb-2019  msaitoh - Match Intel I21[01]. These chips' model number is wrongly set to 0
(== 88E1000 with model number 0). It seems the PHY function is almost the
same as 88E1512. When we add 88E1512 related change to makphy.c, I21[01]
should be take into account.
- KNF.
 1.53 08-Feb-2019  msaitoh - Add 88E1240.
- Rename E1116R_29 to E1318S
 1.52 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.51 16-Jan-2019  msaitoh Change the register size to uint16_t again in makphy_reset(). No functional
change intended.
 1.50 16-Jan-2019  msaitoh Restore a comment which was removed in rev. 1.46.
 1.49 08-Jan-2019  msaitoh Whitespace fixes. No functional change.
 1.48 30-Dec-2018  msaitoh Add 88E1512.
 1.47 30-Dec-2018  msaitoh - Control BMCR_PDOWN for IFM_NONE. Some chips still don't work as expected.
It would be required to modify PSCR and/or other register.
- Set mii_media_active correctly on non-autonego mode.
 1.46 28-Dec-2018  msaitoh - Backout some changes done in rev. 1.44. OK'd by jdolecek@:
- Remove e1000phyreg.h and use makphyreg.h again.
- Remove Energy detect stuff. Leave it by default.
- Remove MDI crossover configuraton. Leave it by default. I think it's OK to
add new API to change the mode.
- PHY_RESET() is used to commit some changes, so I think it's not good to
always clear BMCR_AUTOEN before reset in makphy_reset().
- It's not required to read MII_100T2SR twice because this register has no
any bit which is latched.
- Use mii_phy_reset() instead of extracted code.
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Add some "XXX FIXME" comment. Non GMII mode uses different page except
very old chip. Some bits are at the same location but others are not.
- Remove obsolete comment.
- s/MII_MAKPHY_/MAKPHY_/

XXX rev. 1.44 changed the setting of mii_media_active when the interface is
set to other than auto. I suspect the intention of the change is to reflect
the link up/down status. But, it didn't work because non auto setting makes
PSSR_LINK bit alwasy set "without modifing some registers".
This commit won't fix the change and it'll be fixed in the next commit.
 1.45 18-Jun-2018  msaitoh branches: 1.45.2;
- All of Marvell PHY's registers from addr 0x0 to 0xf conforms IEEE 802.3
specification, so those register definitions are not required. Use mii.h's
definitions. Note that E1000_ER_PAR_DETECT_FAULT should be 0x0010 instead of
0x0100(typo).
- Restore code for BMCR_ISO which was removed in makphy.c rev. 1.44
- Whitespace fix.
 1.44 16-Jun-2018  jdolecek switch to using OpenBSD eehpy(4) code to drive maphy(4), synchronizing support
for several special PHY conditions, particularly:
- Properly re-initialise the PHY upon resume
- Store next page in the Link Partner Next Page register for compatibility
with 802.3ab on 88E3016 PHYs. Fixes some autonegotiation problems on msk(4)
- Make 88E3016 actually work
- Make sure page 0 is selected when we initialize the PHY. Fixes problems
with the eephy(4) that attaches to nfe(4) on machines like the Sun Ultra 40.
(we had condition for this, now the page 0 is selected for any PHY type)
- Disable fiber/copper auto-selection on the 88E1111 if it is in RGMII mode, to
work around the fact that the onboard PHYs attached to nfe(4) on the Sun
X4100 M2 have fiber/copper auto-selection enabled even though the interfaces
are clearly copper-only

make sure to also add appropriate licenses, since basically nothing
really significant remains out of previous code

use FreeBSD <dev/mii/e1000reg.h> for register definitions as a base instead
of OpenBSD <dev/mii/eephyreg.h>, since it has some extra definitions for some
3016 bits, but add the several extra bits from OpenBSD needed by the code;
removed no longed used <dev/mii/makphyreg.h>

tested with PHY 88E1111, there no particular change observed - the
link status works as it did before, just now it does media nego
even before the interface is up

should however fix 88E3016 support and hence PR kern/49270 and PR kern/53301
 1.43 13-Jun-2018  jdolecek sort the models, and add several more variants; data found in OpenBSD eephy.c

this also makes makphy match model 88E3016, which adresses PR kern/53301
by Chris Humphries
 1.42 08-Nov-2016  msaitoh branches: 1.42.8; 1.42.14;
Set mii_mpd_{oui,rev}.
 1.41 07-Jul-2016  msaitoh branches: 1.41.2;
KNF. Remove extra spaces. No functional change.
 1.40 16-Jun-2014  msaitoh branches: 1.40.2; 1.40.4; 1.40.8;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.39 13-May-2014  christos Add some code from FreeBSD to make the E1147* work. Still does not autoneg
to GiGE for some reason but it autonegs to 100BaseTX full-duplex.
 1.38 21-Dec-2013  kiyohara branches: 1.38.2;
Add Marvell 88E1543. Tested on OPENBLOCKS_AX3.
 1.37 21-Jan-2012  chs branches: 1.37.2; 1.37.6; 1.37.10;
disable the entry for Marvell E1149 for now since this driver doesn't work
with some instances of this hardware (in particular, the ones on the
motherboard of an HP XW9400 workstation, which is supposedly a Tyan S2915).
ukphy works fine for this.
 1.36 12-Nov-2011  sekiya branches: 1.36.4;
Add support for makphy 0x0029 variation found on most recent Globalscale Dreamplug.
 1.35 11-Dec-2010  matt branches: 1.35.8;
Match Marvell E1145
 1.34 01-Aug-2010  kiyohara Add Marvell E1116R.
 1.33 14-Dec-2009  matt branches: 1.33.2; 1.33.4;
Add E1149 Phy.
 1.32 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.31 19-Apr-2009  msaitoh Oooops. Back out some of previous my commit.
 1.30 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.29 17-Nov-2008  dyoung branches: 1.29.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.28 04-May-2008  xtraeme branches: 1.28.6; 1.28.8; 1.28.14; 1.28.18;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.27 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.26 08-Apr-2008  cegger branches: 1.26.2; 1.26.4;
use aprint_*_dev and device_xname
 1.25 29-Dec-2007  wiz branches: 1.25.6;
Recognize Marvell 88E1116 Gigabit PHY.
 1.24 09-Dec-2007  jmcneill branches: 1.24.2;
Merge jmcneill-pm branch.
 1.23 23-Feb-2007  msaitoh branches: 1.23.16; 1.23.18; 1.23.24; 1.23.26; 1.23.28;
fix some negotiation problems on wm(4).

will fix PR#30078, PR#30490, PR#30906, PR#33429, PR#35386.
 1.22 16-Nov-2006  christos branches: 1.22.2; 1.22.4;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.21 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.20 21-Oct-2006  bouyer Restart negotiation when we change media even if autoneg is not enabled.
Otherwise switching from a fixed media to another fixed media isn't noticed
by the switch and the effective speed doesn't change.
 1.19 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.18 29-Mar-2006  thorpej branches: 1.18.8; 1.18.10;
Use device_private().
 1.17 11-Dec-2005  christos branches: 1.17.4; 1.17.6; 1.17.8; 1.17.10; 1.17.12;
merge ktrace-lwp.
 1.16 23-Jun-2005  briggs branches: 1.16.2;
Match Marvell 88E1111 from Dave Huang in PR kern/30556
 1.15 23-Aug-2004  thorpej branches: 1.15.10;
Make use of static.
 1.14 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.13 10-Apr-2004  thorpej Fetch negotiated flow control parameters. From HITOSHI Osada.
 1.12 29-Apr-2003  thorpej branches: 1.12.2;
Use aprint*().
 1.11 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.10 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.9 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.8 08-Aug-2002  fvdl Match 881011 PHY.
 1.7 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.6 25-Mar-2002  thorpej branches: 1.6.2; 1.6.4;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.5 15-Jan-2002  thorpej Update for 88E1000 model number changes.
 1.4 13-Nov-2001  lukem add RCSID
 1.3 25-Aug-2001  thorpej ANSI'ify.
 1.2 20-Jul-2001  thorpej branches: 1.2.2; 1.2.4;
Adjust for the corrected Marvell entry.
 1.1 12-Jul-2001  thorpej Driver for the Marvell 88E1000 ``Alaska'' 10/100/1000 PHY.
 1.2.4.9 18-Oct-2002  nathanw Catch up to -current.
 1.2.4.8 13-Aug-2002  nathanw Catch up to -current.
 1.2.4.7 01-Aug-2002  nathanw Catch up to -current.
 1.2.4.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.4.5 28-Feb-2002  nathanw Catch up to -current.
 1.2.4.4 14-Nov-2001  nathanw Catch up to -current.
 1.2.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.2.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.2.4.1 20-Jul-2001  nathanw file makphy.c was added on branch nathanw_sa on 2001-08-24 00:09:58 +0000
 1.2.2.8 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.7 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.2.6 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.2.5 11-Feb-2002  jdolecek Sync w/ -current.
 1.2.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.2.2 03-Aug-2001  lukem update to -current
 1.2.2.1 20-Jul-2001  lukem file makphy.c was added on branch kqueue on 2001-08-03 04:13:13 +0000
 1.6.4.1 16-Nov-2002  he Pull up revision 1.8 (requested by thorpej in ticket #649):
Match 881011 PHY.
 1.6.2.2 29-Aug-2002  gehenna catch up with -current.
 1.6.2.1 15-Jul-2002  gehenna catch up with -current.
 1.12.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.12.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.15.10.2 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.15.10.1 03-Jul-2005  tron Pull up revision 1.16 (requested by briggs in ticket #524):
Match Marvell 88E1111 from Dave Huang in PR kern/30556
 1.16.2.4 21-Jan-2008  yamt sync with head
 1.16.2.3 26-Feb-2007  yamt sync with head.
 1.16.2.2 30-Dec-2006  yamt sync with head.
 1.16.2.1 21-Jun-2006  yamt sync with head.
 1.17.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.17.10.1 19-Apr-2006  elad sync with head.
 1.17.8.1 01-Apr-2006  yamt sync with head.
 1.17.6.1 22-Apr-2006  simonb Sync with head.
 1.17.4.1 09-Sep-2006  rpaulo sync with head
 1.18.10.2 10-Dec-2006  yamt sync with head.
 1.18.10.1 22-Oct-2006  yamt sync with head
 1.18.8.1 18-Nov-2006  ad Sync with head.
 1.22.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.22.2.1 26-Mar-2007  jdc Pull up revision 1.23 (requested by msaitoh in ticket #514).

fix some negotiation problems on wm(4).

will fix PR#30078, PR#30490, PR#30906, PR#33429, PR#35386.
 1.23.28.1 11-Dec-2007  yamt sync with head.
 1.23.26.1 26-Dec-2007  ad Sync with head.
 1.23.24.1 18-Feb-2008  mjf Sync with HEAD.
 1.23.18.1 09-Jan-2008  matt sync with HEAD
 1.23.16.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.23.16.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.24.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.25.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.25.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.26.4.4 11-Aug-2010  yamt sync with head.
 1.26.4.3 11-Mar-2010  yamt sync with head
 1.26.4.2 04-May-2009  yamt sync with head.
 1.26.4.1 16-May-2008  yamt sync with head.
 1.26.2.1 18-May-2008  yamt sync with head.
 1.28.18.1 07-Jan-2011  matt Match some more phys.
 1.28.14.2 24-Dec-2011  matt Match 88E1114
 1.28.14.1 09-Nov-2009  cliff - add table entry for MII_STR_xxMARVELL_E1149
no spec available, may need special handling?
 1.28.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.28.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.29.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.33.4.1 05-Mar-2011  rmind sync with head
 1.33.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.35.8.2 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.35.8.1 17-Apr-2012  yamt sync with head
 1.36.4.1 18-Feb-2012  mrg merge to -current.
 1.37.10.1 18-May-2014  rmind sync with head
 1.37.6.2 03-Dec-2017  jdolecek update from HEAD
 1.37.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37.2.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.38.2.1 10-Aug-2014  tls Rebase.
 1.40.8.1 18-Jan-2017  skrll Sync with netbsd-5
 1.40.4.2 05-Dec-2016  skrll Sync with HEAD
 1.40.4.1 09-Jul-2016  skrll Sync with HEAD
 1.40.2.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1301):
sys/dev/mii/inphy.c: revision 1.55
sys/dev/mii/makphy.c: revision 1.42
sys/dev/mii/ikphy.c: revision 1.12
sys/dev/mii/atphy.c: revision 1.18
sys/dev/mii/ihphy.c: revision 1.10
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,model,rev}.
--
Set mii_mpd_{oui,rev}.
 1.41.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.42.14.3 26-Jan-2019  pgoyette Sync with HEAD
 1.42.14.2 18-Jan-2019  pgoyette Synch with HEAD
 1.42.14.1 25-Jun-2018  pgoyette Sync with HEAD
 1.42.8.6 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1726):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.42.8.5 05-Aug-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1594:

sys/dev/pci/if_wm.c 1.655-1.658, 1.660,
1.662, 1.664-1.668,
1.671-1.674, 1.678,
1.680-1.685 via patch
sys/dev/pci/if_wmreg.c 1.118-1.119 via patch
sys/dev/pci/if_wmvar.c 1.45 via patch
sys/dev/mii/igphy.c 1.35-1.36 via patch
sys/dev/mii/igphyreg.h 1.12-1.13
sys/dev/mii/makphy.c 1.66 via patch
sys/dev/mii/makphyreg.h 1.11

- Add SFP support. Module insertion/removal is not supported yet.
Currently, SFP detection is only done in the driver's attach phase.
- Detect the Media Auto Sense feature. Not supported yet.
- Fix SFF_SFP_ETH_FLAGS_100FX. It's not 0x10 but 0x20.
- Add extra delay in wm_serdes_power_up_link_82575().
- Add Intel I219 LM10-LM15 and V10-V14.
- wm(4) can use workqueue as deferred Rx/Tx handler).
Set hw.wm*.txrx_workqueue=1 to use workqueue instead of softint.
The default value of hw.wm*.txrx_workqueue is 0 which use softint
as before.
- Unset RSS UDP flags like ixg(4) and other OSes. To handle IP
fragmented UDP, first packet and second packet should be processed
in the same Rx queue.
- It's useless to not to set PCI_PMCSR_PME_STS bit when writing because
the bit is W1C. Instead, always write PCI_PMCSR_PME_STS bit to clear
in case it's already set.
- Actually writing always the checksum offload context descriptor
makes the HW do extra processing, avoid doing that if possible.
- Fix a bug that the WMREG_EEARBC_I210 register is incorrectly set if
the system uses iNVM.
- "wmX: 0" on 82542 is difficult to understand, so don't print it.
- Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID to avoid undefined behavior.
- Set if_baudrate for non-MII device.
- Rename some macros and function.
- KNF. Add comment.
 1.42.8.4 28-Jan-2020  martin Pull up the following, requested by msaitoh in ticket #1493:

sys/dev/mii/makphy.c 1.61, 1.63-1.64 via patch
sys/dev/mii/makphyreg.h 1.10

- Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is
valid only when the link is up, so it's not good to check in the
attach function.
- There is an environment that both copper and fiber bits are set in
EXTSR but it support copper only. To resolve this problem, check the
ESSR register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112
only.
- Fix comment. KNF.
 1.42.8.3 01-Aug-2019  martin Pull up the following revision, requested by msaitoh in ticket #1316:

sys/dev/mii/makphy.c 1.54,1.57-1.60 via patch
sys/dev/mii/makphyvar.h 1.1-1.2
sys/dev/mii/ihphy.c 1.12,1.14 via patch

- Support Intel I21[01].
- 88E1000(S) has no page select register, so don't access it.
Note that qemu doesn't implement the register and the access fails.
- Check the result of the ESSR register access because Qemu doesn't
implement the register.
- KNF.
 1.42.8.2 07-Mar-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1208):

sys/dev/mii/makphy.c: revision 1.53

- Add 88E1240.
- Rename E1116R_29 to E1318S
 1.42.8.1 17-Jan-2019  martin Pull up the following (requested by msaitoh in ticket #1164):

sys/dev/mii/miidevs 1.128, 1.132 (patch)
sys/dev/mii/makphy.c 1.43-1.51
sys/dev/mii/makphyreg.h 1.7-1.9

- miidevs: Add E1000 with model id 0x0006, it exists according to
OpenBSD rename E1000 model 0x0000 to E1000_0 for consistency.
- Match 88E1112, 88E1118, 88E1512, 88E3082 and G65G.
- Match 88E3016 and add some 88E3016 specific code. Fixes part of
PR kern/49270 and PR kern/53301.
- Make sure page 0 is selected when we initialize the PHY. Fixes
problems with the eephy(4) that attaches to nfe(4) on machines like
the Sun Ultra 40. (we had condition for this, now the page 0 is
selected for any PHY type)
- If autonegotiation is not enabled, we need a software reset for the
settings to take effect in makphy_service().
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Control BMCR_PDOWN for IFM_NONE. Some chips still don't work as
expected. It would be required to modify PSCR and/or other register.
- Set mii_media_active correctly on non-autonego mode.
- Remove obsolete comment.
- Whitespace fix.
 1.45.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.45.2.1 10-Jun-2019  christos Sync with HEAD
 1.60.2.4 29-Jan-2022  martin Pull up the following revisions (all via patch), requested by msaitoh
in ticket #1410:

sys/dev/mii/makphy.c 1.67,1.69-1.72
sys/dev/mii/makphyvar.h 1.3-1.4

- Add I347-AT4 support.
- Add three workarounds for QEMU e1000:
- QEMU sets BMSR_EXTSTAT but the access to register 15 fails.
Set EXTSR_1000TFDX and EXTSR_1000THDX if the access failed in the
attach function. It's just a cosmetic change.
- Marvell 88E1[01]11 have the Fiber/Copper auto selection feature,
but QEMU doesn't implement it. If the register access failed,
the media is regarded as copper only. It's just a cosmetic change.
- QEMU provides the PHY specific status register at 0x11 but the
link indication bit (PSSR_LINK) is always 1. It causes
"virsh domif-setlink xxx yyy down" doesn't work. To avoid this
problem, read the BMSR and check the BMSR_LINK bit. Add
MAKPHY_QUIRK_PSSR_LINK bit for this quirk. Set it if MII_EXTSR
doesn't exist because it's one of the case of QEMU.
- Reduce the number of access to the ESSR register. One of the reason
is that the register is not implemented on QEMU. Another reason is
that it's not required to access the register if the device is in
the copper only mode.
 1.60.2.3 29-Jan-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1409):

sys/dev/mii/igphy.c: revision 1.37
sys/dev/mii/ihphy.c: revision 1.19
sys/dev/mii/makphy.c: revision 1.68

Fix a bug that "ifconfig xx0 media none" set LINK_STATE_UNKNOWN instead of
LINK_STATE_DOWN.

XXX We should check for other PHY drivers, too.
 1.60.2.2 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1040):

sys/dev/mii/igphy.c: revision 1.35
sys/dev/mii/igphy.c: revision 1.36
sys/dev/mii/igphyreg.h: revision 1.12
sys/dev/mii/igphyreg.h: revision 1.13
sys/dev/mii/makphyreg.h: revision 1.11
sys/dev/pci/if_wm.c: revision 1.682
sys/dev/pci/if_wm.c: revision 1.683
sys/dev/pci/if_wm.c: revision 1.684
sys/dev/pci/if_wm.c: revision 1.685
sys/dev/mii/makphy.c: revision 1.66

s/MII_IGPHY_/IGPHY_/. No functional change.

Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.

Setup PCS and SGMII for SFP correctly. It still doesn't support SFP
insertion/removal.

Copper:
wm2: SGMII(SFP)
wm2: 0x1043c440<SPI,IOH_VALID,PCIE,SGMII,NEWQUEUE,ASF_FIRM,EEE,SFP>
makphy0 at wm2 phy 6: Marvell 88E1111 Gigabit PHY, rev. 1

Fiber:
wm3: SERDES(SFP)
wm3: 0x10034440<SPI,IOH_VALID,PCIE,NEWQUEUE,ASF_FIRM,SFP>
wm3: 1000baseSX, 1000baseSX-FDX, auto

Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID. Found by kUBSan.

Set if_baudrate for non-MII device. Before this commit, it was 0.
 1.60.2.1 28-Jan-2020  martin Pull up the following, requested by msaitoh in ticket #663:

sys/dev/mii/makphy.c 1.61, 1.63-1.64 via patch
sys/dev/mii/makphyreg.h 1.10

- Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is
valid only when the link is up, so it's not good to check in the
attach function.
- There is an environment that both copper and fiber bits are set in
EXTSR but it support copper only. To resolve this problem, check the
ESSR register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112
only.
- Fix comment. KNF.
 1.63.2.1 29-Feb-2020  ad Sync with head.
 1.67.2.1 14-Dec-2020  thorpej Sync w/ HEAD.
 1.12 26-Feb-2024  andvar s/Transmi /Transmit / in comments.
 1.11 03-Aug-2020  msaitoh Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.
 1.10 12-Dec-2019  msaitoh - Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is valid only
when the link is up, so it's not good to check in the attach function.
- There is an environment that both copper and fiber bits are set in EXTSR
but it support copper only. To resolve this problem, check the ESSR
register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112 only.
To support other chips documents are required.
 1.9 28-Dec-2018  msaitoh branches: 1.9.4; 1.9.6;
- Backout some changes done in rev. 1.44. OK'd by jdolecek@:
- Remove e1000phyreg.h and use makphyreg.h again.
- Remove Energy detect stuff. Leave it by default.
- Remove MDI crossover configuraton. Leave it by default. I think it's OK to
add new API to change the mode.
- PHY_RESET() is used to commit some changes, so I think it's not good to
always clear BMCR_AUTOEN before reset in makphy_reset().
- It's not required to read MII_100T2SR twice because this register has no
any bit which is latched.
- Use mii_phy_reset() instead of extracted code.
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Add some "XXX FIXME" comment. Non GMII mode uses different page except
very old chip. Some bits are at the same location but others are not.
- Remove obsolete comment.
- s/MII_MAKPHY_/MAKPHY_/

XXX rev. 1.44 changed the setting of mii_media_active when the interface is
set to other than auto. I suspect the intention of the change is to reflect
the link up/down status. But, it didn't work because non auto setting makes
PSSR_LINK bit alwasy set "without modifing some registers".
This commit won't fix the change and it'll be fixed in the next commit.
 1.8 25-Dec-2018  msaitoh Re-add makphyreg.h
 1.7 16-Jun-2018  jdolecek switch to using OpenBSD eehpy(4) code to drive maphy(4), synchronizing support
for several special PHY conditions, particularly:
- Properly re-initialise the PHY upon resume
- Store next page in the Link Partner Next Page register for compatibility
with 802.3ab on 88E3016 PHYs. Fixes some autonegotiation problems on msk(4)
- Make 88E3016 actually work
- Make sure page 0 is selected when we initialize the PHY. Fixes problems
with the eephy(4) that attaches to nfe(4) on machines like the Sun Ultra 40.
(we had condition for this, now the page 0 is selected for any PHY type)
- Disable fiber/copper auto-selection on the 88E1111 if it is in RGMII mode, to
work around the fact that the onboard PHYs attached to nfe(4) on the Sun
X4100 M2 have fiber/copper auto-selection enabled even though the interfaces
are clearly copper-only

make sure to also add appropriate licenses, since basically nothing
really significant remains out of previous code

use FreeBSD <dev/mii/e1000reg.h> for register definitions as a base instead
of OpenBSD <dev/mii/eephyreg.h>, since it has some extra definitions for some
3016 bits, but add the several extra bits from OpenBSD needed by the code;
removed no longed used <dev/mii/makphyreg.h>

tested with PHY 88E1111, there no particular change observed - the
link status works as it did before, just now it does media nego
even before the interface is up

should however fix 88E3016 support and hence PR kern/49270 and PR kern/53301
 1.6 13-May-2014  christos branches: 1.6.20; 1.6.26;
new register.
 1.5 19-Apr-2009  msaitoh branches: 1.5.22; 1.5.26; 1.5.36;
Oooops. Back out some of previous my commit.
 1.4 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.3 28-Apr-2008  martin branches: 1.3.8; 1.3.14;
Remove clause 3 and 4 from TNF licenses
 1.2 25-Dec-2006  wiz branches: 1.2.40; 1.2.42; 1.2.44;
Spell "threshold" correctly. From Zafer Aydogan.
 1.1 12-Jul-2001  thorpej branches: 1.1.2; 1.1.4; 1.1.40; 1.1.70;
Driver for the Marvell 88E1000 ``Alaska'' 10/100/1000 PHY.
 1.1.70.1 12-Jan-2007  ad Sync with head.
 1.1.40.1 30-Dec-2006  yamt sync with head.
 1.1.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.1.4.1 12-Jul-2001  nathanw file makphyreg.h was added on branch nathanw_sa on 2001-08-24 00:09:58 +0000
 1.1.2.2 03-Aug-2001  lukem update to -current
 1.1.2.1 12-Jul-2001  lukem file makphyreg.h was added on branch kqueue on 2001-08-03 04:13:13 +0000
 1.2.44.1 16-May-2008  yamt sync with head.
 1.2.42.1 18-May-2008  yamt sync with head.
 1.2.40.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.8.1 28-Apr-2009  skrll Sync with HEAD.
 1.5.36.1 10-Aug-2014  tls Rebase.
 1.5.26.1 18-May-2014  rmind sync with head
 1.5.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.26.3 18-Jan-2019  pgoyette Synch with HEAD
 1.6.26.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.6.26.1 25-Jun-2018  pgoyette Sync with HEAD
 1.6.20.3 05-Aug-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1594:

sys/dev/pci/if_wm.c 1.655-1.658, 1.660,
1.662, 1.664-1.668,
1.671-1.674, 1.678,
1.680-1.685 via patch
sys/dev/pci/if_wmreg.c 1.118-1.119 via patch
sys/dev/pci/if_wmvar.c 1.45 via patch
sys/dev/mii/igphy.c 1.35-1.36 via patch
sys/dev/mii/igphyreg.h 1.12-1.13
sys/dev/mii/makphy.c 1.66 via patch
sys/dev/mii/makphyreg.h 1.11

- Add SFP support. Module insertion/removal is not supported yet.
Currently, SFP detection is only done in the driver's attach phase.
- Detect the Media Auto Sense feature. Not supported yet.
- Fix SFF_SFP_ETH_FLAGS_100FX. It's not 0x10 but 0x20.
- Add extra delay in wm_serdes_power_up_link_82575().
- Add Intel I219 LM10-LM15 and V10-V14.
- wm(4) can use workqueue as deferred Rx/Tx handler).
Set hw.wm*.txrx_workqueue=1 to use workqueue instead of softint.
The default value of hw.wm*.txrx_workqueue is 0 which use softint
as before.
- Unset RSS UDP flags like ixg(4) and other OSes. To handle IP
fragmented UDP, first packet and second packet should be processed
in the same Rx queue.
- It's useless to not to set PCI_PMCSR_PME_STS bit when writing because
the bit is W1C. Instead, always write PCI_PMCSR_PME_STS bit to clear
in case it's already set.
- Actually writing always the checksum offload context descriptor
makes the HW do extra processing, avoid doing that if possible.
- Fix a bug that the WMREG_EEARBC_I210 register is incorrectly set if
the system uses iNVM.
- "wmX: 0" on 82542 is difficult to understand, so don't print it.
- Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID to avoid undefined behavior.
- Set if_baudrate for non-MII device.
- Rename some macros and function.
- KNF. Add comment.
 1.6.20.2 28-Jan-2020  martin Pull up the following, requested by msaitoh in ticket #1493:

sys/dev/mii/makphy.c 1.61, 1.63-1.64 via patch
sys/dev/mii/makphyreg.h 1.10

- Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is
valid only when the link is up, so it's not good to check in the
attach function.
- There is an environment that both copper and fiber bits are set in
EXTSR but it support copper only. To resolve this problem, check the
ESSR register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112
only.
- Fix comment. KNF.
 1.6.20.1 17-Jan-2019  martin Pull up the following (requested by msaitoh in ticket #1164):

sys/dev/mii/miidevs 1.128, 1.132 (patch)
sys/dev/mii/makphy.c 1.43-1.51
sys/dev/mii/makphyreg.h 1.7-1.9

- miidevs: Add E1000 with model id 0x0006, it exists according to
OpenBSD rename E1000 model 0x0000 to E1000_0 for consistency.
- Match 88E1112, 88E1118, 88E1512, 88E3082 and G65G.
- Match 88E3016 and add some 88E3016 specific code. Fixes part of
PR kern/49270 and PR kern/53301.
- Make sure page 0 is selected when we initialize the PHY. Fixes
problems with the eephy(4) that attaches to nfe(4) on machines like
the Sun Ultra 40. (we had condition for this, now the page 0 is
selected for any PHY type)
- If autonegotiation is not enabled, we need a software reset for the
settings to take effect in makphy_service().
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Control BMCR_PDOWN for IFM_NONE. Some chips still don't work as
expected. It would be required to modify PSCR and/or other register.
- Set mii_media_active correctly on non-autonego mode.
- Remove obsolete comment.
- Whitespace fix.
 1.9.6.2 05-Aug-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1040):

sys/dev/mii/igphy.c: revision 1.35
sys/dev/mii/igphy.c: revision 1.36
sys/dev/mii/igphyreg.h: revision 1.12
sys/dev/mii/igphyreg.h: revision 1.13
sys/dev/mii/makphyreg.h: revision 1.11
sys/dev/pci/if_wm.c: revision 1.682
sys/dev/pci/if_wm.c: revision 1.683
sys/dev/pci/if_wm.c: revision 1.684
sys/dev/pci/if_wm.c: revision 1.685
sys/dev/mii/makphy.c: revision 1.66

s/MII_IGPHY_/IGPHY_/. No functional change.

Rename PSSR_* to MAKPHY_PSSR_* and IGPHY_PSSR_* to avoid conflict.
No functional change.

Setup PCS and SGMII for SFP correctly. It still doesn't support SFP
insertion/removal.

Copper:
wm2: SGMII(SFP)
wm2: 0x1043c440<SPI,IOH_VALID,PCIE,SGMII,NEWQUEUE,ASF_FIRM,EEE,SFP>
makphy0 at wm2 phy 6: Marvell 88E1111 Gigabit PHY, rev. 1

Fiber:
wm3: SERDES(SFP)
wm3: 0x10034440<SPI,IOH_VALID,PCIE,NEWQUEUE,ASF_FIRM,SFP>
wm3: 1000baseSX, 1000baseSX-FDX, auto

Explicitly cast from uint16_t to uint32_t before shifting 16bit left
when printing Image Unique ID. Found by kUBSan.

Set if_baudrate for non-MII device. Before this commit, it was 0.
 1.9.6.1 28-Jan-2020  martin Pull up the following, requested by msaitoh in ticket #663:

sys/dev/mii/makphy.c 1.61, 1.63-1.64 via patch
sys/dev/mii/makphyreg.h 1.10

- Remove ESSR_FIBER_LINK bit check in makphyattach(). This bit is
valid only when the link is up, so it's not good to check in the
attach function.
- There is an environment that both copper and fiber bits are set in
EXTSR but it support copper only. To resolve this problem, check the
ESSR register's HWCFG_MODE bit and drop unsupported bits.
- If the chip is in Fiber/Copper auto select mode, check which media is
selected. Currently, the code supports 88E1011, 88E1111 and 88E1112
only.
- Fix comment. KNF.
 1.9.4.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.9.4.2 10-Jun-2019  christos Sync with HEAD
 1.9.4.1 28-Dec-2018  christos file makphyreg.h was added on branch phil-wifi on 2019-06-10 22:07:14 +0000
 1.4 06-Jan-2022  msaitoh QEMU e1000's PHY code doesn't reflect the PSSR_LINK bit. Do workaround.

IEEE 802.3 clause 22's PHY device has a link status bit in the BMCR
register, but it's required to read twice to get the correct value.
Almost all PHY devices have the vendor specific register which has
the link status bit that it's not required to read twice. makphy(4)
use the bit in the PSSR register to reduce the access cost.

QEMU's e1000 provides the PHY specific status register at 0x11 but the
link indication bit (PSSR_LINK.) is always 1 because
e1000x_update_regs_on_link_{down,up}() modify MII_SR_LINK_STATUS
(BMSR_LINK in NetBSD) but don't modify PSSR_LINK. It causes
"virsh domif-setlink xxx yyy down" doesn't work.
To avoid this problem, read the BMSR and check the BMSR_LINK bit. Add
MAKPHY_QUIRK_PSSR_LINK bit for this quirk. Set it if MII_EXTSR doesn't
exist because it's one of the case of QEMU.

Found and tested by ozaki-r.
 1.3 28-Dec-2021  msaitoh Reduce the access of the ESSR register.

- makphyattach() have a code to detect the Fiber/Copper auto selection
feature. Save the info to sc_flags to reduce the access
to the ESSR register. One of the reason is that the register is not
implemented on QEMU. Another reason is that it's not required to
access the register if the device is in the copper only mode.
 1.2 25-Mar-2019  msaitoh branches: 1.2.4; 1.2.6; 1.2.8;
Add my name.
 1.1 25-Mar-2019  msaitoh - 88E1000(S) has no page select register, so don't access it.
Note that qemu doesn't implement the register and the access fails.
For I210, we can use the register.
- Don't set PSCR_CRS_ON_TX bit on I210.
 1.2.8.2 01-Aug-2019  martin Add missing file from last pullup (ticket #1316, revisions 1.1-1.2)
 1.2.8.1 25-Mar-2019  martin file makphyvar.h was added on branch netbsd-8 on 2019-08-01 15:48:15 +0000
 1.2.6.1 29-Jan-2022  martin Pull up the following revisions (all via patch), requested by msaitoh
in ticket #1410:

sys/dev/mii/makphy.c 1.67,1.69-1.72
sys/dev/mii/makphyvar.h 1.3-1.4

- Add I347-AT4 support.
- Add three workarounds for QEMU e1000:
- QEMU sets BMSR_EXTSTAT but the access to register 15 fails.
Set EXTSR_1000TFDX and EXTSR_1000THDX if the access failed in the
attach function. It's just a cosmetic change.
- Marvell 88E1[01]11 have the Fiber/Copper auto selection feature,
but QEMU doesn't implement it. If the register access failed,
the media is regarded as copper only. It's just a cosmetic change.
- QEMU provides the PHY specific status register at 0x11 but the
link indication bit (PSSR_LINK) is always 1. It causes
"virsh domif-setlink xxx yyy down" doesn't work. To avoid this
problem, read the BMSR and check the BMSR_LINK bit. Add
MAKPHY_QUIRK_PSSR_LINK bit for this quirk. Set it if MII_EXTSR
doesn't exist because it's one of the case of QEMU.
- Reduce the number of access to the ESSR register. One of the reason
is that the register is not implemented on QEMU. Another reason is
that it's not required to access the register if the device is in
the copper only mode.
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 25-Mar-2019  christos file makphyvar.h was added on branch phil-wifi on 2019-06-10 22:07:14 +0000
 1.3 23-Oct-2024  skrll mcommphy(4): add support for YT85[23]1

The YT8531 support has been tested with additional changes on a
VisionFive2 board which requires several device properties propogated

rx-internal-delay-ps
tx-internal-delay-ps
motorcomm,rx-clk-drv-microamp
motorcomm,rx-data-drv-microamp
motorcomm,tx-clk-adj-enabled
motorcomm,tx-clk-10-inverted
motorcomm,tx-clk-100-inverted
motorcomm,tx-clk-1000-inverted

The YT8521 currently isn't attached, but support should work. It seems
a VisionFive has this PHY.
 1.2 12-Oct-2024  skrll mcommphy(4): adjust register names to reflect the YT8511 that's supported.
 1.1 03-Jan-2022  jmcneill branches: 1.1.10;
Add driver for Motorcomm YT8511 GbE PHY
 1.1.10.1 02-Aug-2025  perseant Sync with HEAD
 1.10 07-Jan-2019  msaitoh Add definitions of EEE advertisement(7.60) and EEE LP ability(7.61).
 1.9 06-Jul-2018  msaitoh Add PMA/PMD control 2 register bit definitions.
 1.8 28-Jun-2018  msaitoh branches: 1.8.2;
Add 25G(802.3by), 2.5G and 5G (802.3bz).
 1.7 07-Nov-2017  msaitoh branches: 1.7.2;
Define bit definitions of MDIO_PMAPMD_CTRL1 and MDIO_AN_CTRL1.
 1.6 09-Jun-2017  msaitoh - Update IEEE 802.3 Clause 45 definitions from IEEE 802.3 2009 to IEEE 802.3
2015.
- Modify register names.
- Modify comments.
 1.5 07-Jun-2017  msaitoh Fix typo.
 1.4 06-Jun-2017  msaitoh Add missing RCS Id.
 1.3 15-Apr-2013  msaitoh branches: 1.3.4; 1.3.12; 1.3.16; 1.3.32;
Fix typo.
 1.2 15-Apr-2013  msaitoh Add my name.
 1.1 15-Apr-2013  msaitoh Add new file mii/mdio.h which contain IEEE 802.3 Clause 45 MDIO
register definitions. From:
- IEEE 802.3 2009
- IEEE 802.3at
- IEEE 802.3av
- IEEE 802.3az
Currently, only device addresses and register number are written.
 1.3.32.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #937):
sys/dev/mii/mdio.h: revision 1.8-1.9
Add 25G(802.3by), 2.5G and 5G (802.3bz).
--
Add PMA/PMD control 2 register bit definitions.
 1.3.32.1 21-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #363):
sys/dev/mii/mdio.h: revision 1.4
sys/dev/mii/mdio.h: revision 1.5
sys/dev/mii/mdio.h: revision 1.6
sys/dev/mii/mdio.h: revision 1.7
Add missing RCS Id.
Fix typo.
- Update IEEE 802.3 Clause 45 definitions from IEEE 802.3 2009 to IEEE 802.3
2015.
- Modify register names.
- Modify comments.
Define bit definitions of MDIO_PMAPMD_CTRL1 and MDIO_AN_CTRL1.
 1.3.16.1 28-Aug-2017  skrll Sync with HEAD
 1.3.12.2 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.3.12.1 15-Apr-2013  yamt file mdio.h was added on branch yamt-pagecache on 2014-05-22 11:40:23 +0000
 1.3.4.3 03-Dec-2017  jdolecek update from HEAD
 1.3.4.2 23-Jun-2013  tls resync from head
 1.3.4.1 15-Apr-2013  tls file mdio.h was added on branch tls-maxphys on 2013-06-23 06:20:18 +0000
 1.7.2.2 18-Jan-2019  pgoyette Synch with HEAD
 1.7.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.8.2.1 10-Jun-2019  christos Sync with HEAD
 1.15 31-Oct-2022  jmcneill fix blank printf at attach
 1.14 28-Mar-2020  thorpej Don't set DVF_DETACH_SHUTDOWN. The MII layer wants to manage the lifecycle
of the PHY devices, and if a NIC driver chooses not to detach its PHYs
at shutdown, that's the driver's business.

PR kern/55121.
 1.13 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.12 14-Feb-2020  nisimura add missing two aprint_normal* lines
 1.11 13-Dec-2019  msaitoh branches: 1.11.2;
KNF. No functional change.
 1.10 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.9 06-Nov-2019  msaitoh Add support for KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and KSZ9477.
It also supports LAN7430's internal PHY. First wrote by nisimura@ and added
some device support by me. Not tested well.
 1.8 25-Mar-2019  msaitoh branches: 1.8.4;
KNF. No functional change.
 1.7 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.6 14-Feb-2019  msaitoh Add KSZ8081 support from FreeBSD.
 1.5 22-Jan-2019  skrll Fix build after API change
 1.4 07-Jul-2016  msaitoh branches: 1.4.10; 1.4.16; 1.4.18;
KNF. Remove extra spaces. No functional change.
 1.3 26-Sep-2014  ryo branches: 1.3.2;
s/__diagused/__debugused/ for KDASSERT
 1.2 10-Sep-2014  ryo add __diagused
 1.1 26-Feb-2014  ozaki-r branches: 1.1.4; 1.1.6; 1.1.10;
Add Micrel PHY (KSZ9021RN)

The new driver micphy is almost same as ukphy except that
micphy has a fixup for cpsw; a PHY with cpsw has to adjust
RGMII signal timing.

Reviewed by christos@
 1.1.10.3 03-Dec-2017  jdolecek update from HEAD
 1.1.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.10.1 26-Feb-2014  tls file micphy.c was added on branch tls-maxphys on 2014-08-20 00:03:41 +0000
 1.1.6.2 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.1.6.1 26-Feb-2014  yamt file micphy.c was added on branch yamt-pagecache on 2014-05-22 11:40:23 +0000
 1.1.4.2 18-May-2014  rmind sync with head
 1.1.4.1 26-Feb-2014  rmind file micphy.c was added on branch rmind-smpnet on 2014-05-18 17:45:39 +0000
 1.3.2.1 09-Jul-2016  skrll Sync with HEAD
 1.4.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4.18.1 10-Jun-2019  christos Sync with HEAD
 1.4.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4.10.2 04-Sep-2019  martin The gcc on this branch is not smart enough and the build breaks due to
a bogus "may be used uninitialized" warning. Initialize to zero with
XXX gcc comment (suggested by msaitoh).
 1.4.10.1 01-Sep-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1349:

sys/dev/mii/micphy.c 1.6 via patch

Add KSZ8081 support from FreeBSD.
 1.8.4.1 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #479):

sys/dev/mii/micphy.c: revision 1.9
sys/dev/mii/miidevs: revision 1.161
share/man/man4/micphy.4: revision 1.3

Add Micrel (now Microchip) KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and
KSZ9477.

Add support for KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and KSZ9477.
It also supports LAN7430's internal PHY. First wrote by nisimura@ and added
some device support by me. Not tested well.
 1.11.2.1 29-Feb-2020  ad Sync with head.
 1.59 08-Feb-2024  andvar s/sharable/shareable in comments and documentation.
 1.58 14-Aug-2022  riastradh mii(4): Wait for MIIF_DOINGAUTO to clear with MIIF_AUTOTSLEEP too.

Otherwise mii_phy_detach may return while mii_phy_auto_timeout_locked
is still in progress in another thread.

Reuse the storage for mii_nway_ch, which is unused if MIIF_AUTOTSLEEP
is set, for a new condvar in a union. This doesn't change the kernel
ABI because sizeof(struct kcondvar) <= sizeof(struct callout) and
both have the same alignment, for an array of void *.
 1.57 07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.56 24-Apr-2021  thorpej branches: 1.56.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.55 15-Mar-2020  thorpej branches: 1.55.6;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.54 09-Apr-2019  msaitoh - Use uint16_t more for MII registers.
- Whitespace.
 1.53 25-Mar-2019  msaitoh KNF. No functional change.
 1.52 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.51 11-Jun-2015  matt branches: 1.51.16; 1.51.18;
Constify nibbletab
 1.50 04-Dec-2009  dyoung branches: 1.50.22; 1.50.40;
Delete unused function mii_activate().
 1.49 12-Nov-2009  dyoung Simplify activation hook.
 1.48 05-May-2008  tsutsui Use device_private() where appropriate.
 1.47 04-May-2008  xtraeme device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.46 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.45 08-Apr-2008  cegger branches: 1.45.2; 1.45.4;
use aprint_*_dev and device_xname
 1.44 10-Jan-2008  dyoung branches: 1.44.6;
Add a helper routine for ethernet drivers, mii_ifmedia_change().

Remove an mii_softc from its mii_data in mii_phy_detach(), not in
mii_detach(), so that we do not leave dangling pointers to a PHY
in an mii_data.
 1.43 29-Dec-2007  dyoung Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.42 29-Dec-2007  dyoung Use LIST_FOREACH().
 1.41 09-Jul-2007  ad branches: 1.41.8; 1.41.14; 1.41.20;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.40 11-Dec-2005  christos branches: 1.40.30; 1.40.32;
merge ktrace-lwp.
 1.39 25-Aug-2005  drochner kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function

This is handled by config_stdsubmatch() now.
 1.38 25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.37 13-Sep-2004  drochner branches: 1.37.12;
a round of autoconf cleanup:
-convert submatch() style functions (passed to config_search() or
config_found_sm()) to the locator passing variants
-pass interface attributes in some cases
-make submatch() functions look uniformly as far as possible
-avoid macros which just hide cfdata members, and reduce dependencies
on "locators.h"
 1.36 01-Sep-2004  drochner include locators.h from .c only, avoids unnecessary dependencies
 1.35 23-Aug-2004  thorpej Make use of static.
 1.34 20-Aug-2004  yamt for offloc, use MII_OFFSET_ANY rather than abusing MII_PHY_ANY.
 1.33 01-Jan-2003  thorpej branches: 1.33.2;
Use aprint_normal() in cfprint routines.
 1.32 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.31 27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.30 27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.29 25-Mar-2002  thorpej Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.28 13-Nov-2001  lukem add RCSID
 1.27 25-Aug-2001  thorpej ANSI'ify.
 1.26 20-Jun-2001  thorpej branches: 1.26.2;
When probing for a PHY, look at the EXTSTAT bit in the BMSR, as well,
not just the media mask. This prevents PHYs/TBIs that only support
Gigabit media from slipping through the cracks.
 1.25 17-May-2001  drochner re-enable mii_flags in attach args - I've found a use for it: tell the
PHY which support it that a fiber interface is present
 1.24 13-Apr-2001  augustss Comment out some flag stuff that isn't used. Someone should take a look
at this. There is something fishy with the mii code, the last argument to
mii_attach() is not being used in any meaningful way.
 1.23 28-Mar-2001  drochner Reading the IEEE specs shows that the bits have to be reversed when
mapping an OUI to the MII id registers.
Doing this in the MII_OUI() macro would be too complex, so put it into
a helper function and move the MII id register interpretation stuff
into miivar.h.
 1.22 24-Mar-2001  thorpej Remove a comment; this module has not been compatible w/ BSD/OS's
for quite a long time.
 1.21 04-Jul-2000  thorpej branches: 1.21.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.20 23-Mar-2000  thorpej branches: 1.20.4;
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.19 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.18 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.17 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.16 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.15 04-Nov-1999  thorpej Allow mii_phy_probe() to be called multiple times, and allow the caller
to specify either the PHY number or the PHY `offset' (1st, 2nd, 3rd, etc.)
to configure.
 1.14 27-Oct-1999  thorpej Fix a braino in some currently-disabled code.
 1.13 25-Sep-1999  thorpej branches: 1.13.2; 1.13.4; 1.13.6;
Add a PHY `offset' (e.g. "first PHY on bus, second PHY on bus, ...") to
the PHY's softc.
 1.12 03-Aug-1999  drochner move common support functions for phy drivers from mii.c to mii_physubr.c,
so that they are not includes if no PHY is configured
(avoids code bloat if an interface driver has the "mii" attribute but
mii is not used by the particular version)
 1.11 05-Feb-1999  thorpej Some PHYs are really braindead, and report incorrect IDs. Simplify the
test for this, and probe for PHYs based on media in the BMSR.
 1.10 29-Jan-1999  pk Fix bit test
 1.9 05-Nov-1998  thorpej Common code for media-from-bmcr.
 1.8 05-Nov-1998  thorpej Tidy up the message from mii_print() somewhat.
 1.7 11-Aug-1998  thorpej Adapt to attribute name change. Also, deal with 3Com PHYs that report
0/0 as their oui/model IDs.
 1.6 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.5 09-Jun-1998  thorpej Nuke __BROKEN_INDIRECT_CONFIG.
 1.4 11-Feb-1998  bouyer Correct a bogosity in the adapter->mii attach code pointed out by cgd:
in pci/if_tl.c, call config_found() with a print function, instead of
printing ourself a message in if_tl.c if no miibus was found. The print
function is in mii/mii.c (mii_adapter_print()) so that it can be used by any
adapter (idea from the scsi system).
 1.3 12-Jan-1998  thorpej Adjust for config changes.
 1.2 17-Nov-1997  thorpej KNF.
 1.1 17-Oct-1997  bouyer branches: 1.1.2;
Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.1.2.1 10-Nov-1998  cgd patch from bouyer to address sysinst and media selection issues:
set the default media to UTP, and don't include 'none' in the media
list, so that sysinst will be able to set media properly. Done
differently in -current, because there the code uses MII. (bouyer)
 1.13.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.4.1 15-Nov-1999  fvdl Sync with -current
 1.13.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.13.2.2 27-Mar-2001  bouyer Sync with HEAD.
 1.13.2.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.20.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.21.2.9 03-Jan-2003  thorpej Sync with HEAD.
 1.21.2.8 11-Nov-2002  nathanw Catch up to -current
 1.21.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.21.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.21.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.21.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.21.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.21.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.26.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.26.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.26.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.26.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.33.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.33.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.33.2.2 03-Sep-2004  skrll Sync with HEAD
 1.33.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.37.12.3 21-Jan-2008  yamt sync with head
 1.37.12.2 03-Sep-2007  yamt sync with head.
 1.37.12.1 21-Jun-2006  yamt sync with head.
 1.40.32.1 11-Jul-2007  mjf Sync with head.
 1.40.30.1 01-Jul-2007  ad Adapt to callout API change.
 1.41.20.2 10-Jan-2008  bouyer Sync with HEAD
 1.41.20.1 02-Jan-2008  bouyer Sync with HEAD
 1.41.14.1 18-Feb-2008  mjf Sync with HEAD.
 1.41.8.2 23-Mar-2008  matt sync with HEAD
 1.41.8.1 09-Jan-2008  matt sync with HEAD
 1.44.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.45.4.2 11-Mar-2010  yamt sync with head
 1.45.4.1 16-May-2008  yamt sync with head.
 1.45.2.1 18-May-2008  yamt sync with head.
 1.50.40.1 22-Sep-2015  skrll Sync with HEAD
 1.50.22.1 03-Dec-2017  jdolecek update from HEAD
 1.51.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.18.1 10-Jun-2019  christos Sync with HEAD
 1.51.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.55.6.1 22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.56.8.1 04-Aug-2021  thorpej Adapt to CFARGS().
 1.28 28-Feb-2025  andvar Fix various typos in comments.
 1.27 11-Apr-2019  msaitoh branches: 1.27.36;
KNF. No functional change.
 1.26 25-Feb-2019  msaitoh MMDACR_FN_{DATANPI,DATAPIRW,DATAPIW} are little hard to identify and might be
misread, so rename them to MMDACR_FN_{DATA,DATA_INC_RW,DATA_INC_W}.
 1.25 16-Jan-2019  msaitoh Add MII_100T2CR and MII_GTCR's test mode definitions.
 1.24 16-Jan-2019  msaitoh Add MII_GTCR(== 0x09 == MII_100T2CR) and MII_GTSR(== 0x0a == MII_100T2SR).
100T2 is little hard to imagine the meaning for gigabit Ethernet.
 1.23 18-Jun-2018  msaitoh branches: 1.23.2;
- Rename ENP (Extended Next Page) to XNP.
- Add ANLPAR_XNP bit.
- Add definitions for RF1 and RF2 (for 1000BASE-X) .
- Rename MII_ANNP (Autonegotiation next page transmit) register to MII_ANNPT.
- Add bit definitions for MII_ANNPT and MII_ANLPRNP.
- Remove GTSR_LP_ASM_DIR bit. This is not described in the 802.3 spec now and
no any NetBSD drivers use the definition.
 1.22 07-Jun-2017  msaitoh branches: 1.22.4;
- Add some bit definitions:
- Unidirectional enable
- Unidirectional ability
- Extended Next Page
- Receive Next Page Location Able
- Received Next Page Storage Location
- Data Link Layer Classification capability
- Enable Physical Layer Classification
- Invalid Class in PD Class
- PSE Status bit definitions
- Sort registers
- Modify comments.
 1.21 07-Jun-2017  msaitoh Fix typos.
 1.20 28-Oct-2016  msaitoh branches: 1.20.8;
Define MII_ADDRBITS and MII_ADDRMASK.
 1.19 21-Jul-2015  msaitoh branches: 1.19.2;
Fix typos reported by yuo@.
 1.18 16-Jun-2014  msaitoh branches: 1.18.2; 1.18.4; 1.18.8;
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.17 16-Jun-2013  msaitoh branches: 1.17.6;
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.16 15-Apr-2013  msaitoh Add the following registers from IEEE 802.3-2009 Clause 22.
- PSE control register(0x0b)
- PSE status register(0x0c)
- MMD access control register(0x0d)
- MMD access address data register(0x0e)
 1.15 03-Apr-2013  msaitoh Fix typo in comment.
 1.14 19-Oct-2009  bouyer branches: 1.14.12; 1.14.18; 1.14.22;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.13 11-Dec-2005  christos branches: 1.13.74;
merge ktrace-lwp.
 1.12 27-Feb-2005  perry nuke trailing whitespace
 1.11 09-Apr-2004  thorpej branches: 1.11.4; 1.11.6;
Correct pause related bits in ANAR and ANLPAR.

From HITOSHI Osada.
 1.10 25-Jul-2001  thorpej branches: 1.10.20;
Fix 1000BASE-X duplex negotiation. That'll teach me to read the
manual more carefully next time.
 1.9 31-May-2001  thorpej branches: 1.9.2;
Typo in last.
 1.8 31-May-2001  thorpej The 1000baseT CR and SR are overlapped with the 100base-T2 CR and SR.
Note this in a comment. Add the 1000baseT CR and SR bits.
 1.7 15-May-2001  matt Note that extended status is in register 15
 1.6 30-Apr-2001  thorpej Add code to recognize and set media on GMII (Gigabit MII) PHYs.

802.3 doens't specify ANAR or ANLPAR bits for GMII. Need to
use PHY-specific registers for this, for now, which means we
need specific drivers for the Gigabit-capable PHYs (I think the
most common is the BCM5400).
 1.5 30-Apr-2001  thorpej Add a bunch of Gig-E definitions.
 1.4 28-Mar-2001  drochner Reading the IEEE specs shows that the bits have to be reversed when
mapping an OUI to the MII id registers.
Doing this in the MII_OUI() macro would be too complex, so put it into
a helper function and move the MII id register interpretation stuff
into miivar.h.
 1.3 02-Feb-2000  thorpej branches: 1.3.6;
Bring some order to the chaos which was the MII code function naming
"conventions".
 1.2 29-Sep-1999  thorpej branches: 1.2.2;
Define ANAR and ANLPAR bits that are used to negotiate the 802.3x PAUSE
feature.
 1.1 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.2.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.2.2.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.3.6.3 24-Aug-2001  nathanw Catch up with -current.
 1.3.6.2 21-Jun-2001  nathanw Catch up to -current.
 1.3.6.1 09-Apr-2001  nathanw Catch up with -current.
 1.9.2.1 03-Aug-2001  lukem update to -current
 1.10.20.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.10.20.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.20.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.20.1 03-Aug-2004  skrll Sync with HEAD
 1.11.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.11.4.1 29-Apr-2005  kent sync with -current
 1.13.74.1 11-Mar-2010  yamt sync with head
 1.14.22.3 03-Dec-2017  jdolecek update from HEAD
 1.14.22.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.22.1 23-Jun-2013  tls resync from head
 1.14.18.2 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.14.18.1 04-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1146):
sys/dev/mii/mii_physubr.c: revision 1.79
sys/dev/mii/rgephy.c: revision 1.33
sys/dev/mii/brgphy.c: revision 1.66
sys/dev/mii/atphy.c: revision 1.15
sys/dev/mii/mii.h: revision 1.17
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.14.12.1 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.17.6.1 10-Aug-2014  tls Rebase.
 1.18.8.1 18-Jan-2017  skrll Sync with netbsd-5
 1.18.4.3 28-Aug-2017  skrll Sync with HEAD
 1.18.4.2 05-Dec-2016  skrll Sync with HEAD
 1.18.4.1 22-Sep-2015  skrll Sync with HEAD
 1.18.2.1 12-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1302):
sys/dev/mii/igphyreg.h: revisions 1.7-1.10
sys/dev/mii/ikphyreg.h: revisions 1.3
sys/dev/mii/inbmphyreg.h: revisions 1.4-1.9
sys/dev/mii/mii.h: revisions 1.19-1.20
sys/dev/pci/if_wm.c: revisions 1.390, 1.392-1.395, 1.397, 1.419-1.425, 1.427-1.428, 1.430-1.435, 1.437-1.453 via patch
sys/dev/pci/if_wmreg.: revisions 1.89-1.93 via patch
sys/dev/pci/if_wmvar.h: revisions 1.31-1.32
Update wm(4) up to if_wm.c rev. 1.453 except MSI/MSI-X, multiqueue and
NET_MPSAFE:
- Add I219 support. It's not stable so it's disabled by default.
- wm_gate_hw_phy_config_ich8lan() is for younger than PCH2.
- Drop the host wakeup bit after resetting PHY on PCH and newer
devices.
- Increase delay while toggling LANPHYPC
- Move call of wm_reset() in wm_attach() after setting PHY and NVM
related flags because those flags are used in wm_reset().
- Use mutex for NVM access on ICH8 and newer devices. Same as FreeBSD.
- Rewrite PHY related lock stuff. Almost the same as FreeBSD.
This change will fix a bug that PHY read/write fail on some cases.
- Increase delay in wm_phy_resetisblocked(). Same as FreeBSD.
- Use semaphore in wm_hv_phy_workaround_ich8lan() and
wm_k1_gig_workaround_hv()
- Use wm_gii_mdic_readreg/writereg() in wm_access_phy_wakeup_reg_bm()
because these functions are called with taking lock.
- 82567V_3 is BME1000_E_2(bm). Tested with Advantech AIMB-212 1st
Ethernet port.
- Use wm_gmii_82544_{read,write}reg() on non-82567 ICH8, 9 and 10.
- Remove an 82578 workaround which was for PCH rev < 3. FreeBSD
removed this workaround in r228386.
- Add an 82578 workaround which is for PHY rev < 2. From FreeBSD and
Linux.
- Fix wm(4) input drop packet counter. WMREG_RNBC is incremented when
there is no available buffers in host memory. However, ethernet
controller can receive packets in such case if there is space in
phy's FIFO. That is, ethernet controller drops packet only if there
is no available buffers *and* there is no space in phy's FIFO. So,
the number of dropped packets should be added WMREG_MPC only.
- Use MII_ADDRMASK.
- Define WMPHY_I217, WMPHY_VF and WMPHY_210.
- Use BME1000_PHY_PAGE_SELECT in wm_gmii_bm_{read,write}reg(). This
change has no effect because GG82563_PHY_PAGE_SELECT and
BME1000_PHY_PAGE_SELECT have the same value.
- Fix PHY access on 82567(ICH8 or ICH10), 82574 and 82583:
- Use wm_gmii_bm_{read,write}reg() on 82574 and 82573.
- Issue page select correctly on BM PHYs.
- Fix workaround which did dummy read BM_WUC register. This code was
changed to drop BM_WUC_HOST_WU_BIT of BM_PROT_GEN_CFG register in
FreeBSD r228386. The code was added rev. 1.149, but the location was
not the best.
- wm_gmii_hv_{read/write}reg*(): USE PHY address 1 for some special
registers.
- Add check code for an 82578 workaround. Not completed yet.
- wm_release_hw_control(): Remove extra line. No any effect.
- Add "10/100" into non-gigabit devices' name.
- Call wm_enable_wakeup() in wm_detach() and wm_suspend(). Now wake on
lan works on Thinkpad X61(ICH8).
- Fix wm_access_phy_wakeup_reg_bm(). This change has no effect because
this function is used for WUC register and our driver currenlty
doesn't access to it.
- Call wm_enable_phy_wakeup() on PCH2 and newer, too. Now these devices
can do WOL. Tested with Thinkpad X220(PCH2).
- Set CTRL_MEHE correctly (PCH_{LPT,SPT} only).
- Add three workarounds for PCH_{LPT,SPT}.
- Fix a bug that 8257[56], 82580, I35[04] and I21[01] didn't use
wm_{get,release}_hw_control() correctly.
- Sync wm_smbustopci() with Linux and FreeBSD. This change effects PCH
and newer devices.
- Move the location of wm_smbustopci() call.
- Fix flag check in wm_get_wakeup()
- 8254[17]* and 8257[124] should not set WM_F_ARC_SUBSYS_VALID.
- Add missing WM_T_82541_2 and WM_T_82547_2.
- Fix WOL related setting of the WUC register for other than PCH* in
wm_enable_wakeup(). Tested with 82567V(ICH8) and 82583V.
- Use common MII_ADDRMASK.
- igphy(4): No binary change:
- s/IGPPHY/IGPHY/
- Fix the definition of PLHR_VALID_CHANNEL_*
- Fix the definition of MSE_CHANNEL_*
- Add MII_IGPHY_POWER_MGMT.
- Add some KASSERT.
- Add comment. Modify comment.
- Add debug code.
 1.19.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.20.8.1 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #932):
sys/dev/mii/mii.h: 1.21-1.23
Fix typos.
--
- Add some bit definitions:
- Unidirectional enable
- Unidirectional ability
- Extended Next Page
- Receive Next Page Location Able
- Received Next Page Storage Location
- Data Link Layer Classification capability
- Enable Physical Layer Classification
- Invalid Class in PD Class
- PSE Status bit definitions
- Sort registers
- Modify comments.
--
- Rename ENP (Extended Next Page) to XNP.
- Add ANLPAR_XNP bit.
- Add definitions for RF1 and RF2 (for 1000BASE-X) .
- Rename MII_ANNP (Autonegotiation next page transmit) register to MII_ANNPT.
- Add bit definitions for MII_ANNPT and MII_ANLPRNP.
- Remove GTSR_LP_ASM_DIR bit. This is not described in the 802.3 spec now and
no any NetBSD drivers use the definition.
 1.22.4.2 18-Jan-2019  pgoyette Synch with HEAD
 1.22.4.1 25-Jun-2018  pgoyette Sync with HEAD
 1.23.2.1 10-Jun-2019  christos Sync with HEAD
 1.27.36.1 02-Aug-2025  perseant Sync with HEAD
 1.4 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.3 11-Feb-1998  bouyer Correct a bogosity in the adapter->mii attach code pointed out by cgd:
in pci/if_tl.c, call config_found() with a print function, instead of
printing ourself a message in if_tl.c if no miibus was found. The print
function is in mii/mii.c (mii_adapter_print()) so that it can be used by any
adapter (idea from the scsi system).
 1.2 17-Nov-1997  thorpej Cosmetic changes.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.4 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.3 17-Nov-1997  thorpej Cosmetic changes.
 1.2 16-Nov-1997  christos PR/4510: William Coldwell: Recognize TI thunderlan.
 1.1 17-Oct-1997  bouyer branches: 1.1.2;
Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.1.2.1 17-Nov-1997  thorpej sync w/ trunk.
 1.14 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.13 08-Jan-2019  msaitoh s/u_int32_t/uint32_t/
 1.12 04-May-2008  xtraeme branches: 1.12.86; 1.12.88;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.11 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10 11-Dec-2005  christos branches: 1.10.70; 1.10.72; 1.10.74;
merge ktrace-lwp.
 1.9 09-Aug-2005  chris Remove changes to bitbang code for de devices to work as tlps on cats.

I need to investigate a proper fix that doesn't break other platforms, eg:
PR kern/30952
 1.8 07-Aug-2005  chris Following feedback from thorpej, remove the #ifdef cats block, and update
comment.

All platforms will now send a change in direction, then the 32 MDO bits
when synchronising with the phy. Rather than sending the change in
direction with the first MDO bit.
 1.7 06-Aug-2005  chris Check in cats specific tweak to make older de cards work as tlp devices.

With this tweak I've completed a full install from NFS of 3.99.7, using a
card the previously didn't work as a tlp device.
 1.6 23-Aug-2004  thorpej Make use of static.
 1.5 13-Nov-2001  lukem branches: 1.5.16;
add RCSID
 1.4 11-Nov-2001  perry fix a couple of signed->unsigned warnings lint found
 1.3 25-Aug-2001  thorpej branches: 1.3.4;
ANSI'ify.
 1.2 30-Apr-2001  lukem branches: 1.2.2;
remove some lint
 1.1 17-Nov-1999  thorpej branches: 1.1.2; 1.1.8; 1.1.10;
Common module for bit-bang'ing the MII.
 1.1.10.3 14-Nov-2001  nathanw Catch up to -current.
 1.1.10.2 21-Sep-2001  nathanw Catch up to -current.
 1.1.10.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.8.2 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.8.1 17-Nov-1999  bouyer file mii_bitbang.c was added on branch thorpej_scsipi on 2000-11-20 11:42:10 +0000
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.3.4.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.5.16.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.16.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.16.1 25-Aug-2004  skrll Sync with HEAD.
 1.10.74.1 16-May-2008  yamt sync with head.
 1.10.72.1 18-May-2008  yamt sync with head.
 1.10.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.88.1 10-Jun-2019  christos Sync with HEAD
 1.12.86.2 26-Jan-2019  pgoyette Sync with HEAD
 1.12.86.1 18-Jan-2019  pgoyette Synch with HEAD
 1.7 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.6 12-May-2009  cegger branches: 1.6.62; 1.6.64;
struct device * -> device_t, no functional changes intended.
 1.5 25-Nov-2008  matt branches: 1.5.4;
u_int32_t -> uint32_t
 1.4 28-Apr-2008  martin branches: 1.4.6; 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 23-Aug-2004  thorpej De-__P
 1.1 17-Nov-1999  thorpej branches: 1.1.2; 1.1.8; 1.1.32;
Common module for bit-bang'ing the MII.
 1.1.32.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.32.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.32.1 25-Aug-2004  skrll Sync with HEAD.
 1.1.8.2 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.8.1 17-Nov-1999  bouyer file mii_bitbang.h was added on branch thorpej_scsipi on 2000-11-20 11:42:11 +0000
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.74.3 16-May-2009  yamt sync with head
 1.3.74.2 04-May-2009  yamt sync with head.
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.4.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.5.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.64.1 10-Jun-2019  christos Sync with HEAD
 1.6.62.1 26-Jan-2019  pgoyette Sync with HEAD
 1.3 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.2 25-Mar-2019  msaitoh - Copy copyright messages from if_ethersubr.c rev. 1.157.
- Add missing RCS ID.
 1.1 02-Jan-2008  dyoung branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.106;
Fix XEN2_DOMU (and amd64?) builds: move ether_mediastatus(),
ether_mediachange() to their own module that we compile only if
the kernel configuration demands support for both MII buses and
ethernet. Thanks to Tom Spindler for suggesting that these routines
move to dev/mii/.
 1.1.106.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.106.1 10-Jun-2019  christos Sync with HEAD
 1.1.8.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.8.1 02-Jan-2008  mjf file mii_ethersubr.c was added on branch mjf-devfs on 2008-02-18 21:05:51 +0000
 1.1.6.2 21-Jan-2008  yamt sync with head
 1.1.6.1 02-Jan-2008  yamt file mii_ethersubr.c was added on branch yamt-lazymbuf on 2008-01-21 09:43:26 +0000
 1.1.4.2 09-Jan-2008  matt sync with HEAD
 1.1.4.1 02-Jan-2008  matt file mii_ethersubr.c was added on branch matt-armv6 on 2008-01-09 01:53:22 +0000
 1.1.2.2 02-Jan-2008  bouyer Sync with HEAD
 1.1.2.1 02-Jan-2008  bouyer file mii_ethersubr.c was added on branch bouyer-xeni386 on 2008-01-02 21:54:32 +0000
 1.3 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.2 17-Nov-1997  thorpej Cosmetic changes.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.103 22-May-2023  msaitoh Fix a bug when a media is changed to IFM_AUTO.

Fix a bug that ifconfig ifN media auto doesn't change the setting when
the previous media setting used autonego. When the mii_phy_setmedia()
function is called to change the media to IFM_AUTO, the BMCR_AUTOEN bit was
used to check if the previous setting was IFM_AUTO. It's not correct.
IFM_1000_T also uses autonego. So if a previous setting is IFM_1000_T and
the next setting is IFM_AUTO, mii_phy_auto() is not called if neither
MIIF_FORCEANEG nor MIIF_DOPAUSE are set. As a result, after changing
IFM_AUTO, neither 10Mbps nor 100Mbps are not advertised.

Note that almost all drivers uses MIIF_DOPAUSE flags.

TODO: cleanup ciphy.c and rgephy.c. Those have #ifdef foo.
 1.102 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.101 23-Aug-2022  riastradh branches: 1.101.4;
mii(9): Make mii_phy_down clear the flag if it prevented the callout.

This fixes a bug in the previous change to make mii_down wait for the
mii auto timeout to complete.
 1.100 20-Aug-2022  riastradh mii(4): Make mii_down wait for concurrent mii_phy_auto to finish.

This is important for callers in if_stop routines to guarantee that
all concurrent access to the mii registers has ended.

Drivers must not call this from softint context. Drivers with custom
watchdog timers (not if_watchdog) that do if_stop from callout must
defer to thread context instead, e.g. via workqueue(9) -- as they
should be doing anyway for heavyweight operations like if_stop.
 1.99 14-Aug-2022  riastradh mii(4): Wait for MIIF_DOINGAUTO to clear with MIIF_AUTOTSLEEP too.

Otherwise mii_phy_detach may return while mii_phy_auto_timeout_locked
is still in progress in another thread.

Reuse the storage for mii_nway_ch, which is unused if MIIF_AUTOTSLEEP
is set, for a new condvar in a union. This doesn't change the kernel
ABI because sizeof(struct kcondvar) <= sizeof(struct callout) and
both have the same alignment, for an array of void *.
 1.98 14-Aug-2022  riastradh mii(4): Sprinkle assertions in mii phy auto timeout.
 1.97 28-Dec-2021  riastradh mii(9): Fix callout race between mii_phy_down and mii_phy_detach.
 1.96 15-Dec-2021  msaitoh Cosmetic change for the output of mii_get_descr().
 1.95 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.94 27-Aug-2020  kardel branches: 1.94.6;
Move mii_phy_statusmsg(sc) back to its original position. Fixes
deafness bug on macppc reported and tested by martin@
Thanks !
 1.93 24-Aug-2020  kardel Keep the change check invariant intact. The previous code could miss
status updates by picking up a new status different from the tested
status. This left addresses in the DETACHED state although the
link status is already UP again.

addresses PR/kern 55538
 1.92 24-Aug-2020  msaitoh Don't do full initialization for autonego when just restarting autonego
because it's not required.

This change reduce extra initialization which include PHY_RESET() which
caused long delay(max 500ms).
 1.91 07-Jul-2020  msaitoh - Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.90 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.89 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.88 20-Nov-2019  msaitoh Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.87 09-Apr-2019  msaitoh branches: 1.87.4;
- Use uint16_t more for MII registers.
- Whitespace.
 1.86 25-Mar-2019  msaitoh KNF. No functional change.
 1.85 25-Mar-2019  msaitoh KNF. No functional change.
 1.84 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.83 08-Jan-2019  msaitoh Whitespace fixes. No functional change.
 1.82 28-Dec-2018  msaitoh 802.2 22.2.4.1.1 "Reset" says The reset shall be completed in 0.5s, so change
the value from 100ms to 500ms.
 1.81 05-Mar-2018  msaitoh branches: 1.81.2; 1.81.4;
KNF in comment. No functional change.
 1.80 20-Jun-2013  roy branches: 1.80.26;
Move the detaching and making tentative addresses out if in6_if_up
and into in6_if_link_up.

This fixes a possible panic where link is up but not the interface.
Note that a better solution would be to listen to the routing socket
in the kernel, but I don't know how to do that.

Reachable Router tests for IFF_UP as well.
 1.79 16-Jun-2013  msaitoh The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.78 09-Jun-2013  msaitoh Fix a bug in last commit that mii_ticks isn't inclemented.
 1.77 09-Jun-2013  msaitoh Update link status quickly. This change is a part of FreeBSD's mii_physubr.c
r158649.
 1.76 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.75 03-Oct-2012  mlelstv use media_table instead of replicating code
 1.74 22-Jul-2012  matt branches: 1.74.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.73 10-Dec-2011  buhrow branches: 1.73.2;

Fixes PR kern/20700 reported by Darcy Cain

Make 1000baset connections work even when the user specifies media 1000baset
connections with ifconfig(8) rather then only when media auto is specified.

For a further discussion of this fix, see:
http://mail-index.NetBSD.org/current-users/2011/12/07/msg018561.html
 1.72 21-Aug-2010  pgoyette branches: 1.72.8; 1.72.12;
Update the various xxx_verbose modules to conform to the module subsystem's
new locking protocol.
 1.71 25-Jul-2010  pgoyette Move setting of mii_verbose_loaded flag into the module's init routine.
This ensures that the flag is set even if the module was manually loaded
by the user rather than just auto-loaded.
 1.70 06-Jun-2010  pgoyette Update miiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
 1.69 02-Jun-2010  martin Move all miiverbose/module related functions from ukphy.c to mii_physubr.c -
ukphy is not included in all kernels, but mii_physubr.c should be in every
kernel that has a phy.
 1.68 02-Mar-2010  martin branches: 1.68.2;
Before destroying a autonegotiation callout, make sure it is quiet
 1.67 24-Feb-2010  dyoung 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.66 08-Jan-2010  dyoung branches: 1.66.2;
Expand PMF_FN_* macros.
 1.65 06-Nov-2009  dyoung Simplify mii_phy_activate(). Remark in mii_phy_activate() and
mii_phy_detach() comments that we may need to invalidate the parent's
media setting. No functional change intended.
 1.64 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.63 07-Apr-2009  dyoung In mii_phy_detach(), destroy the NWay callout.
 1.62 16-Jan-2009  cegger branches: 1.62.2;
add mii_anar(). From OpenBSD.
 1.61 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.60 04-May-2008  xtraeme branches: 1.60.6; 1.60.8; 1.60.10;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.59 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.58 29-Feb-2008  dyoung branches: 1.58.2; 1.58.4;
Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.57 20-Jan-2008  msaitoh branches: 1.57.2; 1.57.6;
mii_physubr.c::mii_phy_reset() has gphyter and nsphyter specific delay(500).
This delay cause 500us loops under splnet() per linkdown port per mii_tick.
It causes periodically drop packets. It's not acceptable for other devices.

Move gphyter and nsphyter specific delay(500) into the drivers from
mii_physubr.c.
 1.56 10-Jan-2008  dyoung Add a helper routine for ethernet drivers, mii_ifmedia_change().

Remove an mii_softc from its mii_data in mii_phy_detach(), not in
mii_detach(), so that we do not leave dangling pointers to a PHY
in an mii_data.
 1.55 29-Dec-2007  dyoung Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.54 09-Dec-2007  jmcneill branches: 1.54.2;
Merge jmcneill-pm branch.
 1.53 16-Nov-2006  christos branches: 1.53.2; 1.53.22; 1.53.24; 1.53.30; 1.53.34; 1.53.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.52 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.51 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.50 02-Sep-2006  christos branches: 1.50.2; 1.50.4;
comment out unreachable code
 1.49 29-Mar-2006  thorpej Use device_private().
 1.48 25-Mar-2006  thorpej Use device_parent().
 1.47 20-Feb-2006  thorpej branches: 1.47.2; 1.47.4; 1.47.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.46 18-Feb-2006  joerg Change the link status code in MII to use if_link_state_change instead
of calling rt_ifmsg directly. This allows other parts of the kernel
to change the behaviour depending on the link state and is a
prerequirement for CARP.

Hide mii_phy_statusmsg, mii_phy_update should be used instead.
Don't send routing messages for baudrate changes, if_baudrate is
currently not exported via this interface.

OK tls@
 1.45 11-Dec-2005  christos branches: 1.45.2; 1.45.4; 1.45.6;
merge ktrace-lwp.
 1.44 27-Feb-2005  perry branches: 1.44.4;
nuke trailing whitespace
 1.43 23-Aug-2004  thorpej branches: 1.43.4; 1.43.6;
Make use of static.
 1.42 11-Apr-2004  thorpej mii_phy_flowstatus(): short-circuit processing if both sides advertise
symmetric pause capability. From HITOSHI Osada.
 1.41 11-Apr-2004  thorpej Add a comment describing why we force renegotiation when PAUSE is being
used. From HITOSHI Osada.
 1.40 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.39 10-Apr-2004  thorpej gmii_phy_getflowcontrol(): Bail out early if the MAC didn't tell us to
do flow control processing.
 1.38 10-Apr-2004  thorpej Flow-control advertisement and parsing support. From HITOSHI Osada.
Slightly modified by me.
 1.37 10-Sep-2003  briggs It is best to allow a little time for the reset to settle in before
we start polling the BMCR again. Greg Woods noted on tech-net@
that the DP83840A manual states that there should be a 500us delay
between asserting software reset and attempting MII serial operations.

I've also noted that a DP83815 can get into a bad state on cable
removal and reinsertion if we do not delay here.

This may well address PR/16346, and I seem to recall occasional
reports of auto-negotiation and flaky kinds of errors that this
might also alleviate.
 1.36 29-Apr-2003  thorpej branches: 1.36.2;
Use aprint*().
 1.35 20-Feb-2003  matt Add a MIIF_FORCEANEG flag to be passed to mii_attach. This forces an
autonegotiation to take place if IFM_AUTO is selected in mii_media_set.
Make the gem driver use it. (XXX hme probably should use it but I can't
test that).
 1.34 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.33 12-May-2002  thorpej Back out change accidentally committed.
 1.32 10-May-2002  thorpej Make sure ifp->if_baudrate is valid when the parent's statchg
callback is made.

Pointed out by Matt Thomas.
 1.31 07-May-2002  uwe Delint somewhat.
 1.30 13-Nov-2001  lukem add RCSID
 1.29 25-Aug-2001  thorpej ANSI'ify.
 1.28 25-Aug-2001  thorpej For HomePNA PHYs, don't register it w/ ifmedia as 10BASE-T, but
rather as HomePNA1.
 1.27 27-Jul-2001  thorpej Clean up 1000BASE-SX autonegotiation, and add a way to advertise
PAUSE capability.
 1.26 25-Jul-2001  thorpej Fix 1000BASE-X duplex negotiation. That'll teach me to read the
manual more carefully next time.
 1.25 30-Jun-2001  bjh21 branches: 1.25.2;
IFM_1000_TX -> IFM_1000_T, as (breifly) discussed on tech-net.
 1.24 02-Jun-2001  thorpej Make PHY matching all table-driven.
 1.23 31-May-2001  thorpej Enable frobbing the 1000baseT control register on Gig-E PHYs,
used for hard-wiring master mode, and for advertising the 1000baseT
media options during autonegotiation.
 1.22 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.21 30-Apr-2001  thorpej Add code to recognize and set media on GMII (Gigabit MII) PHYs.

802.3 doens't specify ANAR or ANLPAR bits for GMII. Need to
use PHY-specific registers for this, for now, which means we
need specific drivers for the Gigabit-capable PHYs (I think the
most common is the BCM5400).
 1.20 13-Apr-2001  thorpej Remove the use of splimp() from the NetBSD kernel. splnet()
and only splnet() is allowed for the protection of data structures
used by network devices.
 1.19 13-Apr-2001  augustss Add a flag to mii_flags which will cause autonegotiation to use tsleep()
instead of callout. This way adapters which need a process context for
PHY register access (e.g. USB adapters) have a chance.
 1.18 04-Jul-2000  thorpej branches: 1.18.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.17 23-Mar-2000  thorpej branches: 1.17.4;
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.16 15-Mar-2000  thorpej - Go to splimp() when sending the rtsock message regarding link status.
- Would like to notify protocols if a link goes up or down, to e.g.
restart Duplicate Address Detection, etc. Add a comment to this
effect.
 1.15 06-Mar-2000  thorpej Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.14 03-Feb-2000  thorpej Some PHYs go off into left field for a few seconds if you attempt to kick
autonegotiation while it's already enabled.
 1.13 03-Feb-2000  thorpej Oops, missing return;
 1.12 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.11 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.10 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.9 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.8 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.7 03-Nov-1999  thorpej Don't add any loopback versions of media, for now.
 1.6 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.5 03-Aug-1999  drochner branches: 1.5.2; 1.5.4; 1.5.8;
move common support functions for phy drivers from mii.c to mii_physubr.c,
so that they are not includes if no PHY is configured
(avoids code bloat if an interface driver has the "mii" attribute but
mii is not used by the particular version)
 1.4 26-Apr-1999  kleink mii_phy_auto(): don't rely on an implicit declaration of the waitfor argument.
 1.3 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.2 04-Nov-1998  thorpej branches: 1.2.6;
Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.1 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.2.6.1 23-Apr-1999  perry branches: 1.2.6.1.2;
pullup 1.2->1.3 (thorpej): Fix PR7361
 1.2.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.5.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.4.1 15-Nov-1999  fvdl Sync with -current
 1.5.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.5.2.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.17.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.18.2.6 11-Nov-2002  nathanw Catch up to -current
 1.18.2.5 20-Jun-2002  nathanw Catch up to -current.
 1.18.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.18.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.18.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.18.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.25.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.25.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.25.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.25.2.1 03-Aug-2001  lukem update to -current
 1.36.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.36.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.36.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.36.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.36.2.1 03-Aug-2004  skrll Sync with HEAD
 1.43.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.43.4.1 29-Apr-2005  kent sync with -current
 1.44.4.4 17-Mar-2008  yamt sync with head.
 1.44.4.3 21-Jan-2008  yamt sync with head
 1.44.4.2 30-Dec-2006  yamt sync with head.
 1.44.4.1 21-Jun-2006  yamt sync with head.
 1.45.6.1 22-Apr-2006  simonb Sync with head.
 1.45.4.1 09-Sep-2006  rpaulo sync with head
 1.45.2.1 01-Mar-2006  yamt sync with head.
 1.47.6.2 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.47.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.47.4.1 19-Apr-2006  elad sync with head.
 1.47.2.2 03-Sep-2006  yamt sync with head.
 1.47.2.1 01-Apr-2006  yamt sync with head.
 1.50.4.2 10-Dec-2006  yamt sync with head.
 1.50.4.1 22-Oct-2006  yamt sync with head
 1.50.2.1 18-Nov-2006  ad Sync with head.
 1.53.36.1 11-Dec-2007  yamt sync with head.
 1.53.34.1 26-Dec-2007  ad Sync with head.
 1.53.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.53.24.2 23-Mar-2008  matt sync with HEAD
 1.53.24.1 09-Jan-2008  matt sync with HEAD
 1.53.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.53.2.1 12-Jun-2012  sborrill Pull up the following revisions(s) (requested by buhrow in ticket #1448):
sys/dev/mii/mii_physubr.c: revision 1.73 via patch

Make 1000baseT connections work even when the user specifies media 1000baseT
connections with ifconfig(8) rather than only when media auto is specified.
Fixes PR kern/20700.
 1.54.2.3 20-Jan-2008  bouyer Sync with HEAD
 1.54.2.2 10-Jan-2008  bouyer Sync with HEAD
 1.54.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.57.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.57.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.57.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.57.2.1 24-Mar-2008  keiichi sync with head.
 1.58.4.6 09-Oct-2010  yamt sync with head
 1.58.4.5 11-Aug-2010  yamt sync with head.
 1.58.4.4 11-Mar-2010  yamt sync with head
 1.58.4.3 16-May-2009  yamt sync with head
 1.58.4.2 04-May-2009  yamt sync with head.
 1.58.4.1 16-May-2008  yamt sync with head.
 1.58.2.1 18-May-2008  yamt sync with head.
 1.60.10.2 25-Jan-2012  riz Pull up following revision(s) (requested by buhrow in ticket #1701):
sys/dev/mii/mii_physubr.c: revision 1.73
Fixes PR kern/20700 reported by Darcy Cain
Make 1000baset connections work even when the user specifies media 1000baset
connections with ifconfig(8) rather then only when media auto is specified.
For a further discussion of this fix, see:
http://mail-index.NetBSD.org/current-users/2011/12/07/msg018561.html
 1.60.10.1 23-Apr-2009  snj Pull up following revision(s) (requested by sborrill in ticket #715):
sys/dev/mii/mii_physubr.c: revision 1.62
sys/dev/mii/miivar.h: revision 1.53
add mii_anar(). From OpenBSD.
 1.60.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.60.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.60.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.62.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.66.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.66.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.66.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.68.2.2 05-Mar-2011  rmind sync with head
 1.68.2.1 03-Jul-2010  rmind sync with head
 1.72.12.1 18-Feb-2012  mrg merge to -current.
 1.72.8.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.72.8.2 30-Oct-2012  yamt sync with head
 1.72.8.1 17-Apr-2012  yamt sync with head
 1.73.2.2 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.73.2.1 04-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1146):
sys/dev/mii/mii_physubr.c: revision 1.79
sys/dev/mii/rgephy.c: revision 1.33
sys/dev/mii/brgphy.c: revision 1.66
sys/dev/mii/atphy.c: revision 1.15
sys/dev/mii/mii.h: revision 1.17
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.74.2.2 23-Jun-2013  tls resync from head
 1.74.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.80.26.2 21-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1454:

sys/dev/mii/atphy.c 1.22-1.23, 1.25 via patch
sys/dev/mii/mii_physubr.c 1.88 via patch
sys/dev/mii/miivar.h 1.69 via patch

- Fix a bug that atphy(4) can't negotiate correctly when the media
setting is neither auto nor 1000baseT.
- Code cleanup.
 1.80.26.1 30-Dec-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #1149):

sys/dev/mii/mii_physubr.c: revision 1.81
sys/dev/mii/mii_physubr.c: revision 1.82

KNF in comment. No functional change.

-

802.3 22.2.4.1.1 "Reset" says The reset shall be completed in 0.5s, so change
the value from 100ms to 500ms.
 1.81.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.81.4.1 10-Jun-2019  christos Sync with HEAD
 1.81.2.2 26-Jan-2019  pgoyette Sync with HEAD
 1.81.2.1 18-Jan-2019  pgoyette Synch with HEAD
 1.87.4.1 21-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #459):

sys/dev/mii/atphy.c: revision 1.23
sys/dev/mii/atphy.c: revision 1.25
sys/dev/mii/miivar.h: revision 1.69
sys/dev/mii/mii_physubr.c: revision 1.88

s/etphy/atphy/. No functional change.

Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.94.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.101.4.2 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #211):

sys/dev/mii/mii_physubr.c: revision 1.103

Fix a bug when a media is changed to IFM_AUTO.

Fix a bug that ifconfig ifN media auto doesn't change the setting when
the previous media setting used autonego. When the mii_phy_setmedia()
function is called to change the media to IFM_AUTO, the BMCR_AUTOEN bit was
used to check if the previous setting was IFM_AUTO. It's not correct.

IFM_1000_T also uses autonego. So if a previous setting is IFM_1000_T and
the next setting is IFM_AUTO, mii_phy_auto() is not called if neither
MIIF_FORCEANEG nor MIIF_DOPAUSE are set. As a result, after changing
IFM_AUTO, neither 10Mbps nor 100Mbps are not advertised.

Note that almost all drivers uses MIIF_DOPAUSE flags.

TODO: cleanup ciphy.c and rgephy.c. Those have #ifdef foo.
 1.101.4.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.9 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.8 05-Jun-2021  pgoyette Ooopppsss - typo!
 1.7 05-Jun-2021  pgoyette As with usbverbose and pciverbose, these modules are not safe to be
auto-unloaded. Disable for now.

All of these need to be updated with an appropriate refcount mechanism
to ensure that the code and/or tables aren't unloaded while they are
being used.
 1.6 25-Mar-2019  msaitoh branches: 1.6.16; 1.6.20;
Fix compile error when MIIVERBOSE is set. Reported by Kurt Schreiner.
 1.5 25-Mar-2019  msaitoh KNF. No functional change.
 1.4 08-Jan-2019  msaitoh Whitespace fixes. No functional change.
 1.3 25-Jul-2010  pgoyette branches: 1.3.2; 1.3.4; 1.3.62; 1.3.64;
Move setting of mii_verbose_loaded flag into the module's init routine.
This ensures that the flag is set even if the module was manually loaded
by the user rather than just auto-loaded.
 1.2 06-Jun-2010  pgoyette branches: 1.2.2;
Update miiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
 1.1 30-May-2010  pgoyette Extract MIIVERBOSE into a kernel module. The module can be builtin
by defining 'options MIIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.
 1.2.2.3 05-Mar-2011  rmind sync with head
 1.2.2.2 03-Jul-2010  rmind sync with head
 1.2.2.1 06-Jun-2010  rmind file mii_verbose.c was added on branch rmind-uvmplock on 2010-07-03 01:19:36 +0000
 1.3.64.1 10-Jun-2019  christos Sync with HEAD
 1.3.62.1 18-Jan-2019  pgoyette Synch with HEAD
 1.3.4.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.3.4.1 25-Jul-2010  uebayasi file mii_verbose.c was added on branch uebayasi-xip on 2010-08-17 06:46:20 +0000
 1.3.2.2 11-Aug-2010  yamt sync with head.
 1.3.2.1 25-Jul-2010  yamt file mii_verbose.c was added on branch yamt-nfs-mp on 2010-08-11 22:53:40 +0000
 1.6.20.1 06-Jun-2021  cjep sync with head
 1.6.16.2 01-Aug-2021  thorpej Sync with HEAD.
 1.6.16.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.3 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.2 06-Jun-2010  pgoyette branches: 1.2.2; 1.2.4; 1.2.6; 1.2.84;
Update miiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
 1.1 30-May-2010  pgoyette Extract MIIVERBOSE into a kernel module. The module can be builtin
by defining 'options MIIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.
 1.2.84.1 01-Aug-2021  thorpej Sync with HEAD.
 1.2.6.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.2.6.1 06-Jun-2010  uebayasi file mii_verbose.h was added on branch uebayasi-xip on 2010-08-17 06:46:20 +0000
 1.2.4.2 11-Aug-2010  yamt sync with head.
 1.2.4.1 06-Jun-2010  yamt file mii_verbose.h was added on branch yamt-nfs-mp on 2010-08-11 22:53:40 +0000
 1.2.2.2 03-Jul-2010  rmind sync with head
 1.2.2.1 06-Jun-2010  rmind file mii_verbose.h was added on branch rmind-uvmplock on 2010-07-03 01:19:36 +0000
 1.174 23-Oct-2024  skrll Add Motorcomm YT8531 Gigabit PHY
 1.173 06-Oct-2024  msaitoh Add ADMTek.
 1.172 17-Jul-2024  msaitoh miidevs: Add some MaxLinear GPY211 variants, GPY 212 and GPY215.
 1.171 17-Oct-2023  msaitoh branches: 1.171.6;
miidevs: Add MaxLinear GPY115.
 1.170 29-Sep-2023  msaitoh miidevs: Update I22[56]

- Add model 0x0001 and 0x0005 for I226 and 0x000c for I225.
Need more info to write better descriptions.
- Modify GPY211's description a little.
 1.169 29-Sep-2023  msaitoh Add MaxLinear GPY21[125] 2.5G PHY.
 1.168 23-Jun-2020  msaitoh branches: 1.168.20;
Add some Microsemi (Vitesse) devices.
 1.167 08-Apr-2020  msaitoh Add two new RDC PHYs from Andrius V.
 1.166 13-Mar-2020  msaitoh 0x001374 is non-bitreversed value of Attansic OUI(0x00c82e).

Attansic/Atheros correctly uses ID1 and ID2 register, so delete all 0x001374
related entries.
 1.165 13-Mar-2020  msaitoh - Add Quake Technologies and Aeluros' OUI
- Add Teranetics TN1010 10GBase-T PHY
 1.164 27-Feb-2020  msaitoh Use xxVIA instead of VIA.

0x004063 is VIA's official OUI but VT6103 use 0x0002c6.
0x0002c6 is non-bitreversed value of 0x004063. Reported by Andrius V.
 1.163 22-Feb-2020  jmcneill Add BCM54213PE
 1.162 05-Feb-2020  msaitoh Change the OUI macro name of RDC to xxRDC. 0x00d02d is non-bitreverse value
of official 0x000bb4. From Andrius V.
 1.161 06-Nov-2019  msaitoh branches: 1.161.2;
Add Micrel (now Microchip) KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and
KSZ9477.
 1.160 30-Oct-2019  msaitoh - Rename JMICRON 0x0021 from JMC250 to JMP211
- Rename JMICRON 0x0022 from JMC260 to JMP202
 1.159 18-Oct-2019  maya Fix typo. from vezhlys
 1.158 17-Oct-2019  msaitoh - All of Cicada and Vitesse devices' OUI are not bit-reversed, so use "xx".
- Rename CS82xx -> CIS82xx
- Add Vitesse VSC8224, VSC8234, VSC8641 and VSC8501.
 1.157 19-Sep-2019  msaitoh Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3)
 1.156 04-Sep-2019  msaitoh Use uppercase for vendor name.
 1.155 04-Sep-2019  msaitoh Add Teranetics, Aquantia and Renesas.
 1.154 16-Aug-2019  msaitoh From FreeBSD:
- Rename ET1011 to ET1011C
- Add ET1011
 1.153 06-Jun-2019  thorpej branches: 1.153.2;
Add ID for the Broadcom BCM53125 1000BASE-T switch.
 1.152 22-Apr-2019  jmcneill Add Amlogix GXL internal PHY
 1.151 25-Mar-2019  msaitoh Add Bankspeed Pty and NetExcell.
 1.150 25-Mar-2019  msaitoh Remove extra space.
 1.149 15-Mar-2019  msaitoh Add Davicom DM9161, DM9161[ABC] and DM9601.
 1.148 08-Mar-2019  msaitoh Add yyASIX and AX88772* devices.
 1.147 08-Mar-2019  msaitoh Cleanup xx or yy OUIs. Sort by number.
 1.146 08-Mar-2019  msaitoh Fix I82578 OUI. This change only affects to MIIVERBOSE.
See also if_wm.c rev. 1.599.
 1.145 07-Mar-2019  msaitoh Add SMSC(Microchip) LAN911X and LAN75XX.
 1.144 06-Mar-2019  msaitoh Add SMSC(now Microchip) LAN8741A and LAN8742
 1.143 27-Feb-2019  msaitoh - Add SMSC LAN83C185 10/100 PHY from OpenBSD
- Add SMSC LAN8740 10/100 media interface
 1.142 25-Feb-2019  msaitoh Add non-xx'ed DAVICOM DM9101.
 1.141 14-Feb-2019  msaitoh Sort in alphebetical order a bit.
 1.140 13-Feb-2019  msaitoh Change CS8244's OUI from xxCICADA to CICADA. I don't know whether this
change is correct or not...
 1.139 13-Feb-2019  msaitoh - Sort by model number.
- Add missing white space.
 1.138 13-Feb-2019  msaitoh From FreeBSD:
- Add Broadcom BCM540[24], BCM5424, BCM5466 and BCM54[78]8.
- Add ICS1893C.
- Add Micrel KSZ8081 and KSZ9031.
 1.137 13-Feb-2019  msaitoh Sort by model number.
 1.136 13-Feb-2019  msaitoh - Add Tridium, Data Track Technology, Netas, Ralink Technology,
Sunplus Technology and ADMtek's OUI.
- Sort by OUI.
 1.135 13-Feb-2019  msaitoh From OpenBSD:
- Add ASIX OUI.
- Add VIA OUI and devices.
- Add Vitesse OUI and devices.
From FreeBSD:
- Add BROADCOM4.
 1.134 09-Feb-2019  rin Add RTL8201E from OpenBSD.
 1.133 08-Feb-2019  msaitoh - Add Marvell 88E1240.
- Marvell model 0x0029 is not 88E1116R but E1318S.
 1.132 28-Dec-2018  msaitoh 88E154[358] have the same ID.
 1.131 02-Jul-2018  msaitoh - Add ASIX Ax88x9x
- Add description for DP83846A.
 1.130 02-Jul-2018  msaitoh Sort OUI by number. No functional change.
 1.129 19-Jun-2018  msaitoh branches: 1.129.2;
All of 88E151[0248]'s model number is 0x001d.
 1.128 13-Jun-2018  jdolecek add E1000 with model id 0x0006, it exists according to OpenBSD
rename E1000 model 0x0000 to E1000_0 for consistency
 1.127 10-May-2018  msaitoh Add Intel X540 internal PHY.
 1.126 03-Jul-2017  msaitoh branches: 1.126.4;
Add X550 and X557.
 1.125 01-Feb-2017  msaitoh branches: 1.125.6;
Add some Intel devices.
 1.124 14-Aug-2015  knakahara branches: 1.124.2; 1.124.4;
Add Marvell 88E1512.
 1.123 09-Jun-2015  matt Add xxMarvell E6060 6-port 10/100 Fast Ethernet Switch
 1.122 09-Nov-2014  nonaka branches: 1.122.2;
Add Realtek RTL8251.
 1.121 20-Aug-2014  msaitoh BCM5714 and BCM5780 are used for both copper and fiber.
 1.120 02-Jul-2014  msaitoh branches: 1.120.2;
Add BCM5706 1000BASE-T/SX.
 1.119 13-May-2014  christos sync marvel with freebsd.
 1.118 26-Feb-2014  ozaki-r branches: 1.118.2;
Add Micrel PHY (KSZ9021RN)

The new driver micphy is almost same as ukphy except that
micphy has a fixup for cpsw; a PHY with cpsw has to adjust
RGMII signal timing.

Reviewed by christos@
 1.117 21-Dec-2013  kiyohara Add Marvell 88E1543 Quad Port Gb PHY
 1.116 12-Jun-2013  msaitoh branches: 1.116.2;
Add some IC Plus Corp. devices.
 1.115 02-Jun-2013  msaitoh Intel I217 PHY
 1.114 23-Apr-2013  msaitoh Add Intel I210 internal PHY.
 1.113 14-Mar-2013  msaitoh Add BCM5756.
 1.112 20-Feb-2013  msaitoh Add BCM5708S, BCM57780, BCM5717C, BCM5719C and BCM5720C.
 1.111 12-Jan-2013  jakllsch Unlike usbdevs, miidevs needs the vendor name in the product id string.
 1.110 12-Jan-2013  jakllsch Add SMSC OUI and LAN8700 and LAN8710/LAN8720 PHY IDs,
at this point just for MIIVERBOSE.
 1.109 17-Sep-2012  tsutsui Add another Broadcom OUI and BCM57765 1000BASE-T media interface.
Per PR kern/46961.
 1.108 15-Jul-2012  matt branches: 1.108.2;
Add AR8035
 1.107 06-Apr-2012  matt Add VSC8221
 1.106 06-Apr-2012  isaki Sync a comment with a fact.
There is MII_OUI() in miivar.h not mii.h after 2001.
 1.105 25-Nov-2011  jakllsch branches: 1.105.2; 1.105.4;
Add National DP83849. Prompted by PR 41256.
 1.104 12-Nov-2011  sekiya Add support for makphy 0x0029 variation found on most recent Globalscale Dreamplug.
 1.103 02-Nov-2011  jakllsch Add Broadcom BCM5325 and BCM5365.
 1.102 07-Jun-2011  cegger branches: 1.102.2;
add BCM5785
 1.101 28-May-2011  matt branches: 1.101.2;
Fix CS8244 entry (changed to VSC8244).
 1.100 20-May-2011  msaitoh Add Intel 82579
 1.99 26-Jan-2011  bouyer Add RDC Semiconductor R6040 10/100 integrated PHY
 1.98 11-Dec-2010  matt branches: 1.98.2; 1.98.4;
Add two phys (Atheros 8021 and Marvell 88E1145)
 1.97 27-Nov-2010  christos PR/44080: Grégoire Sutre: Support for the i82577 ethernet PHY
 1.96 27-Nov-2010  jym Correct string for BCM5709S.

(Yup, sorry, fix was supposed to be for miidevs and not miidevs.h)
 1.95 02-May-2010  pgoyette Add Broadcom BCM5481 and BCM5709S - From OpenBSD
 1.94 13-Mar-2010  kiyohara branches: 1.94.2;
Add Broadcom BCM5482.
 1.93 24-Jan-2010  msaitoh branches: 1.93.2;
Add BCM5461,BCM5784 and BCM5761.
 1.92 07-Jan-2010  jdc Add NS DP83865.
 1.91 13-Dec-2009  matt Add Marvel 88E1149
 1.90 18-Nov-2009  bouyer Add BCM5709CAX and BCM5709C PHYs.
 1.89 12-Aug-2009  simonb Add Broadcom BCM5464 PHY.
 1.88 18-Jun-2009  rjs Add Marvell 88E1116R PHY.
 1.87 19-Apr-2009  msaitoh Oooops. Back out some of previous my commit.
 1.86 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.85 19-Apr-2009  msaitoh Add some boradcom's PHYs.
Sort.
 1.84 25-Mar-2009  cegger add some CICADA PHYs. from FreeBSD.
 1.83 11-Feb-2009  cegger add ATTANSIC and their L1/L2 PHYs
ok cube@
 1.82 21-Jan-2009  jnemeth branches: 1.82.2;
add a comment explaining how to regenerate miidevs.h and miidevs_data.h
 1.81 16-Jan-2009  cegger add ATHEROS F1 and F2 PHYs
 1.80 27-Dec-2008  tsutsui Fix a botched comment.
 1.79 27-Dec-2008  jnemeth PR/39094 - Kaspar Brand -- Add et (Agere ET1310/ET1301) netowrk driver
 1.78 28-Sep-2008  bouyer branches: 1.78.2; 1.78.4; 1.78.10;
Add JMicron OUI, and JMC2[56]0 PHYs.
 1.77 25-Aug-2008  cegger PR 39241: Add support for Broadcom BCM5906(M) from Karl Uwe Lockhoff
 1.76 28-Apr-2008  martin branches: 1.76.2; 1.76.6;
Remove clause 3 and 4 from TNF licenses
 1.75 20-Feb-2008  markd branches: 1.75.6; 1.75.8; 1.75.10;
Add BCM5708C 1000BASE-T media interface, from FreeBSD
 1.74 29-Dec-2007  wiz Add Marvell 88E1116 Gigabit PHY.
 1.73 12-Oct-2007  tsutsui branches: 1.73.4; 1.73.10;
Add Realtek RTL8211, which has the same ID with 8169S/8110S internal PHY.
 1.72 28-Aug-2007  msaitoh branches: 1.72.2;
add Intel I82566
 1.71 06-Aug-2007  markd branches: 1.71.2; 1.71.4;
Add BCM5755 and 5754 Gig-E PHYs.
 1.70 17-Feb-2007  jmcneill branches: 1.70.4; 1.70.12; 1.70.16;
Add Marvell 88E6060 10/100 5-port PHY switch
 1.69 26-Nov-2006  tsutsui branches: 1.69.2; 1.69.4; 1.69.6;
Add BCM5752 Gig-E PHY. From Matthias Drochner and FreeBSD/OpenBSD.
 1.68 21-Oct-2006  bouyer Add support for the Intel 80003 Gigabit Ethernet controller (found e.g. in
newer server chipsets) to wm(4), from the FreeBSD em(4) driver.
While there, add a few other Intel Ethernet controller that should work as
is.
Properly update the RX error and TX collision counters.
Add ikphy(4), a driver for the Intel i82563 Kumeran 10/100/1000 Ethernet PHYs
 1.67 27-Sep-2006  cube Add Intel 82562G PHY.
 1.66 27-Apr-2006  jonathan branches: 1.66.8; 1.66.10;
Add PHY ID for the integral 1000base-T PHY in the bcm5780 (also known
as Broadcom/Serverworks HT-2000). Following the Broadcom-supplied
Linux driver, update brgphy.c to treat the bcm5780 integral copper PHY
just like the 5714/5715 PHY.

For NetBSB-3 pullup purposes, this commit includes:

src/sys/dev/mii/miidevs revision: 1.65 -> 1.66
src/sys/dev/mii/brgphy.c revision: 1.26 -> 1.27

plus a regen of src/sys/dev/mii/{miidevs.h,miidevs_data.h}.
 1.65 21-Mar-2006  wiz Fix typo, reported by seebs in PR 33106.
 1.64 14-Mar-2006  chs branches: 1.64.2;
add an rlphy clone from IC Plus. from openbsd.
 1.63 18-Feb-2006  thorpej branches: 1.63.2; 1.63.4;
Add the DP83847 PHY. From seebs in kern/32866
 1.62 04-Jan-2006  xtraeme branches: 1.62.2; 1.62.4;
Add Realtek RTL8201L. From OpenBSD
 1.61 08-Dec-2005  jonathan branches: 1.61.2;
Add PHY mii-id for the Broadcom 1000base-T PHY integral to the
bcm5714, added yesterday to sys/dev/pci/if_bge.c in revision 1.98,
since it appears the 5714 has a new PHY revision. Pending further
details, follow the FreeBSD code (as submitted by
John Cagle <john dot cagle at hp dot com> and committed by
ps@FreeBSD.ORG), and treat the 5714 integral PHY the same way as we
treat the bcm5750 integral PHY.
 1.60 28-Aug-2005  kiyohara Add DAVICOM DM9102.
 1.59 23-Jun-2005  briggs branches: 1.59.2;
Marvell 88E1111 from Dave Huang in PR kern/30556
 1.58 16-Mar-2005  briggs branches: 1.58.2;
Add new/alternate OUI for CICADA that's been spotted in a VIA VT6122.
Submitted in PR 29705 from Tomokazu HARADA.
 1.57 20-Feb-2005  jdolecek Add driver for 10/100/1000 copper PHY integrated on VIA Networking Technologies
VT6122 gigabit ethernet chips

From FreeBSD
 1.56 17-Jan-2005  scw branches: 1.56.2;
Add entry for Broadcom BCM5222 Dual 10/100 media interface.
 1.55 23-Dec-2004  jonathan branches: 1.55.2;
Add PHY models for integrated 1000baseT PHYs in Realtek 8169S chips,
in two flavours: one with non-IEEE OUI code from FreeSD if_re(4) mii
driver for early 8169S, and a second IEEE-compliant version as
observed on Netgear GA-511 with newer 8196S stepping.
 1.54 24-Nov-2004  martin Add BCM4401 phy
 1.53 28-Oct-2004  cube Add an entry for the PHY found with BCM575x chips.
 1.52 07-Feb-2004  matt Add LXT973/974/975 PHYs
 1.51 26-Oct-2003  fvdl Make the name of the IGPE1000 a bit clearer.
 1.50 26-Oct-2003  fvdl Add Intel IGP01E1000 phy.
 1.49 17-Jul-2003  hannken Add support for the BCM5705:
- Only BCM5705M asic rev A1 was tested.

Thanks to Bill Paul (wpaul@freebsd.org) for help and support.

Approved by: Frank van der Linden <fvdl@netbsd.org>
 1.48 01-Jul-2003  msaitoh branches: 1.48.2;
Add ICS1889 and 1892
 1.47 02-May-2003  scw Add entry for Broadcom's BCM5214 Quad 10/100 media interface.
 1.46 26-Jan-2003  matt Add AMD Am79C87[45] (which use the Altima OUI).
 1.45 17-Jan-2003  gendalia Add altima (broadcom) AC101L, phy for 3com 3c905cx-tx on nForce2 MCP-T.
 1.44 16-Jan-2003  jonathan Add PHY entry for bcm5704c (copper) integral phy to miidevs.
Add 5704 phy and dsp patch, and untestsed dsp patch for 5703, to brgphy.c.
 1.43 27-Dec-2002  matt Add BCM5703.
 1.42 07-Nov-2002  martin Add MYSON MTD803
 1.41 08-Aug-2002  fvdl Add ID for Marvell 881011 phy found on newer i8254x-based gig-e cards.
 1.40 09-Jul-2002  matt Add Broadcom BCM5421
 1.39 25-Jun-2002  drochner After I found a press release of 1998 which states that AMD sold
Davicom PHY chips, merge the identical entries for DM9101 and Am79c873
into one.
Should also fix PR kern/17369 by Dave Huang.
 1.38 22-Jun-2002  fvdl Aff BCM 5701 PHY Id.
 1.37 15-May-2002  matt branches: 1.37.2; 1.37.4;
Correct/add more PMC-Sierra PHYs
 1.36 15-May-2002  matt Add another PMC-SIERRA phy
 1.35 14-Mar-2002  chs add support for LXT971 PHYs.
 1.34 10-Feb-2002  wiz Add ICS 1893
 1.33 15-Jan-2002  thorpej Add another Marvell 88E1000 PHY model number.
 1.32 15-Dec-2001  augustss Add another Altima PHY. From Peter Seebach.
 1.31 25-Aug-2001  thorpej Back out previous; closer inspection of the manual reveals that the
Am79c874 has the same ID register contents as the AC101.
 1.30 25-Aug-2001  thorpej Add AMD Am79c874 NetPHY-1LP.
 1.29 25-Aug-2001  thorpej Improve the AMD PHY names.
 1.28 23-Aug-2001  thorpej The Am79c972 PCnet-FAST+ has its built-in 10BASE-T interface mapped
onto the MII bus. Recognize it.
 1.27 27-Jul-2001  thorpej Fixup some Broadcom entries, add an entry for Broadcom PHY that
is built-in to some 3Com 3c905B cards.
 1.26 20-Jul-2001  thorpej Bleh, I don't like the way our miidevs works now. Repair the
Marvell Semiconductor entry.
 1.25 12-Jul-2001  thorpej Add LevelOne LXT-1000 10/100/1000 PHY, clean up some Gig-E
PHY names.
 1.24 12-Jul-2001  thorpej Correct Marvell OUI, and 88E1000 model number.
 1.23 19-Jun-2001  thorpej branches: 1.23.2;
Add Seeq 80225 10/100 PHY.
 1.22 31-May-2001  thorpej Add several additional PHYs.
 1.21 31-May-2001  thorpej Add product ID for the NatSemi DP83891 1000baseTX PHY.
 1.20 22-May-2001  soren Add i82562ET id.
 1.19 17-May-2001  drochner argh - the OUI of PMC-Sierra is 00-e0-04, according to IEEE.
They managed to mess it up in a new way.
 1.18 15-May-2001  matt Add OUI for PMC-Sierra. Add BCM5221 Phy. Add PM8351 Phy.
 1.17 15-May-2001  thorpej Add National Semiconductor DP83861 1000baseTX PHY.
 1.16 09-Apr-2001  drochner add media options for the Intel UCH2 internal ethernet controller
 1.15 28-Mar-2001  drochner adapt to corrected OUI calculation
 1.14 07-Jan-2001  augustss branches: 1.14.2;
Add an Altima PHY.
 1.13 07-Nov-2000  soren Just print 'Intel' for their other OUI.
 1.12 06-Nov-2000  augustss Add some OUIs and models. From OpenBSD.
 1.11 08-May-2000  augustss Add another AMD chip.
 1.10 13-Jan-2000  augustss Add a Broadcom PHy used in the D-Link USB100 adapter.
There's no special driver for this PHY (yet).
 1.9 19-Nov-1999  thorpej Add OUI for Enable Semiconductor.
 1.8 07-Sep-1999  soren branches: 1.8.2; 1.8.8;
Note 78Q2121.
 1.7 04-Sep-1999  soren Add Intel 82553 and TSC 78Q2120.
 1.6 14-May-1999  drochner Define OUIs in a more uniform way. OUIs are fixed entities registered
with IEEE, so use the "real" OUIs for definitions.
Now unfortunately vendors differ in how the MII ID register bits are
used wrt bit and byte ordering. There is a straightforward way - bits
numbered from LSB to MSB - used by AMD, Intel, NS and QS. This is used
by the current MII_OUI() conversion macro. ICS, Seeq, SiS and TI count
the bits as they appear on the wire, and some differ completely.
Account for these cases by "xx" prefixed OUI definitions which compensate
for this, so the MII_OUI() macro can still be used.
Add AMD (the "real" AMD this time) and the 79c973 PCnet internal PHY.
 1.5 24-Mar-1999  thorpej branches: 1.5.4;
Silicon Integrated Systems OUI and the SiS 900 PHY model number.
 1.4 05-Feb-1999  thorpej Add oui for Davicom Semiconductor, and add Davicom DM9101 10/100 PHY.
 1.3 05-Nov-1998  thorpej Add AMD's OUI, and the model number for the AMD 79C873 10/100 Ethernet PHY.
 1.2 03-Nov-1998  thorpej Define the model ID of the Seeq 84220 10/100 PHY.
 1.1 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.5.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.8.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.8.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.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.14.2.13 17-Jan-2003  thorpej Sync with HEAD.
 1.14.2.12 29-Dec-2002  thorpej Sync with HEAD.
 1.14.2.11 11-Nov-2002  nathanw Catch up to -current
 1.14.2.10 13-Aug-2002  nathanw Catch up to -current.
 1.14.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.14.2.8 20-Jun-2002  nathanw Catch up to -current.
 1.14.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.14.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.14.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.14.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.14.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.14.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.14.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.23.2.8 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.23.2.7 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.2.6 16-Mar-2002  jdolecek Catch up with -current.
 1.23.2.5 11-Feb-2002  jdolecek Sync w/ -current.
 1.23.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.23.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.23.2.1 03-Aug-2001  lukem update to -current
 1.37.4.3 28-Jan-2003  jmc Pullup revisions 1.42-1.44 (requested by fvdl in ticket #1126)
Pullup support for bge device. (Broadcom Gigabit Ethernet)
 1.37.4.2 16-Nov-2002  he Pull up revision 1.41 (requested by thorpej in ticket #648):
Add ID for Marvell 881011 phy found on newer i8254x-based
gig-ether cards.
 1.37.4.1 12-Jul-2002  thorpej Add Broadcom BCM5421 and BCM5701. Spurred by pullup-1-6 ticket #486
(matt).
 1.37.2.2 29-Aug-2002  gehenna catch up with -current.
 1.37.2.1 15-Jul-2002  gehenna catch up with -current.
 1.48.2.11 11-Dec-2005  christos Sync with head.
 1.48.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.48.2.9 01-Apr-2005  skrll Sync with HEAD.
 1.48.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.48.2.7 24-Jan-2005  skrll Sync with HEAD.
 1.48.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.48.2.5 29-Nov-2004  skrll Sync with HEAD.
 1.48.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.48.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.48.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.48.2.1 03-Aug-2004  skrll Sync with HEAD
 1.55.2.1 29-Apr-2005  kent sync with -current
 1.56.2.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.58.2.7 23-Sep-2007  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1842):
sys/dev/mii/miidevs: revisions 1.69, 1.71
sys/dev/mii/brgphy.c: revisions 1.31 - 1.34
Add support for BCM5752, BCM5754 and BCM5755.
Fix the problem "ifconfig bge0 media auto" negotiates to 100Mbps
on 1000BaseT HUB.
 1.58.2.6 31-Mar-2007  bouyer pullup the following revisions (requested by msaitoh in ticket 1681):
sys/dev/pci/if_wm.c 1.104-1.105, 1.116-1.121,
1.127,1.133-1.134 via patch
sys/dev/pci/if_wmreg.h 1.17-1.20
sys/dev/pci/pcidevs patch
sys/dev/mii/igphy.c 1.11
sys/dev/mii/makphy.c 1.20, 1.23
sys/dev/mii/ikphy.c patch
sys/dev/mii/ikphyreg.h patch
sys/dev/mii/miidevs 1.68
sys/dev/mii/files.mii 1.39
sys/arch/i386/conf/GENERIC 1.788-1.789 via patch
sys/arch/i386/conf/GENERIC.MPACPI patch
sys/arch/i386/conf/GENERIC_LAPTOP 1.209 via patch
sys/arch/i386/conf/INSTALL 1.291 via patch
sys/arch/i386/conf/INSTALL_LAPTOP 1.104 via patch
sys/arch/i386/conf/XEN2_DOM0 1.13 via patch
share/man/man4/wm.4 1.14-1.16
Add support for many cards (include PCI-express based chips).
Many bug fixes about auto negotiations (PR#30078, PR#30490,
PR#30906, PR#33429 and PR#35386).
Fix media link issues with fiber-based card (PR#35797).
 1.58.2.5 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.58.2.4 28-Apr-2006  riz Pull up following revision(s) (requested by jonathan in ticket #1292):
sys/dev/mii/brgphy.c: revision 1.27
sys/dev/mii/miidevs: revision 1.66
Add PHY ID for the integral 1000base-T PHY in the bcm5780 (also known
as Broadcom/Serverworks HT-2000). Following the Broadcom-supplied
Linux driver, update brgphy.c to treat the bcm5780 integral copper PHY
just like the 5714/5715 PHY.
For NetBSB-3 pullup purposes, this commit includes:
src/sys/dev/mii/miidevs revision: 1.65 -> 1.66
src/sys/dev/mii/brgphy.c revision: 1.26 -> 1.27
plus a regen of src/sys/dev/mii/{miidevs.h,miidevs_data.h}.
 1.58.2.3 29-Dec-2005  riz Pull up following revision(s) (requested by jonathan in ticket #1044):
sys/dev/mii/brgphy.c: revision 1.24
sys/dev/mii/miidevs: revision 1.61
Add PHY mii-id for the Broadcom 1000base-T PHY integral to the
bcm5714, added yesterday to sys/dev/pci/if_bge.c in revision 1.98,
since it appears the 5714 has a new PHY revision. Pending further
details, follow the FreeBSD code (as submitted by
John Cagle <john dot cagle at hp dot com> and committed by
ps@FreeBSD.ORG), and treat the 5714 integral PHY the same way as we
treat the bcm5750 integral PHY.
 1.58.2.2 12-Sep-2005  tron Pull up following revision(s) (requested by kiyohara in ticket #760):
sys/dev/mii/dmphy.c: revision 1.21
sys/dev/mii/miidevs: revision 1.60
Add DAVICOM DM9102.
 1.58.2.1 03-Jul-2005  tron Pull up revision 1.59 (requested by briggs in ticket #523):
Marvell 88E1111 from Dave Huang in PR kern/30556
 1.59.2.7 27-Feb-2008  yamt sync with head.
 1.59.2.6 21-Jan-2008  yamt sync with head
 1.59.2.5 27-Oct-2007  yamt sync with head.
 1.59.2.4 03-Sep-2007  yamt sync with head.
 1.59.2.3 26-Feb-2007  yamt sync with head.
 1.59.2.2 30-Dec-2006  yamt sync with head.
 1.59.2.1 21-Jun-2006  yamt sync with head.
 1.61.2.2 18-Feb-2006  yamt sync with head.
 1.61.2.1 15-Jan-2006  yamt sync with head.
 1.62.4.2 01-Jun-2006  kardel Sync with head.
 1.62.4.1 22-Apr-2006  simonb Sync with head.
 1.62.2.1 09-Sep-2006  rpaulo sync with head
 1.63.4.2 11-May-2006  elad sync with head
 1.63.4.1 19-Apr-2006  elad sync with head.
 1.63.2.2 24-May-2006  yamt sync with head.
 1.63.2.1 01-Apr-2006  yamt sync with head.
 1.64.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.64.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.66.10.2 10-Dec-2006  yamt sync with head.
 1.66.10.1 22-Oct-2006  yamt sync with head
 1.66.8.2 12-Jan-2007  ad Sync with head.
 1.66.8.1 18-Nov-2006  ad Sync with head.
 1.69.6.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.69.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.69.2.3 18-Aug-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1342):
sys/dev/pci/if_bge.c: revisions 1.135, 1.146, 1.151-1.152,
1.155-1.167 via patch
sys/dev/pci/if_bgereg.h: revisions 1.43, 1.48-1.52
sys/dev/pci/if_bgevar.h: revision 1.1
sys/dev/mii/brgphy.c: revisions 1.36, 1.40, 1.43-1.44 and
1.47-1.48 via patch
sys/dev/mii/brgphyreg.h: revisions 1.3-1.4
sys/dev/mii/miidevs: revisions 1.75, 1.77, 1.85
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs_data.h: regen
sys/dev/mii/miivar.h: revision 1.54
For bge:
- Really set Tx threshold.
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the "link changed" bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
- Add BCM5786 support.
for brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2, BCM5708C, BCM5722, and BCM5906.
 1.69.2.2 31-Aug-2007  xtraeme Pull up following revision(s) (requested by phil in ticket #819):
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs: revision 1.71
sys/dev/pci/if_bge.c: revision 1.133
sys/dev/pci/if_bge.c: revision 1.134
sys/dev/pci/if_bgereg.h: revision 1.43
sys/dev/mii/brgphy.c: revision 1.34
sys/dev/mii/miidevs_data.h: regen
Add BCM5755 and 5754 Gig-E PHYs.
Regen for BCM5755 and 5754.
Add support for BCM5754 and BCM5755. From suggestions from Jonathan
Stone.
Add a couple more BGE_CHIPIDs
Add support for BCM5755 and BCM5754/5787. Suggestions from Jonathan
Stone and fixes from OpenBSD for various hardware bugs/errata.
Disable firmware fastboot on 5754 and 5755. From FreeBSD by way of Phil
Nelson.
 1.69.2.1 29-Aug-2007  liamjfoy Pull up following revision(s) (requested by masanobu in ticket #850):

sys/dev/pci/if_wm.c 1.137
sys/dev/pci/if_wm.c 1.138
sys/dev/pci/if_wm.c 1.141
sys/dev/pci/if_wm.c 1.144
sys/dev/pci/if_wmreg.h 1.23
sys/dev/pci/pcidevs 1.893
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphy.c 1.12
sys/dev/mii/miidevs 1.72
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/wm.4 1.18

Fix for 82541 and 82547's reset bug.
Modify wm_reset() to make some device stable.
Add ICH9 support to wm.
Add I82566 support to igphy.

Pulled done via patch.
 1.70.16.3 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.70.16.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.70.16.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.70.12.2 03-Sep-2007  skrll Sync with HEAD.
 1.70.12.1 15-Aug-2007  skrll Sync with HEAD.
 1.70.4.3 12-Oct-2007  ad Sync with head.
 1.70.4.2 09-Oct-2007  ad Sync with head.
 1.70.4.1 20-Aug-2007  ad Sync with HEAD.
 1.71.4.2 06-Aug-2007  markd Add BCM5755 and 5754 Gig-E PHYs.
 1.71.4.1 06-Aug-2007  markd file miidevs was added on branch matt-mips64 on 2007-08-06 12:07:01 +0000
 1.71.2.3 23-Mar-2008  matt sync with HEAD
 1.71.2.2 09-Jan-2008  matt sync with HEAD
 1.71.2.1 06-Nov-2007  matt sync with HEAD
 1.72.2.1 14-Oct-2007  yamt sync with head.
 1.73.10.1 02-Jan-2008  bouyer Sync with HEAD
 1.73.4.1 18-Feb-2008  mjf Sync with HEAD.
 1.75.10.6 11-Aug-2010  yamt sync with head.
 1.75.10.5 11-Mar-2010  yamt sync with head
 1.75.10.4 19-Aug-2009  yamt sync with head.
 1.75.10.3 18-Jul-2009  yamt sync with head.
 1.75.10.2 04-May-2009  yamt sync with head.
 1.75.10.1 16-May-2008  yamt sync with head.
 1.75.8.1 18-May-2008  yamt sync with head.
 1.75.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.75.6.3 05-Oct-2008  mjf Sync with HEAD.
 1.75.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.75.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.76.6.1 19-Oct-2008  haad Sync with HEAD.
 1.76.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.76.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.78.10.6 24-Dec-2011  matt Add 88E1114 Phy
 1.78.10.5 20-May-2011  matt One more try to get RCSID correct.
 1.78.10.4 20-May-2011  matt Restore $NetBSD$
 1.78.10.3 20-May-2011  matt Add entry for AR8316 Switch
 1.78.10.2 20-Apr-2010  matt Sync to netbsd-5
 1.78.10.1 09-Nov-2009  cliff - add entry for Marvell 88E1149 Gigabit PHY to miidevs
- regenerate (make) miidevs.h and miidevs_data.h
 1.78.4.6 09-Nov-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1982):
sys/dev/mii/miidevs: revisions 1.79-1.80, 1.84, 1.86-1.88,
1.91-1.92, 1.94-1.96, 1.98-1.99, 1.101-1.112 via patch

Sync miidevs up to rev. 1.112:
- Add Agere ET1101 (PR#39094)
- Add some CICADA PHYs.
- AddMarvell 88E1000[S], 88E1116R, 88E1118, 88E1145, 88E1149[R],
- 88E1543, 88E3016, PHYG65G
- Add NS DP83849(PR#41256), DP83865.
- Add Broadcom BCM5325, BCM5365, BCM548[12], BCM5706, BCM570[89]S,
- BCM571[79]C, BCM5720C, BCM5756, BCM5785, BCM57765, BCM57780
- Add Atheros AR8021, AR8035
- Add RDC Semiconductor R6040 10/100 integrated PHY
- Add Vitesse VSC8221
- Add SMSC LAN 87[012]0
- Add Intel I21[07].
- Add IC Plus IP100, IP1000A and IP1001
- Add Micrel KSZ9021RN
- Add Relatek RTL8251
- Update comment.
 1.78.4.5 19-Jun-2013  bouyer Pullup the following revisions via patch, requested by msaitoh in ticket #1850:
sys/dev/pci/if_wm.c 1.201, 1.203-1.204,
1.207-1.212, 1.215,
1.217-1.218, 1.220-1.223,
1.228, 1.232-245
sys/dev/pci/if_wmreg.h 1.40-1.45, 1.47-1.48
sys/dev/pci/if_wmvar.h 1.11-1.13
sys/dev/pci/pcidevs 1.1074, 1.1077, 1.1117
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphyreg.h 1.6
sys/dev/mii/ihphy.c 1.1-1.2
sys/dev/mii/ihphyreg.h 1.1
sys/dev/mii/inbmphyreg.h 1.3
sys/dev/mii/files.mii 1.47 via patch
sys/dev/mii/miidevs 1.97 and 1.100
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/arch/i386/conf/ALL 1.280
sys/arch/i386/conf/GENERIC 1.1001
sys/arch/i386/conf/INSTALL_FLOPPY 1.11
sys/arch/i386/conf/XEN2_DOM0 patch
sys/arch/amd64/conf/GENERIC 1.293
sys/arch/amd64/conf/XEN3_DOM0 1.61
share/man/man4/wm.4 1.21-1.24

Apply almost all fixes and improvements from netbsd-6 except for
the rev. 1.196's iqdrops' change.

- Add the detach code.
- Add code for WOL, ASF, IPMI and Intel AMT. WOL is disabled by default
- Add Yet another workaround for ICH8.
- 82576 is dual port, so check the FUNCID and increment the MAC address for
the 2nd port.
- Fix the names of 82577L[MC] LAN controllers (for mobile).
- Fix CTRL_EXT_SWDPIN() and CTRL_EXT_SWDPIO() macros. The bit order of the
SW definable pin is not 6543 but 3654!!!
- Rewrite the code to read MAC address from eeprom.
- Add 82580 support.
- 82571 quirk. Only 82571 shares port 0 of EEMNGCTL_CFGDONE.
- The document says that the TDH register must be set after
TCL.EN is set on 82575 and newer devices.
- Fix some register names. No functional change.
- Omit U+00AE "REGISTERED SIGN" in a product name due to its non-ASCII nature.
- Stop wm(4) from needlessly resetting when you add or delete a vlan(4).
- Fix MAC address check on 8257[156] and 80003 case. Some cards have non 0xffff
pointer but those don't use alternative MAC address in reality. So we check
whether the broadcast bit is set or not like Intel's e1000 driver.
Fixes PR kern/44072 reported by Jean-Yves Moulin.
- Add PCH2(and 82579) support. Fixes PR#46487
- Add yet another 82567V support.
- Add ICH10+HANKSVILL support.
- Add support Intel I350 Ethernet.
- Make vlan and all ip/ip6 checksum offload work for the I350.
- Fix compile error with WM_DEBUG.
- Fix a bug that PHY isn't set to low-power mode on PCH and PCH2.
- Add WM_DEBUG_NVM. If WM_DEBUG_NVM is enabled, dump the FLASH ROM data.
- Skip 64bit BAR correctly.
- Fix RAL_TABSIZE for ICH8, 82576, 82580 and I350.
- Use 82580(and I350) specific PHY read/write functions. Fixes PR#47542.
- Style fix. Fix typo in comment. Fix comments. Add comments.
 1.78.4.4 19-Nov-2010  riz branches: 1.78.4.4.2;
Pull up revisions (requested by msaitoh in ticket #1359):
sys/dev/pci/if_bge.c 1.170-1.181
sys/dev/pci/if_bgereg.h 1.53-1.56
sys/dev/pci/if_bgevar.h 1.2-1.5
sys/dev/pci/pcidevs 1.1017, 1.1021
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/miidevs 1.89, 1.93
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
sys/dev/mii/brgphy.c 1.49, 1.52

- Fix a bug of BGE_RDMA_MODE_FIFO_LONG_BURST definition.
- Fix the bug that both BGE_PCIE and BGE_PCIX are set on PCI-Express devices.
- Add support for BCM5705F,BCM5714,SBCM5715S,BCM5717,BCM5718,BCM5720,BCM5723,
BCM5724,BCM5751F,BCM5753F,BCM5756,BCM5761,BCM5761E,BCM5761S,BCM5761SE,
BCM5764,BCM5781,BCM5784M,BCM5903M,BCM57760,BCM57761,BCM57765,BCM57780,
BCM57781,BCM57785,BCM57788,BCM57790,BCM57791 and BCM57795. Fixes PR#41694.
- Fix misunderstanding the capability for TSO4 on some chips.
- Use proplib for no EEPROM systems (e.g. sparc64 with onboard bge).
- Add debug function to show some flags.
- (brgphy(4)) Add support for BCM5461, BCM5464, BCM5784 and BCM5761.
- (brgphy(4)) Enable brgphy_jumbo_settings().
- (brgphy(4)) Enable the Ethernet@Wirespeed function.
- Add support for device properties to override the mac address and set
the BGE_NO_EEPROM flag if we have an onboard device w/o SEEPROM.
- Introduce IPMI and ASF related code from FreeBSD. It fixes some problems
which occured in netboot on sparc64 and PR#32767
- move the code of disabling host interrput in bge_stop() like linux tg3
driver.
- fix the return value of bge_eeprom_getbyte().
- Fixes the bug that error bits arent cleard because these bit are W2C
(in other words W1C).
- Many other bugfixes from FreeBSD and OpenBSD.
- remove an unused structure.
- ANSI C, KNF and tabify
- fix typo in comment.
 1.78.4.3 27-Jan-2010  sborrill Pull up the following revisions(s) (requested by bouyer in ticket #1268):
sys/dev/mii/miidevs: revision 1.90
sys/dev/pci/pcidevs: revision 1.1001
sys/dev/mii/brgphy.c: revision 1.51
sys/dev/microcode/bnx/bnxfw.h: revision 1.3
sys/dev/pci/if_bnx.c: revision 1.29
sys/dev/pci/if_bnxreg.h: revision 1.9
sys/dev/pci/if_bnx.c: revision 1.30

Add support for the Broadcom BCM5709 and BCM5716 chips. Upgrade
the B06 firmware and add the B09 firmware required by the BCM5709.
Replace TX dmamap array with a dynamically-grown list.
Support associated BCM5709CAX and BCM5709C PHYs.
 1.78.4.2 04-Aug-2009  snj Apply patch (requested by msaitoh in ticket #866):
For bge:
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the 'link changed' bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
For brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2 and BCM5722.
 1.78.4.1 03-May-2009  snj Pull up following revision(s) (requested by sborrill in ticket #721):
sys/dev/mii/miidevs: revision 1.81-1.83
Add ATHEROS F1 and F2 PHYs.
Add ATTANSIC and their L1/L2 PHYs.
Add a comment explaining how to regenerate miidevs.h and miidevs_data.h.
 1.78.4.4.2.1 07-Jan-2011  matt Add fresh miidevs from HEAD.
 1.78.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.78.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.78.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.82.2.2 23-Jul-2009  jym Sync with HEAD.
 1.82.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.93.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.93.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.94.2.4 12-Jun-2011  rmind sync with head
 1.94.2.3 31-May-2011  rmind sync with head
 1.94.2.2 05-Mar-2011  rmind sync with head
 1.94.2.1 30-May-2010  rmind sync with head
 1.98.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.98.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.101.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.102.2.5 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.102.2.4 23-Jan-2013  yamt sync with head
 1.102.2.3 30-Oct-2012  yamt sync with head
 1.102.2.2 17-Apr-2012  yamt sync with head
 1.102.2.1 10-Nov-2011  yamt sync with head
 1.105.4.3 07-Dec-2014  martin Pull up the following changes, requested by msaitoh in #1204:
sys/dev/mii/miidevs 1.110-1.111, 1.114-1.118, 1.120-1.122 (patch)

Add some PHYs into miidevs:
- Add SMSC OUI and LAN8700 and LAN8710/LAN8720 PHY IDs.
- Add Intel I210 internal PHY.
- Add Intel I217 PHY.
- Add some IC Plus Corp. devices.
- Add Marvell 88E1543 Quad Port Gb PHY.
- Add Micrel KSZ9021RN.
- Add BCM5706 1000BASE-T/SX.
- BCM5714 and BCM5780 are used for both copper and fiber, so modify the
descriptions.
- Add Realtek RTL8251.
 1.105.4.2 07-Sep-2013  bouyer sys/dev/pci/if_bge.c 1.203-1.237, 1.239-1.241, 1.243-1.258 via patch
sys/dev/pci/if_bgereg.h 1.58-1.74, 1.76-1.83 via patch
sys/dev/pci/if_bgevar.h 1.10-1.16 via patch
sys/dev/pci/pcidevs 1.1149 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/brgphy.c 1.61-1.63, 1.65, 1.67 via patch
sys/dev/mii/miivar.h 1.61 via patch
sys/dev/mii/miidevs 1.112-1.113 via patch
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/bge.4 1.13-1.15 via patch

Add some device support, fix a lot of bugs and add some enahcements.
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F,
BCM5785G, BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- brgphy(4): Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
- Add some bugfixes and enhancement from FreeBSD:
- Workaround for BCM5906 silicon bug. When auto-negotiation results in
half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292)
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785.
(FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf.
(FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC.
(FreeBSD r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems
we have seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
From Linux tg3 driver.
- Sync with *BSD. No functional change:
- make bge_chipid() and use it.
- use switch() instead of a lot of if()s.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case.
Note that {tcp,udp}6csum flag is currently not added in the
capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking. FreeBSD has the same delay().
- Rename PHY related flags for the consistency. It's the same as
FreeBSD.
- Remove BGE_10_100_ONLY flag because this was not used.
For 10/100 devices, when calling mii_attach(), mask BMSR_EXTSTAT
flag to not to check Gigabit flags. It's the same as FreeBSD.
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this commit,
only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK calls MI
mii_phy_auto(). That was not intended.
- Sync with FreeBSD and OpenBSD. Almost the same as OpenBSD rev. 1.325:
- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that
do not have jumbo support
- Wait for the bootcode to complete initialization for 5717 and newer
devices. See BCM5718 programmer's guide's "step 13,
Device reset Procedure, Section7".
57781's document has the same note.
- 5718 and 57785 document say we should wait 100us.
- Change the order of register settings a little to match both
Broadcom's document and Linux tg3.
- Add detach function.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix a bug that the NVRAM lock timeout occured on sparc64 onboard bge.
- Check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd
(OpenBSD rev. 1.327).
- Fix the setting of Tx Random Backoff Register.
- Add BGE_PCIMISCCTL_PCISTATE_RW in BGE_INIT. It's required to set the
PCISTATE register correctly.
- Update comments from 57XX-PG105-R.pdf and 5718-PG106-R.pdf.
- Add missing bus_dmamap_sync() in bge_intr(). The status word is
in DMAed area. Same as other *BSDs.
- Check the hardware config words and print them. This change only
read them and print the values.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind().
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- bge_init_tx_ring() uses BGE_RSLOTS (==256) but bge_free_tx_ring() uses
BGE_TX_RING_CNT (== 512). Delete BGE_RSLOTS and use BGE_TX_RING_CNT.
Same as OpenBSD's if_bge.c rev. 1.86.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Call bge_poll_fw() before writing BGE_MODE_CTL register like the
latest linux tg3 dirver.
- Set DMA watermark depend on the PCI max payload size.
- Add BGE_JUMBO_CAPABLE flag to some chips. With this commit, 5714,
5780, 5717, 5718, 5719 (exclude rev. A0), 5720, 57765 and 57766 are
added to support jumbo frame.
- Fix the setting of sc->bge_flags for 5717 and newer devices.
- Fix a link detect bug on non-autopoll systems. Same as OpenBSD
(rev.1.329 and 1.336) and FreeBSD (r213710).
- 57765 series is not based on 5717 series. 5717 series is based on
57765 series.
- Set the TX DMA segment size based on the MTU size.
- Change the TX ring size for 5717 series and 57764 series.
- For 57766, set BGE_RDMAMODE_JMB_2K_MMRR for non-jumbo frame.
Same as Linux tg3.
- For 57765 and newer devices, set BGE_MAX_RX_FRAME_LOWAT to 1.
This value is recommended by the document.
- Change sysctl related functions for consistency.
- Style change.
- Use macro. Remove duplicated macro. Remove unused variable.
- Fix comments. Add comments.
- Remove extra semicolon. Remove unused code.
[msaitoh, ticket #939]
 1.105.4.1 24-Oct-2012  riz Pull up following revision(s) (requested by msaitoh in ticket #633):
sys/dev/mii/miidevs: revision 1.106
sys/dev/mii/miidevs: revision 1.107
sys/dev/mii/miidevs: revision 1.108
sys/dev/mii/miidevs: revision 1.109
Sync a comment with a fact.
There is MII_OUI() in miivar.h not mii.h after 2001.
Add VSC8221
Add AR8035
Add another Broadcom OUI and BCM57765 1000BASE-T media interface.
Per PR kern/46961.
 1.105.2.1 29-Apr-2012  mrg sync to latest -current.
 1.108.2.5 03-Dec-2017  jdolecek update from HEAD
 1.108.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.108.2.3 23-Jun-2013  tls resync from head
 1.108.2.2 25-Feb-2013  tls resync with head
 1.108.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.116.2.1 18-May-2014  rmind sync with head
 1.118.2.1 10-Aug-2014  tls Rebase.
 1.120.2.3 09-Mar-2017  snj Pull up following revision(s) (requested by msaitoh in ticket #1371):
sys/dev/mii/miidevs: revision 1.125
Add some Intel devices.
 1.120.2.2 09-Dec-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1299):
sys/dev/mii/miidevs: revisions 1.123, 1.124
Add xxMarvell E6060 6-port 10/100 Fast Ethernet Switch
--
Add Marvell 88E1512.
 1.120.2.1 17-Jan-2015  martin branches: 1.120.2.1.4;
Pull up following revision(s) (requested by nonaka in ticket #433):
sys/dev/mii/miidevs: revision 1.121
sys/dev/mii/miidevs: revision 1.122
BCM5714 and BCM5780 are used for both copper and fiber.
Add Realtek RTL8251.
 1.120.2.1.4.2 13-Mar-2017  skrll Sync with netbsd-7-1-RELEASE
 1.120.2.1.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.122.2.3 28-Aug-2017  skrll Sync with HEAD
 1.122.2.2 05-Feb-2017  skrll Sync with HEAD
 1.122.2.1 22-Sep-2015  skrll Sync with HEAD
 1.124.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.124.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.125.6.10 20-Jul-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #1577):
sys/dev/mii/miidevs: revision 1.168
Add some Microsemi (Vitesse) devices.
 1.125.6.9 14-Apr-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1529:

sys/dev/mii/miidevs 1.154, 1.162-1.167
sys/dev/mii/atphy.c 1.28 via patch
sys/dev/mii/brgphy.c 1.87 via patch
sys/dev/mii/etphy.c 1.5, 1.6 via patch
sys/dev/mii/rdcphy.c 1.6, 1.8 via patch

- Add support Broadcom BCM54213PE and some new RDC devices.
- Rename RDC to xxRDC.
- Use xxVIA instead of VIA.
- etphy(4):
- Rename ET1011 to ET1011C and add ET1011 support.
- Use mii_phy_flowstatus() to reflect flow status from negotiated
result.
- Use static.
- KNF.
 1.125.6.8 25-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1457:

sys/dev/mii/miidevs 1.155-1.157, 1.159-1.160
sys/dev/mii/rlphy.c 1.37 via patch

- miidevs update:
- Add Teranetics, Aquantia and Renesas.
- Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3).
- Fix typo. from vezhlys.
- Rename JMICRON 0x0021 from JMC250 to JMP211
- Rename JMICRON 0x0022 from JMC260 to JMP202
- rlphy(4): Print model name if it's ICPLUS IP101 to avoid printing
"Realtek internal PHY".
 1.125.6.7 24-Oct-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1414:

sys/dev/mii/ciphy.c 1.34-1.37 via patch
sys/dev/mii/miidevs 1.158

- Indicate master mode if the negotiated result say so.
- Call mii_phy_flowstatus() to show the flow setting.
- Match a lot of Cicada and Vitesse devices correctly.
- Add support for VSC8221, VSC8234 and VSC8641.
- KNF
 1.125.6.6 01-Aug-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1315):

sys/dev/mii/miidevs: revision 1.151
sys/dev/mii/miidevs: revision 1.152
sys/dev/mii/miidevs: revision 1.153
sys/dev/mii/miidevs: revision 1.145
sys/dev/mii/miidevs: revision 1.146
sys/dev/mii/miidevs: revision 1.147
sys/dev/mii/miidevs: revision 1.148
sys/dev/mii/miidevs: revision 1.149
sys/dev/mii/miidevs: revision 1.150

Add SMSC(Microchip) LAN911X and LAN75XX.

Fix I82578 OUI. This change only affects to MIIVERBOSE.
See also if_wm.c rev. 1.599.

Cleanup xx or yy OUIs. Sort by number.

Add yyASIX and AX88772* devices.

Add Davicom DM9161, DM9161[ABC] and DM9601.

Remove extra space.

Add Bankspeed Pty and NetExcell.

Add Amlogix GXL internal PHY

Add ID for the Broadcom BCM53125 1000BASE-T switch.
 1.125.6.5 07-Mar-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1207):

sys/dev/mii/miidevs: revision 1.140
sys/dev/mii/miidevs: revision 1.141
sys/dev/mii/miidevs: revision 1.142
sys/dev/mii/miidevs: revision 1.143
sys/dev/mii/miidevs: revision 1.144
sys/dev/mii/miidevs: revision 1.133
sys/dev/mii/miidevs: revision 1.134
sys/dev/mii/miidevs: revision 1.135
sys/dev/mii/miidevs: revision 1.136
sys/dev/mii/miidevs: revision 1.137
sys/dev/mii/miidevs: revision 1.138
sys/dev/mii/miidevs: revision 1.139

- Add Marvell 88E1240.
- Marvell model 0x0029 is not 88E1116R but E1318S.

Add RTL8201E from OpenBSD.

From OpenBSD:
- Add ASIX OUI.
- Add VIA OUI and devices.
- Add Vitesse OUI and devices.
From FreeBSD:
- Add BROADCOM4.

- Add Tridium, Data Track Technology, Netas, Ralink Technology,
Sunplus Technology and ADMtek's OUI.

- Sort by OUI.
Sort by model number.

From FreeBSD:
- Add Broadcom BCM540[24], BCM5424, BCM5466 and BCM54[78]8.
- Add ICS1893C.
- Add Micrel KSZ8081 and KSZ9031.

- Sort by model number.

- Add missing white space.

Change CS8244's OUI from xxCICADA to CICADA. I don't know whether this
change is correct or not...
Sort in alphabetical order a bit.
Add non-xx'ed DAVICOM DM9101.

- Add SMSC LAN83C185 10/100 PHY from OpenBSD
- Add SMSC LAN8740 10/100 media interface
Add SMSC(now Microchip) LAN8741A and LAN8742
 1.125.6.4 17-Jan-2019  martin Pull up the following (requested by msaitoh in ticket #1164):

sys/dev/mii/miidevs 1.128, 1.132 (patch)
sys/dev/mii/makphy.c 1.43-1.51
sys/dev/mii/makphyreg.h 1.7-1.9

- miidevs: Add E1000 with model id 0x0006, it exists according to
OpenBSD rename E1000 model 0x0000 to E1000_0 for consistency.
- Match 88E1112, 88E1118, 88E1512, 88E3082 and G65G.
- Match 88E3016 and add some 88E3016 specific code. Fixes part of
PR kern/49270 and PR kern/53301.
- Make sure page 0 is selected when we initialize the PHY. Fixes
problems with the eephy(4) that attaches to nfe(4) on machines like
the Sun Ultra 40. (we had condition for this, now the page 0 is
selected for any PHY type)
- If autonegotiation is not enabled, we need a software reset for the
settings to take effect in makphy_service().
- Don't set PSCR_CRS_ON_TX on newer. Those chips have no this bit.
- Control BMCR_PDOWN for IFM_NONE. Some chips still don't work as
expected. It would be required to modify PSCR and/or other register.
- Set mii_media_active correctly on non-autonego mode.
- Remove obsolete comment.
- Whitespace fix.
 1.125.6.3 04-Dec-2018  martin Pull up following revision(s) (requested by msaitoh in ticket #1116):

sys/dev/mii/miidevs: revision 1.130
sys/dev/mii/miidevs: revision 1.131

Sort OUI by number. No functional change.

- Add ASIX Ax88x9x
- Add description for DP83846A.
 1.125.6.2 26-Jul-2018  snj Pull up following revision(s) (requested by msaitoh in ticket #931):
sys/dev/mii/miidevs: 1.127, 1.129
Add Intel X540 internal PHY.
--
All of 88E151[0248]'s model number is 0x001d.
 1.125.6.1 22-Nov-2017  martin Pull up following revision(s) (requested by msaitoh in ticket #372):
sys/dev/mii/miidevs: revision 1.126
Add X550 and X557.
 1.126.4.4 18-Jan-2019  pgoyette Synch with HEAD
 1.126.4.3 28-Jul-2018  pgoyette Sync with HEAD
 1.126.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.126.4.1 21-May-2018  pgoyette Sync with HEAD
 1.129.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.129.2.1 10-Jun-2019  christos Sync with HEAD
 1.153.2.7 10-Jul-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #990):

sys/dev/mii/miidevs: revision 1.168

Add some Microsemi (Vitesse) devices.
 1.153.2.6 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #831):

sys/dev/mii/rdcphy.c: revision 1.6
sys/dev/mii/rdcphy.c: revision 1.8
sys/dev/mii/miidevs: revision 1.162
sys/dev/mii/miidevs: revision 1.163
sys/dev/mii/miidevs: revision 1.164
sys/dev/mii/miidevs: revision 1.165
sys/dev/mii/miidevs: revision 1.167
sys/dev/mii/brgphy.c: revision 1.87

Change the OUI macro name of RDC to xxRDC. 0x00d02d is non-bitreverse value
of official 0x000bb4. From Andrius V.
RDC -> xxRDC. No functional change.

Add BCM54213PE

Match BCM54213PE

Use xxVIA instead of VIA.
0x004063 is VIA's official OUI but VT6103 use 0x0002c6.
0x0002c6 is non-bitreversed value of 0x004063. Reported by Andrius V.

- Add Quake Technologies and Aeluros' OUI
- Add Teranetics TN1010 10GBase-T PHY
Add two new RDC PHYs from Andrius V.
Add two new RDC PHYs from Andrius V.
 1.153.2.5 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.153.2.4 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #479):

sys/dev/mii/micphy.c: revision 1.9
sys/dev/mii/miidevs: revision 1.161
share/man/man4/micphy.4: revision 1.3

Add Micrel (now Microchip) KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and
KSZ9477.

Add support for KSZ80[0456]1, KSZ8721, KSZ9[01]31, KS8731 and KSZ9477.
It also supports LAN7430's internal PHY. First wrote by nisimura@ and added
some device support by me. Not tested well.
 1.153.2.3 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #473):

sys/dev/mii/rlphy.c: revision 1.37
sys/dev/mii/miidevs: revision 1.155
sys/dev/mii/miidevs: revision 1.156
sys/dev/mii/miidevs: revision 1.157
sys/dev/mii/miidevs: revision 1.159
sys/dev/mii/miidevs: revision 1.160

Add Teranetics, Aquantia and Renesas.

Use uppercase for vendor name.

Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3)
- ICPLUS -> xxICPLUS
- Print model name if it's ICPLUS IP101 to avoid "Realtek internal PHY".

Fix typo. from vezhlys
- Rename JMICRON 0x0021 from JMC250 to JMP211
- Rename JMICRON 0x0022 from JMC260 to JMP202
 1.153.2.2 23-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #372):

sys/dev/mii/miidevs: revision 1.158
sys/dev/mii/ciphy.c: revision 1.37

- All of Cicada and Vitesse devices' OUI are not bit-reversed, so use "xx".
- Rename CS82xx -> CIS82xx
- Add Vitesse VSC8224, VSC8234, VSC8641 and VSC8501.
- Match a lot of Cicada and Vitesse devices correctly. This change also fixes
a bug that ciphy_fixup() didn't work.
- Match VSC8221, VSC8234 and VSC8641.
 1.153.2.1 01-Sep-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #144):

sys/dev/mii/miidevs: revision 1.154
sys/dev/mii/etphy.c: revision 1.5
sys/dev/mii/etphy.c: revision 1.6

No functional change:
- Use static.
- KNF.

From FreeBSD:
- Rename ET1011 to ET1011C
- Add ET1011

From FreeBSD:
- Support ET1011.
- Use mii_phy_flowstatus() to reflect flow status from negotiated result.
 1.161.2.1 29-Feb-2020  ad Sync with head.
 1.168.20.1 20-Jun-2024  martin Pull up following revision(s) (requested by msaitoh in ticket #712):

sys/dev/mii/miidevs: revision 1.170
sys/dev/mii/miidevs: revision 1.171
sys/dev/mii/miidevs: revision 1.169

Add MaxLinear GPY21[125] 2.5G PHY.

miidevs: Update I22[56]
- Add model 0x0001 and 0x0005 for I226 and 0x000c for I225.
Need more info to write better descriptions.
- Modify GPY211's description a little.

miidevs: Add MaxLinear GPY115.
 1.171.6.1 02-Aug-2025  perseant Sync with HEAD
 1.172 23-Oct-2024  skrll regen
 1.171 06-Oct-2024  msaitoh Regen.
 1.170 17-Jul-2024  msaitoh miidevs: regen.
 1.169 17-Oct-2023  msaitoh branches: 1.169.6;
miidevs: Regen.
 1.168 29-Sep-2023  msaitoh Regen.
 1.167 29-Sep-2023  msaitoh Regen.
 1.166 29-Jun-2021  pgoyette branches: 1.166.10;
Regen for new sys/dev/devlist2h.awk
 1.165 23-Jun-2020  msaitoh branches: 1.165.6;
Regen.
 1.164 08-Apr-2020  msaitoh Regen.
 1.163 13-Mar-2020  msaitoh Regen.
 1.162 27-Feb-2020  msaitoh Regen.
 1.161 22-Feb-2020  jmcneill regen
 1.160 05-Feb-2020  msaitoh Regen.
 1.159 06-Nov-2019  msaitoh branches: 1.159.2;
Regen.
 1.158 30-Oct-2019  msaitoh Regen.
 1.157 18-Oct-2019  maya Fix typo. from vezhlys
 1.156 17-Oct-2019  msaitoh Regen.
 1.155 19-Sep-2019  msaitoh Regen.
 1.154 04-Sep-2019  msaitoh Regen.
 1.153 04-Sep-2019  msaitoh Regen.
 1.152 16-Aug-2019  msaitoh Regen.
 1.151 06-Jun-2019  thorpej branches: 1.151.2;
Regen for addition of BCM53125 switch.
 1.150 22-Apr-2019  jmcneill regen
 1.149 25-Mar-2019  msaitoh Regen.
 1.148 25-Mar-2019  msaitoh Regen.
 1.147 15-Mar-2019  msaitoh Regen.
 1.146 08-Mar-2019  msaitoh Regen.
 1.145 08-Mar-2019  msaitoh Regen.
 1.144 07-Mar-2019  msaitoh Regen.
 1.143 06-Mar-2019  msaitoh Regen.
 1.142 27-Feb-2019  msaitoh Regen.
 1.141 25-Feb-2019  msaitoh Regen.
 1.140 13-Feb-2019  msaitoh regen.
 1.139 13-Feb-2019  msaitoh Regen.
 1.138 13-Feb-2019  msaitoh Regen.
 1.137 09-Feb-2019  rin regen
 1.136 08-Feb-2019  msaitoh Regen.
 1.135 28-Dec-2018  msaitoh Regen.
 1.134 02-Jul-2018  msaitoh Regen.
 1.133 02-Jul-2018  msaitoh Regen.
 1.132 19-Jun-2018  msaitoh branches: 1.132.2;
Regen.
 1.131 13-Jun-2018  jdolecek regen
 1.130 10-May-2018  msaitoh Regen.
 1.129 03-Jul-2017  msaitoh branches: 1.129.4;
Regen.
 1.128 01-Feb-2017  msaitoh branches: 1.128.6;
regen.
 1.127 14-Aug-2015  knakahara branches: 1.127.2; 1.127.4;
regen
 1.126 09-Jun-2015  matt Regen.
 1.125 09-Nov-2014  riz branches: 1.125.2;
Commit forgotten regenerated file.
 1.124 20-Aug-2014  msaitoh Regen.
 1.123 02-Jul-2014  msaitoh branches: 1.123.2;
Regen.
 1.122 13-May-2014  christos regen
 1.121 26-Feb-2014  ozaki-r branches: 1.121.2;
Regen.
 1.120 21-Dec-2013  kiyohara Regen.
 1.119 12-Jun-2013  msaitoh branches: 1.119.2;
regen.
 1.118 02-Jun-2013  msaitoh regen
 1.117 23-Apr-2013  msaitoh regen.
 1.116 14-Mar-2013  msaitoh Regen.
 1.115 20-Feb-2013  msaitoh regen.
 1.114 12-Jan-2013  jakllsch regen
 1.113 12-Jan-2013  jakllsch regen.
 1.112 17-Sep-2012  tsutsui Regen from miidevs rev 1.109:
> Add another Broadcom OUI and BCM57765 1000BASE-T media interface.
> Per PR kern/46961.
 1.111 15-Jul-2012  matt branches: 1.111.2;
Regen.
 1.110 06-Apr-2012  matt Regen.
 1.109 06-Apr-2012  isaki Regen from miidevs,v 1.106; sync a comment with a fact.
 1.108 25-Nov-2011  jakllsch branches: 1.108.2; 1.108.4;
regen. (PR 41256)
 1.107 12-Nov-2011  sekiya Regen.
 1.106 02-Nov-2011  jakllsch regen.
 1.105 07-Jun-2011  cegger branches: 1.105.2;
regen.
 1.104 28-May-2011  matt branches: 1.104.2;
Regen.
 1.103 20-May-2011  msaitoh regen
 1.102 26-Jan-2011  bouyer Regen: Add RDC Semiconductor R6040 10/100 integrated PHY
 1.101 11-Dec-2010  matt branches: 1.101.2; 1.101.4;
Regen.
 1.100 27-Nov-2010  christos regen
 1.99 27-Nov-2010  jym regen.
 1.98 27-Nov-2010  jym Correct string for BCM5709S.
 1.97 02-May-2010  pgoyette Regen
 1.96 13-Mar-2010  kiyohara branches: 1.96.2;
Regen.
 1.95 24-Jan-2010  msaitoh branches: 1.95.2;
regen.
 1.94 07-Jan-2010  jdc Regenerate for:
Add NS DP83865
 1.93 14-Dec-2009  enami Regen so that makphy.c compiles.
 1.92 18-Nov-2009  bouyer Regen: Add BCM5709CAX and BCM5709C PHYs.
 1.91 12-Aug-2009  simonb Regen.
 1.90 18-Jun-2009  rjs Regen.
 1.89 19-Apr-2009  msaitoh regen.
 1.88 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.87 19-Apr-2009  msaitoh regen
 1.86 25-Mar-2009  cegger regen.
 1.85 11-Feb-2009  cegger regen.
 1.84 16-Jan-2009  cegger branches: 1.84.2;
regen
 1.83 27-Dec-2008  tsutsui Regen from miidevs rev 1.80:
> Fix a botched comment.
 1.82 27-Dec-2008  jnemeth regen for et (Agere) driver
 1.81 28-Sep-2008  bouyer branches: 1.81.2; 1.81.4; 1.81.10;
Regen: Add JMicron OUI, and JMC2[56]0 PHYs.
 1.80 25-Aug-2008  cegger regen. for PR 39241: Add support for Broadcom BCM5906(M) from Karl Uwe Lockhoff
 1.79 28-Apr-2008  martin branches: 1.79.2; 1.79.6;
Remove clause 3 and 4 from TNF licenses
 1.78 20-Feb-2008  markd branches: 1.78.6; 1.78.8; 1.78.10;
regen.
 1.77 29-Dec-2007  wiz regen (+ Marvell 88E1116 Gigabit PHY)
 1.76 12-Oct-2007  tsutsui branches: 1.76.4; 1.76.10;
Regen from miidevs rev 1.73:
> Add Realtek RTL8211, which has the same ID with 8169S/8110S internal PHY.
 1.75 28-Aug-2007  msaitoh branches: 1.75.2;
regen
 1.74 06-Aug-2007  markd branches: 1.74.2; 1.74.4;
Regen for BCM5755 and 5754.
 1.73 17-Feb-2007  jmcneill branches: 1.73.4; 1.73.12; 1.73.16;
Regen.
 1.72 26-Nov-2006  tsutsui branches: 1.72.2; 1.72.4; 1.72.6;
Regen from miidevs rev 1.69:
> Add BCM5752 Gig-E PHY. From Matthias Drochner and FreeBSD/OpenBSD.
 1.71 21-Oct-2006  bouyer Regen: addded i82563 PHY
 1.70 27-Sep-2006  cube Regen (Intel 82562G).
 1.69 27-Apr-2006  jonathan branches: 1.69.8; 1.69.10;
regen sys/dev/mii/miidevs{,_data}.h from miidevs 1.66 after addition
of PHY ID for BCM5780 (serverworks HT-2000) integral 1000base-T PHY.
 1.68 21-Mar-2006  wiz regen.
 1.67 14-Mar-2006  chs branches: 1.67.2;
regen
 1.66 18-Feb-2006  thorpej branches: 1.66.2; 1.66.4;
Add the DP83847 PHY. From seebs in kern/32866
 1.65 04-Jan-2006  xtraeme branches: 1.65.2; 1.65.4;
regen
 1.64 08-Dec-2005  soren branches: 1.64.2;
Regen.
 1.63 28-Aug-2005  kiyohara Fix misstake regen.
 1.62 28-Aug-2005  kiyohara regen.
 1.61 23-Jun-2005  briggs branches: 1.61.2;
Regen for Marvell 88E1111
 1.60 16-Mar-2005  briggs branches: 1.60.2;
regen for xxCICADA 8201B
 1.59 27-Feb-2005  perry regen
 1.58 20-Feb-2005  jdolecek regen: Cicada PHY addition
 1.57 17-Jan-2005  scw branches: 1.57.2;
Regen for Broadcom BCM5222.
 1.56 23-Dec-2004  jonathan branches: 1.56.2;
Regen from miidevs rev 1.55, with codes for Realtek RTK8169S builtin PHY.
 1.55 24-Nov-2004  martin Regen (BCM4401 added)
 1.54 28-Oct-2004  cube Regen.
 1.53 07-Feb-2004  matt Regen.
 1.52 26-Oct-2003  fvdl Regen after clarifying IGPE1000 name.
 1.51 26-Oct-2003  fvdl Regen after adding IGP01E1000.
 1.50 17-Jul-2003  hannken Regen.
 1.49 17-Jul-2003  hannken Add support for the BCM5705:
- Only BCM5705M asic rev A1 was tested.

Thanks to Bill Paul (wpaul@freebsd.org) for help and support.

Approved by: Frank van der Linden <fvdl@netbsd.org>
 1.48 01-Jul-2003  msaitoh branches: 1.48.2;
Add ICS1889 and 1892
 1.47 02-May-2003  scw Regen
 1.46 26-Jan-2003  matt Regen.
 1.45 17-Jan-2003  gendalia regenerate to match miidevs, added ac101L phy
 1.44 16-Jan-2003  jonathan regen machine-generated files from miidevs rev 1.44 (bcm5704 phy)
 1.43 27-Dec-2002  matt Regen.
 1.42 07-Nov-2002  martin Regen (MYSON MTD803 added)
 1.41 08-Aug-2002  fvdl Regen after addition of marvell 881011.
 1.40 09-Jul-2002  matt Regen.
 1.39 25-Jun-2002  drochner regen
 1.38 22-Jun-2002  fvdl Regen.
 1.37 15-May-2002  matt branches: 1.37.2; 1.37.4;
Regen.
 1.36 15-May-2002  matt Regen.
 1.35 14-Mar-2002  chs regen
 1.34 10-Feb-2002  wiz Regen [ICS 1893]
 1.33 15-Jan-2002  thorpej Regen; add another Marvell 88E1000 PHY model number.
 1.32 15-Dec-2001  augustss Regen.
 1.31 25-Aug-2001  thorpej Regen.
 1.30 25-Aug-2001  thorpej Regen; added AMD Am79c874 NetPHY-1LP.
 1.29 25-Aug-2001  thorpej Regen; improve AMD PHY names.
 1.28 23-Aug-2001  thorpej Regen; recognize the 79c972's 10BASE-T interface mapped onto MII.
 1.27 27-Jul-2001  thorpej Regen; added a 3Com 3c905B internal PHY made by Broadcom.
 1.26 20-Jul-2001  thorpej Regen.
 1.25 12-Jul-2001  thorpej Regen; Add LXT-1000, clean up.
 1.24 12-Jul-2001  thorpej Regen; corrected Marvell entries.
 1.23 19-Jun-2001  thorpej branches: 1.23.2;
Regen; added Seeq 80225 10/100 PHY.
 1.22 31-May-2001  thorpej Regen; added several more PHYs.
 1.21 31-May-2001  thorpej Regen; added NatSemi DP83891.
 1.20 22-May-2001  soren Regen.
 1.19 17-May-2001  drochner regen
 1.18 15-May-2001  matt Regen
 1.17 15-May-2001  thorpej Regen; Add National Semiconductor DP83861 1000baseTX PHY.
 1.16 09-Apr-2001  drochner regen
 1.15 28-Mar-2001  drochner regen
 1.14 07-Jan-2001  augustss branches: 1.14.2;
Regen.
 1.13 07-Nov-2000  soren Regen.
 1.12 06-Nov-2000  augustss Regen.
 1.11 08-May-2000  augustss Regen.
 1.10 13-Jan-2000  augustss Regen.
 1.9 19-Nov-1999  thorpej Regen.
 1.8 07-Sep-1999  soren branches: 1.8.2; 1.8.8;
Note 78Q2121.
 1.7 04-Sep-1999  soren Regenerate.
 1.6 14-May-1999  drochner regen
 1.5 24-Mar-1999  thorpej branches: 1.5.4;
Regen.
 1.4 05-Feb-1999  thorpej Regen.
 1.3 05-Nov-1998  thorpej Regen.
 1.2 03-Nov-1998  thorpej Regen.
 1.1 10-Aug-1998  thorpej Initial generation.
 1.5.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.2.4 21-Apr-2001  bouyer Sync with HEAD
 1.8.2.3 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.8.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.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.14.2.13 17-Jan-2003  thorpej Sync with HEAD.
 1.14.2.12 29-Dec-2002  thorpej Sync with HEAD.
 1.14.2.11 11-Nov-2002  nathanw Catch up to -current
 1.14.2.10 13-Aug-2002  nathanw Catch up to -current.
 1.14.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.14.2.8 20-Jun-2002  nathanw Catch up to -current.
 1.14.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.14.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.14.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.14.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.14.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.14.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.14.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.23.2.8 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.23.2.7 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.2.6 16-Mar-2002  jdolecek Catch up with -current.
 1.23.2.5 11-Feb-2002  jdolecek Sync w/ -current.
 1.23.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.23.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.23.2.1 03-Aug-2001  lukem update to -current
 1.37.4.3 28-Jan-2003  jmc Regen (requested by fvdl in ticket #1126)
Pullup support for bge device. (Broadcom Gigabit Ethernet)
 1.37.4.2 16-Nov-2002  he Pull up regenerated files (requested by thorpej in ticket #648):
Add ID for Marvell 881011 phy found on newer i8254x-based
gig-ether cards.
 1.37.4.1 12-Jul-2002  thorpej Regenerate. pullup-1-6 ticket #486.
 1.37.2.2 29-Aug-2002  gehenna catch up with -current.
 1.37.2.1 15-Jul-2002  gehenna catch up with -current.
 1.48.2.11 11-Dec-2005  christos Sync with head.
 1.48.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.48.2.9 01-Apr-2005  skrll Sync with HEAD.
 1.48.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.48.2.7 24-Jan-2005  skrll Sync with HEAD.
 1.48.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.48.2.5 29-Nov-2004  skrll Sync with HEAD.
 1.48.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.48.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.48.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.48.2.1 03-Aug-2004  skrll Sync with HEAD
 1.56.2.1 29-Apr-2005  kent sync with -current
 1.57.2.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.60.2.7 23-Sep-2007  bouyer Regen for ticket #1842
 1.60.2.6 31-Mar-2007  bouyer regen for ticket 1681
 1.60.2.5 03-Mar-2007  bouyer regen for ticket #1673
 1.60.2.4 28-Apr-2006  riz Regen for ticket 1292.
 1.60.2.3 29-Dec-2005  riz Regen for ticket 1044.
 1.60.2.2 12-Sep-2005  tron Regen for ticket #760.
 1.60.2.1 04-Jul-2005  tron Regen for ticket 524,
 1.61.2.7 27-Feb-2008  yamt sync with head.
 1.61.2.6 21-Jan-2008  yamt sync with head
 1.61.2.5 27-Oct-2007  yamt sync with head.
 1.61.2.4 03-Sep-2007  yamt sync with head.
 1.61.2.3 26-Feb-2007  yamt sync with head.
 1.61.2.2 30-Dec-2006  yamt sync with head.
 1.61.2.1 21-Jun-2006  yamt sync with head.
 1.64.2.2 18-Feb-2006  yamt sync with head.
 1.64.2.1 15-Jan-2006  yamt sync with head.
 1.65.4.2 01-Jun-2006  kardel Sync with head.
 1.65.4.1 22-Apr-2006  simonb Sync with head.
 1.65.2.1 09-Sep-2006  rpaulo sync with head
 1.66.4.2 11-May-2006  elad sync with head
 1.66.4.1 19-Apr-2006  elad sync with head.
 1.66.2.2 24-May-2006  yamt sync with head.
 1.66.2.1 01-Apr-2006  yamt sync with head.
 1.67.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.67.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.69.10.2 10-Dec-2006  yamt sync with head.
 1.69.10.1 22-Oct-2006  yamt sync with head
 1.69.8.2 12-Jan-2007  ad Sync with head.
 1.69.8.1 18-Nov-2006  ad Sync with head.
 1.72.6.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.72.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.72.2.3 18-Aug-2009  bouyer Regen for ticket 1342
 1.72.2.2 31-Aug-2007  xtraeme regen for ticket #819
 1.72.2.1 29-Aug-2007  liamjfoy Pull up following revision(s) (requested by masanobu in ticket #850):

sys/dev/pci/if_wm.c 1.137
sys/dev/pci/if_wm.c 1.138
sys/dev/pci/if_wm.c 1.141
sys/dev/pci/if_wm.c 1.144
sys/dev/pci/if_wmreg.h 1.23
sys/dev/pci/pcidevs 1.893
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphy.c 1.12
sys/dev/mii/miidevs 1.72
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/wm.4 1.18

Fix for 82541 and 82547's reset bug.
Modify wm_reset() to make some device stable.
Add ICH9 support to wm.
Add I82566 support to igphy.

Pulled done via patch.
 1.73.16.3 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.73.16.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.73.16.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.73.12.2 03-Sep-2007  skrll Sync with HEAD.
 1.73.12.1 15-Aug-2007  skrll Sync with HEAD.
 1.73.4.3 12-Oct-2007  ad Sync with head.
 1.73.4.2 09-Oct-2007  ad Sync with head.
 1.73.4.1 20-Aug-2007  ad Sync with HEAD.
 1.74.4.2 06-Aug-2007  markd Regen for BCM5755 and 5754.
 1.74.4.1 06-Aug-2007  markd file miidevs.h was added on branch matt-mips64 on 2007-08-06 12:09:27 +0000
 1.74.2.3 23-Mar-2008  matt sync with HEAD
 1.74.2.2 09-Jan-2008  matt sync with HEAD
 1.74.2.1 06-Nov-2007  matt sync with HEAD
 1.75.2.1 14-Oct-2007  yamt sync with head.
 1.76.10.1 02-Jan-2008  bouyer Sync with HEAD
 1.76.4.1 18-Feb-2008  mjf Sync with HEAD.
 1.78.10.6 11-Aug-2010  yamt sync with head.
 1.78.10.5 11-Mar-2010  yamt sync with head
 1.78.10.4 19-Aug-2009  yamt sync with head.
 1.78.10.3 18-Jul-2009  yamt sync with head.
 1.78.10.2 04-May-2009  yamt sync with head.
 1.78.10.1 16-May-2008  yamt sync with head.
 1.78.8.1 18-May-2008  yamt sync with head.
 1.78.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.78.6.3 05-Oct-2008  mjf Sync with HEAD.
 1.78.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.78.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.79.6.1 19-Oct-2008  haad Sync with HEAD.
 1.79.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.79.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.81.10.4 24-Dec-2011  matt Regen.
 1.81.10.3 20-May-2011  matt Regen.
 1.81.10.2 21-Apr-2010  matt sync to netbsd-5
 1.81.10.1 09-Nov-2009  cliff - add entry for Marvell 88E1149 Gigabit PHY to miidevs
- regenerate (make) miidevs.h and miidevs_data.h
 1.81.4.6 09-Nov-2015  sborrill Regen
 1.81.4.5 19-Jun-2013  bouyer Regen for ticket #1850
 1.81.4.4 19-Nov-2010  riz branches: 1.81.4.4.2;
Regen for ticket 1359.
 1.81.4.3 27-Jan-2010  sborrill Regen
 1.81.4.2 04-Aug-2009  snj Regen for ticket 866.
 1.81.4.1 03-May-2009  snj Regen for ticket 721.
 1.81.4.4.2.1 07-Jan-2011  matt Regen.
 1.81.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.81.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.81.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.84.2.2 23-Jul-2009  jym Sync with HEAD.
 1.84.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.95.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.95.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.96.2.4 12-Jun-2011  rmind sync with head
 1.96.2.3 31-May-2011  rmind sync with head
 1.96.2.2 05-Mar-2011  rmind sync with head
 1.96.2.1 30-May-2010  rmind sync with head
 1.101.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.101.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.104.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.105.2.5 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.105.2.4 23-Jan-2013  yamt sync with head
 1.105.2.3 30-Oct-2012  yamt sync with head
 1.105.2.2 17-Apr-2012  yamt sync with head
 1.105.2.1 10-Nov-2011  yamt sync with head
 1.108.4.3 07-Dec-2014  martin regen
 1.108.4.2 07-Sep-2013  bouyer regen for ticket 939
 1.108.4.1 24-Oct-2012  riz Regen for ticket 633.
 1.108.2.1 29-Apr-2012  mrg sync to latest -current.
 1.111.2.5 03-Dec-2017  jdolecek update from HEAD
 1.111.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.111.2.3 23-Jun-2013  tls resync from head
 1.111.2.2 25-Feb-2013  tls resync with head
 1.111.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.119.2.1 18-May-2014  rmind sync with head
 1.121.2.1 10-Aug-2014  tls Rebase.
 1.123.2.3 09-Mar-2017  snj regen for ticket 1371
 1.123.2.2 09-Dec-2016  snj regen for ticket 1299
 1.123.2.1 17-Jan-2015  martin branches: 1.123.2.1.4;
Regen (Ticket #433)
 1.123.2.1.4.2 13-Mar-2017  skrll Sync with netbsd-7-1-RELEASE
 1.123.2.1.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.125.2.3 28-Aug-2017  skrll Sync with HEAD
 1.125.2.2 05-Feb-2017  skrll Sync with HEAD
 1.125.2.1 22-Sep-2015  skrll Sync with HEAD
 1.127.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.127.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.128.6.10 20-Jul-2020  martin regen for ticket #1577
 1.128.6.9 14-Apr-2020  martin Regen for ticket #1529
 1.128.6.8 25-Nov-2019  martin Regen for ticket #1457
 1.128.6.7 24-Oct-2019  martin Regen for ticket #1414
 1.128.6.6 01-Aug-2019  martin regen for ticket #1315
 1.128.6.5 07-Mar-2019  martin Regen for ticket #1207
 1.128.6.4 17-Jan-2019  martin regen (ticket #1164)
 1.128.6.3 04-Dec-2018  martin Regen for ticket #1116
 1.128.6.2 26-Jul-2018  snj regen for ticket 931
 1.128.6.1 22-Nov-2017  martin regen
 1.129.4.4 18-Jan-2019  pgoyette Synch with HEAD
 1.129.4.3 28-Jul-2018  pgoyette Sync with HEAD
 1.129.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.129.4.1 21-May-2018  pgoyette Sync with HEAD
 1.132.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.132.2.1 10-Jun-2019  christos Sync with HEAD
 1.151.2.8 10-Jul-2020  martin Regen for ticket #990
 1.151.2.7 14-Apr-2020  martin Regen for ticket #831
 1.151.2.6 19-Mar-2020  martin Regen (for ticket #786)
 1.151.2.5 25-Nov-2019  martin Regen for ticket 479
 1.151.2.4 25-Nov-2019  martin Regen for ticket 479
 1.151.2.3 25-Nov-2019  martin Regen for ticket #473
 1.151.2.2 23-Oct-2019  martin Regen for ticket #372
 1.151.2.1 02-Sep-2019  martin regen (for ticket #144, also requested in ticket #171)
 1.159.2.1 29-Feb-2020  ad Sync with head.
 1.165.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.166.10.1 20-Jun-2024  martin Regen for ticket #712
 1.169.6.1 02-Aug-2025  perseant Sync with HEAD
 1.161 23-Oct-2024  skrll regen
 1.160 06-Oct-2024  msaitoh Regen.
 1.159 17-Jul-2024  msaitoh miidevs: regen.
 1.158 17-Oct-2023  msaitoh branches: 1.158.6;
miidevs: Regen.
 1.157 29-Sep-2023  msaitoh Regen.
 1.156 29-Sep-2023  msaitoh Regen.
 1.155 29-Jun-2021  pgoyette branches: 1.155.10;
Regen for new sys/dev/devlist2h.awk
 1.154 03-Aug-2020  uwe branches: 1.154.6;
mii_knowndevs[] is de facto const, define it as such.
 1.153 23-Jun-2020  msaitoh Regen.
 1.152 08-Apr-2020  msaitoh Regen.
 1.151 13-Mar-2020  msaitoh Regen.
 1.150 27-Feb-2020  msaitoh Regen.
 1.149 22-Feb-2020  jmcneill regen
 1.148 05-Feb-2020  msaitoh Regen.
 1.147 06-Nov-2019  msaitoh branches: 1.147.2;
Regen.
 1.146 30-Oct-2019  msaitoh Regen.
 1.145 18-Oct-2019  maya Fix typo. from vezhlys
 1.144 17-Oct-2019  msaitoh Regen.
 1.143 19-Sep-2019  msaitoh Regen.
 1.142 04-Sep-2019  msaitoh Regen.
 1.141 04-Sep-2019  msaitoh Regen.
 1.140 16-Aug-2019  msaitoh Regen.
 1.139 06-Jun-2019  thorpej branches: 1.139.2;
Regen for addition of BCM53125 switch.
 1.138 22-Apr-2019  jmcneill regen
 1.137 25-Mar-2019  msaitoh Regen.
 1.136 25-Mar-2019  msaitoh Regen.
 1.135 15-Mar-2019  msaitoh Regen.
 1.134 08-Mar-2019  msaitoh Regen.
 1.133 08-Mar-2019  msaitoh Regen.
 1.132 07-Mar-2019  msaitoh Regen.
 1.131 06-Mar-2019  msaitoh Regen.
 1.130 27-Feb-2019  msaitoh Regen.
 1.129 25-Feb-2019  msaitoh Regen.
 1.128 13-Feb-2019  msaitoh regen.
 1.127 13-Feb-2019  msaitoh Regen.
 1.126 13-Feb-2019  msaitoh Regen.
 1.125 09-Feb-2019  rin regen
 1.124 08-Feb-2019  msaitoh Regen.
 1.123 28-Dec-2018  msaitoh Regen.
 1.122 02-Jul-2018  msaitoh Regen.
 1.121 02-Jul-2018  msaitoh Regen.
 1.120 19-Jun-2018  msaitoh branches: 1.120.2;
Regen.
 1.119 13-Jun-2018  jdolecek regen
 1.118 10-May-2018  msaitoh Regen.
 1.117 03-Jul-2017  msaitoh branches: 1.117.4;
Regen.
 1.116 01-Feb-2017  msaitoh branches: 1.116.6;
regen.
 1.115 14-Aug-2015  knakahara branches: 1.115.2; 1.115.4;
regen
 1.114 09-Jun-2015  matt Regen.
 1.113 09-Nov-2014  nonaka branches: 1.113.2;
regen
 1.112 20-Aug-2014  msaitoh Regen.
 1.111 02-Jul-2014  msaitoh branches: 1.111.2;
Regen.
 1.110 13-May-2014  christos regen
 1.109 26-Feb-2014  ozaki-r branches: 1.109.2;
Regen.
 1.108 21-Dec-2013  kiyohara Regen.
 1.107 12-Jun-2013  msaitoh branches: 1.107.2;
regen.
 1.106 02-Jun-2013  msaitoh regen
 1.105 23-Apr-2013  msaitoh regen.
 1.104 14-Mar-2013  msaitoh Regen.
 1.103 20-Feb-2013  msaitoh regen.
 1.102 12-Jan-2013  jakllsch regen
 1.101 12-Jan-2013  jakllsch regen.
 1.100 17-Sep-2012  tsutsui Regen from miidevs rev 1.109:
> Add another Broadcom OUI and BCM57765 1000BASE-T media interface.
> Per PR kern/46961.
 1.99 15-Jul-2012  matt branches: 1.99.2;
Regen.
 1.98 06-Apr-2012  matt Regen.
 1.97 06-Apr-2012  isaki Regen from miidevs,v 1.106; sync a comment with a fact.
 1.96 25-Nov-2011  jakllsch branches: 1.96.2; 1.96.4;
regen. (PR 41256)
 1.95 12-Nov-2011  sekiya Regen.
 1.94 02-Nov-2011  jakllsch regen.
 1.93 07-Jun-2011  cegger branches: 1.93.2;
regen.
 1.92 28-May-2011  matt branches: 1.92.2;
Regen.
 1.91 20-May-2011  msaitoh regen
 1.90 26-Jan-2011  bouyer Regen: Add RDC Semiconductor R6040 10/100 integrated PHY
 1.89 11-Dec-2010  matt branches: 1.89.2; 1.89.4;
Regen.
 1.88 27-Nov-2010  christos regen
 1.87 27-Nov-2010  jym regen.
 1.86 02-May-2010  pgoyette Regen
 1.85 13-Mar-2010  kiyohara branches: 1.85.2;
Regen.
 1.84 24-Jan-2010  msaitoh branches: 1.84.2;
regen.
 1.83 14-Dec-2009  enami Regen so that makphy.c compiles.
 1.82 18-Nov-2009  bouyer Regen: Add BCM5709CAX and BCM5709C PHYs.
 1.81 12-Aug-2009  simonb Regen.
 1.80 18-Jun-2009  rjs Regen.
 1.79 19-Apr-2009  msaitoh regen.
 1.78 19-Apr-2009  msaitoh Some fixes and enhancements:

Both if_bge* and brgphy.[ch]:
Check the parent's MAC and use the quirk code for the bug like OpenBSD and
FreeBSD. Some bugs can't identify the PHY ID. For example, 5704 Ax has the
ADC bug, but 5704 A3 and 5704 B0 have the same PHY ID and revision. Add
BGE_PHY_CRC_BUG, BGE_PHY_ADC_BUG, BGE_PHY_5704_A0_BUG, BGE_PHY_JITTER_BUG,
BGE_PHY_ADJUST_TRIM and BGE_PHY_BER_BUG for this flag. Some of the DSP
patches are newly taken from OpenBSD and FreeBSD.

if_bge*:
Remove duplicated BGE_CHIPID_BCM5714_A0 entry in the known CHIPID table.
Fix obsolete comments.

brgphy.[ch]:
Add some PHY IDs.

TODO:
Add more three quirk code into bge and brgphy (the brgphy side's are
currently #if0'ed).
Add support for bnx into brgphy (currently #if0'ed)
 1.77 19-Apr-2009  msaitoh regen
 1.76 25-Mar-2009  cegger regen.
 1.75 11-Feb-2009  cegger regen.
 1.74 16-Jan-2009  cegger branches: 1.74.2;
regen
 1.73 27-Dec-2008  tsutsui Regen from miidevs rev 1.80:
> Fix a botched comment.
 1.72 27-Dec-2008  jnemeth regen for et (Agere) driver
 1.71 28-Sep-2008  bouyer branches: 1.71.2; 1.71.4; 1.71.10;
Regen: Add JMicron OUI, and JMC2[56]0 PHYs.
 1.70 25-Aug-2008  cegger regen. for PR 39241: Add support for Broadcom BCM5906(M) from Karl Uwe Lockhoff
 1.69 28-Apr-2008  martin branches: 1.69.2; 1.69.6;
Remove clause 3 and 4 from TNF licenses
 1.68 20-Feb-2008  markd branches: 1.68.6; 1.68.8; 1.68.10;
regen.
 1.67 29-Dec-2007  wiz regen (+ Marvell 88E1116 Gigabit PHY)
 1.66 12-Oct-2007  tsutsui branches: 1.66.4; 1.66.10;
Regen from miidevs rev 1.73:
> Add Realtek RTL8211, which has the same ID with 8169S/8110S internal PHY.
 1.65 28-Aug-2007  msaitoh branches: 1.65.2;
regen
 1.64 06-Aug-2007  markd branches: 1.64.2; 1.64.4;
Regen for BCM5755 and 5754.
 1.63 17-Feb-2007  jmcneill branches: 1.63.4; 1.63.12; 1.63.16;
Regen.
 1.62 26-Nov-2006  tsutsui branches: 1.62.2; 1.62.4; 1.62.6;
Regen from miidevs rev 1.69:
> Add BCM5752 Gig-E PHY. From Matthias Drochner and FreeBSD/OpenBSD.
 1.61 21-Oct-2006  bouyer Regen: addded i82563 PHY
 1.60 27-Sep-2006  cube Regen (Intel 82562G).
 1.59 27-Apr-2006  jonathan branches: 1.59.8; 1.59.10;
regen sys/dev/mii/miidevs{,_data}.h from miidevs 1.66 after addition
of PHY ID for BCM5780 (serverworks HT-2000) integral 1000base-T PHY.
 1.58 21-Mar-2006  wiz regen.
 1.57 14-Mar-2006  chs branches: 1.57.2;
regen
 1.56 18-Feb-2006  thorpej branches: 1.56.2; 1.56.4;
Add the DP83847 PHY. From seebs in kern/32866
 1.55 04-Jan-2006  xtraeme branches: 1.55.2; 1.55.4;
regen
 1.54 08-Dec-2005  soren branches: 1.54.2;
Regen.
 1.53 28-Aug-2005  kiyohara Fix misstake regen.
 1.52 28-Aug-2005  kiyohara regen.
 1.51 23-Jun-2005  briggs branches: 1.51.2;
Regen for Marvell 88E1111
 1.50 16-Mar-2005  briggs branches: 1.50.2;
regen for xxCICADA 8201B
 1.49 27-Feb-2005  perry regen
 1.48 20-Feb-2005  jdolecek regen: Cicada PHY addition
 1.47 17-Jan-2005  scw branches: 1.47.2;
Regen for Broadcom BCM5222.
 1.46 23-Dec-2004  jonathan branches: 1.46.2;
Regen from miidevs rev 1.55, with codes for Realtek RTK8169S builtin PHY.
 1.45 24-Nov-2004  martin Regen (BCM4401 added)
 1.44 28-Oct-2004  cube Regen.
 1.43 07-Feb-2004  matt Regen.
 1.42 26-Oct-2003  fvdl Regen after clarifying IGPE1000 name.
 1.41 26-Oct-2003  fvdl Regen after adding IGP01E1000.
 1.40 17-Jul-2003  hannken Regen.
 1.39 17-Jul-2003  hannken Add support for the BCM5705:
- Only BCM5705M asic rev A1 was tested.

Thanks to Bill Paul (wpaul@freebsd.org) for help and support.

Approved by: Frank van der Linden <fvdl@netbsd.org>
 1.38 01-Jul-2003  msaitoh branches: 1.38.2;
Add ICS1889 and 1892
 1.37 02-May-2003  scw Regen
 1.36 26-Jan-2003  matt Regen.
 1.35 17-Jan-2003  gendalia regenerate to match miidevs, added ac101L phy
 1.34 16-Jan-2003  jonathan regen machine-generated files from miidevs rev 1.44 (bcm5704 phy)
 1.33 27-Dec-2002  matt Regen.
 1.32 07-Nov-2002  martin Regen (MYSON MTD803 added)
 1.31 08-Aug-2002  fvdl Regen after addition of marvell 881011.
 1.30 09-Jul-2002  matt Regen.
 1.29 25-Jun-2002  drochner regen
 1.28 22-Jun-2002  fvdl Regen.
 1.27 15-May-2002  matt branches: 1.27.2; 1.27.4;
Regen.
 1.26 15-May-2002  matt Regen.
 1.25 14-Mar-2002  chs regen
 1.24 10-Feb-2002  wiz Regen [ICS 1893]
 1.23 15-Jan-2002  thorpej Regen; add another Marvell 88E1000 PHY model number.
 1.22 15-Dec-2001  augustss Regen.
 1.21 25-Aug-2001  thorpej Regen.
 1.20 25-Aug-2001  thorpej Regen; added AMD Am79c874 NetPHY-1LP.
 1.19 25-Aug-2001  thorpej Regen; improve AMD PHY names.
 1.18 23-Aug-2001  thorpej Regen; recognize the 79c972's 10BASE-T interface mapped onto MII.
 1.17 27-Jul-2001  thorpej Regen; added a 3Com 3c905B internal PHY made by Broadcom.
 1.16 20-Jul-2001  thorpej Regen.
 1.15 12-Jul-2001  thorpej Regen; Add LXT-1000, clean up.
 1.14 12-Jul-2001  thorpej Regen; corrected Marvell entries.
 1.13 19-Jun-2001  thorpej branches: 1.13.2;
Regen; added Seeq 80225 10/100 PHY.
 1.12 31-May-2001  thorpej Regen; added several more PHYs.
 1.11 31-May-2001  thorpej Regen; added NatSemi DP83891.
 1.10 22-May-2001  soren Regen.
 1.9 17-May-2001  drochner regen
 1.8 15-May-2001  matt Regen
 1.7 15-May-2001  thorpej Regen; Add National Semiconductor DP83861 1000baseTX PHY.
 1.6 09-Apr-2001  drochner regen
 1.5 28-Mar-2001  drochner regen
 1.4 07-Jan-2001  augustss branches: 1.4.2;
Regen.
 1.3 07-Nov-2000  soren branches: 1.3.2;
Regen.
 1.2 06-Nov-2000  augustss Regen.
 1.1 08-May-2000  augustss Regen.
 1.3.2.5 21-Apr-2001  bouyer Sync with HEAD
 1.3.2.4 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.3.2.3 22-Nov-2000  bouyer Sync with HEAD.
 1.3.2.2 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.3.2.1 07-Nov-2000  bouyer file miidevs_data.h was added on branch thorpej_scsipi on 2000-11-20 11:42:11 +0000
 1.4.2.13 17-Jan-2003  thorpej Sync with HEAD.
 1.4.2.12 29-Dec-2002  thorpej Sync with HEAD.
 1.4.2.11 11-Nov-2002  nathanw Catch up to -current
 1.4.2.10 13-Aug-2002  nathanw Catch up to -current.
 1.4.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.4.2.8 20-Jun-2002  nathanw Catch up to -current.
 1.4.2.7 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.4.2.6 28-Feb-2002  nathanw Catch up to -current.
 1.4.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.4.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.4.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.4.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.4.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.13.2.8 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.13.2.7 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.13.2.6 16-Mar-2002  jdolecek Catch up with -current.
 1.13.2.5 11-Feb-2002  jdolecek Sync w/ -current.
 1.13.2.4 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.13.2.3 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.13.2.2 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.13.2.1 03-Aug-2001  lukem update to -current
 1.27.4.3 28-Jan-2003  jmc Regen (requested by fvdl in ticket #1126)
Pullup support for bge device. (Broadcom Gigabit Ethernet)
 1.27.4.2 16-Nov-2002  he Pull up regenerated files (requested by thorpej in ticket #648):
Add ID for Marvell 881011 phy found on newer i8254x-based
gig-ether cards.
 1.27.4.1 12-Jul-2002  thorpej Regenerate. pullup-1-6 ticket #486.
 1.27.2.2 29-Aug-2002  gehenna catch up with -current.
 1.27.2.1 15-Jul-2002  gehenna catch up with -current.
 1.38.2.11 11-Dec-2005  christos Sync with head.
 1.38.2.10 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.38.2.9 01-Apr-2005  skrll Sync with HEAD.
 1.38.2.8 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.38.2.7 24-Jan-2005  skrll Sync with HEAD.
 1.38.2.6 17-Jan-2005  skrll Sync with HEAD.
 1.38.2.5 29-Nov-2004  skrll Sync with HEAD.
 1.38.2.4 02-Nov-2004  skrll Sync with HEAD.
 1.38.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.38.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.38.2.1 03-Aug-2004  skrll Sync with HEAD
 1.46.2.1 29-Apr-2005  kent sync with -current
 1.47.2.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.50.2.7 23-Sep-2007  bouyer Regen for ticket #1842
 1.50.2.6 31-Mar-2007  bouyer regen for ticket 1681
 1.50.2.5 03-Mar-2007  bouyer regen for ticket #1673
 1.50.2.4 28-Apr-2006  riz Regen for ticket 1292.
 1.50.2.3 29-Dec-2005  riz Regen for ticket 1044.
 1.50.2.2 12-Sep-2005  tron Regen for ticket #760.
 1.50.2.1 04-Jul-2005  tron Regen for ticket 524,
 1.51.2.7 27-Feb-2008  yamt sync with head.
 1.51.2.6 21-Jan-2008  yamt sync with head
 1.51.2.5 27-Oct-2007  yamt sync with head.
 1.51.2.4 03-Sep-2007  yamt sync with head.
 1.51.2.3 26-Feb-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.54.2.2 18-Feb-2006  yamt sync with head.
 1.54.2.1 15-Jan-2006  yamt sync with head.
 1.55.4.2 01-Jun-2006  kardel Sync with head.
 1.55.4.1 22-Apr-2006  simonb Sync with head.
 1.55.2.1 09-Sep-2006  rpaulo sync with head
 1.56.4.2 11-May-2006  elad sync with head
 1.56.4.1 19-Apr-2006  elad sync with head.
 1.56.2.2 24-May-2006  yamt sync with head.
 1.56.2.1 01-Apr-2006  yamt sync with head.
 1.57.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.57.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.59.10.2 10-Dec-2006  yamt sync with head.
 1.59.10.1 22-Oct-2006  yamt sync with head
 1.59.8.2 12-Jan-2007  ad Sync with head.
 1.59.8.1 18-Nov-2006  ad Sync with head.
 1.62.6.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.62.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.62.2.3 18-Aug-2009  bouyer Regen for ticket 1342
 1.62.2.2 31-Aug-2007  xtraeme regen for ticket #819
 1.62.2.1 29-Aug-2007  liamjfoy Pull up following revision(s) (requested by masanobu in ticket #850):

sys/dev/pci/if_wm.c 1.137
sys/dev/pci/if_wm.c 1.138
sys/dev/pci/if_wm.c 1.141
sys/dev/pci/if_wm.c 1.144
sys/dev/pci/if_wmreg.h 1.23
sys/dev/pci/pcidevs 1.893
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/igphy.c 1.12
sys/dev/mii/miidevs 1.72
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/wm.4 1.18

Fix for 82541 and 82547's reset bug.
Modify wm_reset() to make some device stable.
Add ICH9 support to wm.
Add I82566 support to igphy.

Pulled done via patch.
 1.63.16.3 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.63.16.2 03-Sep-2007  jmcneill Sync with HEAD.
 1.63.16.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.63.12.2 03-Sep-2007  skrll Sync with HEAD.
 1.63.12.1 15-Aug-2007  skrll Sync with HEAD.
 1.63.4.3 12-Oct-2007  ad Sync with head.
 1.63.4.2 09-Oct-2007  ad Sync with head.
 1.63.4.1 20-Aug-2007  ad Sync with HEAD.
 1.64.4.2 06-Aug-2007  markd Regen for BCM5755 and 5754.
 1.64.4.1 06-Aug-2007  markd file miidevs_data.h was added on branch matt-mips64 on 2007-08-06 12:09:28 +0000
 1.64.2.3 23-Mar-2008  matt sync with HEAD
 1.64.2.2 09-Jan-2008  matt sync with HEAD
 1.64.2.1 06-Nov-2007  matt sync with HEAD
 1.65.2.1 14-Oct-2007  yamt sync with head.
 1.66.10.1 02-Jan-2008  bouyer Sync with HEAD
 1.66.4.1 18-Feb-2008  mjf Sync with HEAD.
 1.68.10.6 11-Aug-2010  yamt sync with head.
 1.68.10.5 11-Mar-2010  yamt sync with head
 1.68.10.4 19-Aug-2009  yamt sync with head.
 1.68.10.3 18-Jul-2009  yamt sync with head.
 1.68.10.2 04-May-2009  yamt sync with head.
 1.68.10.1 16-May-2008  yamt sync with head.
 1.68.8.1 18-May-2008  yamt sync with head.
 1.68.6.4 17-Jan-2009  mjf Sync with HEAD.
 1.68.6.3 05-Oct-2008  mjf Sync with HEAD.
 1.68.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.68.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.69.6.1 19-Oct-2008  haad Sync with HEAD.
 1.69.2.2 10-Oct-2008  skrll Sync with HEAD.
 1.69.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.71.10.4 24-Dec-2011  matt Regen.
 1.71.10.3 20-May-2011  matt Regen.
 1.71.10.2 21-Apr-2010  matt sync to netbsd-5
 1.71.10.1 09-Nov-2009  cliff - add entry for Marvell 88E1149 Gigabit PHY to miidevs
- regenerate (make) miidevs.h and miidevs_data.h
 1.71.4.6 09-Nov-2015  sborrill Regen
 1.71.4.5 19-Jun-2013  bouyer Regen for ticket #1850
 1.71.4.4 19-Nov-2010  riz branches: 1.71.4.4.2;
Regen for ticket 1359.
 1.71.4.3 27-Jan-2010  sborrill Regen
 1.71.4.2 04-Aug-2009  snj Regen for ticket 866.
 1.71.4.1 03-May-2009  snj Regen for ticket 721.
 1.71.4.4.2.1 07-Jan-2011  matt Regen.
 1.71.2.3 28-Apr-2009  skrll Sync with HEAD.
 1.71.2.2 03-Mar-2009  skrll Sync with HEAD.
 1.71.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.74.2.2 23-Jul-2009  jym Sync with HEAD.
 1.74.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.84.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.84.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.85.2.4 12-Jun-2011  rmind sync with head
 1.85.2.3 31-May-2011  rmind sync with head
 1.85.2.2 05-Mar-2011  rmind sync with head
 1.85.2.1 30-May-2010  rmind sync with head
 1.89.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.89.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.92.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.93.2.5 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.93.2.4 23-Jan-2013  yamt sync with head
 1.93.2.3 30-Oct-2012  yamt sync with head
 1.93.2.2 17-Apr-2012  yamt sync with head
 1.93.2.1 10-Nov-2011  yamt sync with head
 1.96.4.3 07-Dec-2014  martin regen
 1.96.4.2 07-Sep-2013  bouyer regen for ticket 939
 1.96.4.1 24-Oct-2012  riz Regen for ticket 633.
 1.96.2.1 29-Apr-2012  mrg sync to latest -current.
 1.99.2.5 03-Dec-2017  jdolecek update from HEAD
 1.99.2.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.99.2.3 23-Jun-2013  tls resync from head
 1.99.2.2 25-Feb-2013  tls resync with head
 1.99.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.107.2.1 18-May-2014  rmind sync with head
 1.109.2.1 10-Aug-2014  tls Rebase.
 1.111.2.3 09-Mar-2017  snj regen for ticket 1371
 1.111.2.2 09-Dec-2016  snj regen for ticket 1299
 1.111.2.1 17-Jan-2015  martin branches: 1.111.2.1.4;
Regen (Ticket #433)
 1.111.2.1.4.2 13-Mar-2017  skrll Sync with netbsd-7-1-RELEASE
 1.111.2.1.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.113.2.3 28-Aug-2017  skrll Sync with HEAD
 1.113.2.2 05-Feb-2017  skrll Sync with HEAD
 1.113.2.1 22-Sep-2015  skrll Sync with HEAD
 1.115.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.115.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.116.6.10 20-Jul-2020  martin regen for ticket #1577
 1.116.6.9 14-Apr-2020  martin Regen for ticket #1529
 1.116.6.8 25-Nov-2019  martin Regen for ticket #1457
 1.116.6.7 24-Oct-2019  martin Regen for ticket #1414
 1.116.6.6 01-Aug-2019  martin regen for ticket #1315
 1.116.6.5 07-Mar-2019  martin Regen for ticket #1207
 1.116.6.4 17-Jan-2019  martin regen (ticket #1164)
 1.116.6.3 04-Dec-2018  martin Regen for ticket #1116
 1.116.6.2 26-Jul-2018  snj regen for ticket 931
 1.116.6.1 22-Nov-2017  martin regen
 1.117.4.4 18-Jan-2019  pgoyette Synch with HEAD
 1.117.4.3 28-Jul-2018  pgoyette Sync with HEAD
 1.117.4.2 25-Jun-2018  pgoyette Sync with HEAD
 1.117.4.1 21-May-2018  pgoyette Sync with HEAD
 1.120.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.120.2.1 10-Jun-2019  christos Sync with HEAD
 1.139.2.8 10-Jul-2020  martin Regen for ticket #990
 1.139.2.7 14-Apr-2020  martin Regen for ticket #831
 1.139.2.6 19-Mar-2020  martin Regen (for ticket #786)
 1.139.2.5 25-Nov-2019  martin Regen for ticket 479
 1.139.2.4 25-Nov-2019  martin Regen for ticket 479
 1.139.2.3 25-Nov-2019  martin Regen for ticket #473
 1.139.2.2 23-Oct-2019  martin Regen for ticket #372
 1.139.2.1 02-Sep-2019  martin regen (for ticket #144, also requested in ticket #171)
 1.147.2.1 29-Feb-2020  ad Sync with head.
 1.154.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.155.10.1 20-Jun-2024  martin Regen for ticket #712
 1.158.6.1 02-Aug-2025  perseant Sync with HEAD
 1.75 14-Aug-2022  riastradh mii(4): Wait for MIIF_DOINGAUTO to clear with MIIF_AUTOTSLEEP too.

Otherwise mii_phy_detach may return while mii_phy_auto_timeout_locked
is still in progress in another thread.

Reuse the storage for mii_nway_ch, which is unused if MIIF_AUTOTSLEEP
is set, for a new condvar in a union. This doesn't change the kernel
ABI because sizeof(struct kcondvar) <= sizeof(struct callout) and
both have the same alignment, for an array of void *.
 1.74 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.73 24-Aug-2020  msaitoh branches: 1.73.6;
Don't do full initialization for autonego when just restarting autonego
because it's not required.

This change reduce extra initialization which include PHY_RESET() which
caused long delay(max 500ms).
 1.72 07-Jul-2020  msaitoh - Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.71 25-May-2020  jmcneill Add MIIF_RXID and MIIF_TXID flags to signal that RX or TX delays are required, from OpenBSD.
 1.70 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.69 20-Nov-2019  msaitoh Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.68 11-Apr-2019  msaitoh branches: 1.68.4;
KNF. No functional change.
 1.67 09-Apr-2019  msaitoh - Use uint16_t more for MII registers.
- Whitespace.
 1.66 26-Feb-2019  msaitoh Add MI MII clause 45 MMD MDIO access macros via clause 22 indirect registers:

DESCRIPTION
static inline int
MMD_INDIRECT(struct mii_softc *sc, uint16_t daddr, uint16_t regnum):
Setup MMD device address and register number. It also setup
address incrementation function.

static inline int
MMD_INDIRECT_READ(struct mii_softc *sc, uint16_t daddr, uint16_t regnum,
uint16_t *valp)):
Do MMD_INDIRECT() and then read the register.

static inline int
MMD_INDIRECT_WRITE(struct mii_softc *sc, uint16_t daddr, uint16_t regnum,
uint16_t val):
Do MMD_INDIRECT() and then write the register.

RETURN VALUE
Retruns 0 on success. Non-zero vaule on failure.

Note that old PHYs have no indirect access registers. Accessing such
devices with these functions cause timeout and return non-zero value
(e.g. ETIMEDOUT).

EXAMPLE
Read MMD Auto negotiation device's EEE advertisement register,
drop 100BASE-TX support and write it.

uint16_t eeadvert;

/* Post increment is not required */
MMD_INDIRECT_READ(sc, MDIO_MMD_AN | MMDACR_FN_DATA,
MDIO_AN_EEEADVERT, &eeadvert);
eeadvert &= ~AN_EEEADVERT_100_TX;

/*
* MMD device address and the register number are already set, so it's
* enough to read MII_MMDACR.
*/
PHY_WRITE(sc. MII_MMDACR, eeadvert);
 1.65 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.64 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.63 08-Jan-2019  msaitoh s/u_int32_t/uint32_t/
 1.62 28-May-2014  msaitoh branches: 1.62.20; 1.62.26; 1.62.28;
Fix typo in comment.
 1.61 15-Mar-2013  msaitoh branches: 1.61.10;
Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
 1.60 22-Jul-2012  matt branches: 1.60.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.59 30-May-2010  pgoyette branches: 1.59.8; 1.59.14;
Extract MIIVERBOSE into a kernel module. The module can be builtin
by defining 'options MIIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.
 1.58 24-Feb-2010  dyoung branches: 1.58.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.57 08-Jan-2010  dyoung branches: 1.57.2;
Expand PMF_FN_* macros.
 1.56 04-Dec-2009  dyoung Delete unused function mii_activate().
 1.55 12-May-2009  cegger struct device * -> device_t, no functional changes intended.
 1.54 19-Apr-2009  msaitoh Add mii_mpd_rev to keep MII PHY revision.
 1.53 16-Jan-2009  cegger branches: 1.53.2;
add mii_anar(). From OpenBSD.
 1.52 04-May-2008  xtraeme branches: 1.52.8; 1.52.10;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.51 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.50 29-Feb-2008  dyoung branches: 1.50.2; 1.50.4;
Use PMF_FN_ARGS, PMF_FN_PROTO.
 1.49 10-Jan-2008  dyoung branches: 1.49.2; 1.49.6;
Add a helper routine for ethernet drivers, mii_ifmedia_change().

Remove an mii_softc from its mii_data in mii_phy_detach(), not in
mii_detach(), so that we do not leave dangling pointers to a PHY
in an mii_data.
 1.48 09-Dec-2007  jmcneill branches: 1.48.2;
Merge jmcneill-pm branch.
 1.47 16-Nov-2006  christos branches: 1.47.2; 1.47.22; 1.47.24; 1.47.30; 1.47.34; 1.47.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.46 25-Mar-2006  thorpej branches: 1.46.8; 1.46.10;
Use device_parent().
 1.45 18-Feb-2006  joerg branches: 1.45.2; 1.45.4; 1.45.6;
Change the link status code in MII to use if_link_state_change instead
of calling rt_ifmsg directly. This allows other parts of the kernel
to change the behaviour depending on the link state and is a
prerequirement for CARP.

Hide mii_phy_statusmsg, mii_phy_update should be used instead.
Don't send routing messages for baudrate changes, if_baudrate is
currently not exported via this interface.

OK tls@
 1.44 11-Dec-2005  christos branches: 1.44.2; 1.44.4; 1.44.6;
merge ktrace-lwp.
 1.43 27-Feb-2005  perry branches: 1.43.4;
nuke trailing whitespace
 1.42 16-Dec-2004  heas branches: 1.42.2; 1.42.4;
Fix a comment.
 1.41 01-Sep-2004  drochner include locators.h from .c only, avoids unnecessary dependencies
 1.40 23-Aug-2004  thorpej De-__P
 1.39 11-Apr-2004  thorpej gmii_phy_getflowcontrol() -> mii_phy_flowstatus(). From HITOSHI Osada.
 1.38 10-Apr-2004  thorpej Flow-control advertisement and parsing support. From HITOSHI Osada.
Slightly modified by me.
 1.37 01-Jul-2003  msaitoh branches: 1.37.2;
- last commit (rev. 1.36) add a entry to keep model number of the PHY in
mii_softc. There are some situations to want to check model number.
- add comment
 1.36 01-Jul-2003  msaitoh Add ICS1889 and 1892
 1.35 20-Feb-2003  matt Add a MIIF_FORCEANEG flag to be passed to mii_attach. This forces an
autonegotiation to take place if IFM_AUTO is selected in mii_media_set.
Make the gem driver use it. (XXX hme probably should use it but I can't
test that).
 1.34 07-Nov-2002  thorpej Make mii_media_active unsigned.
 1.33 07-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.32 29-Sep-2002  wiz "definitions" has lots of 'i's, but that's not reason to leave one out.
 1.31 10-May-2002  thorpej Make sure ifp->if_baudrate is valid when the parent's statchg
callback is made.

Pointed out by Matt Thomas.
 1.30 25-Mar-2002  thorpej Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.29 25-Aug-2001  thorpej Add a flag that indicates that a device is a HomePNA device.
 1.28 27-Jul-2001  thorpej Clean up 1000BASE-SX autonegotiation, and add a way to advertise
PAUSE capability.
 1.27 02-Jun-2001  thorpej branches: 1.27.2;
Make PHY matching all table-driven.
 1.26 31-May-2001  thorpej Enable frobbing the 1000baseT control register on Gig-E PHYs,
used for hard-wiring master mode, and for advertising the 1000baseT
media options during autonegotiation.
 1.25 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.24 17-May-2001  drochner re-enable mii_flags in attach args - I've found a use for it: tell the
PHY which support it that a fiber interface is present
 1.23 30-Apr-2001  thorpej Add code to recognize and set media on GMII (Gigabit MII) PHYs.

802.3 doens't specify ANAR or ANLPAR bits for GMII. Need to
use PHY-specific registers for this, for now, which means we
need specific drivers for the Gigabit-capable PHYs (I think the
most common is the BCM5400).
 1.22 13-Apr-2001  augustss Comment out some flag stuff that isn't used. Someone should take a look
at this. There is something fishy with the mii code, the last argument to
mii_attach() is not being used in any meaningful way.
 1.21 13-Apr-2001  augustss Add a flag to mii_flags which will cause autonegotiation to use tsleep()
instead of callout. This way adapters which need a process context for
PHY register access (e.g. USB adapters) have a chance.
 1.20 28-Mar-2001  drochner Reading the IEEE specs shows that the bits have to be reversed when
mapping an OUI to the MII id registers.
Doing this in the MII_OUI() macro would be too complex, so put it into
a helper function and move the MII id register interpretation stuff
into miivar.h.
 1.19 04-Jul-2000  thorpej branches: 1.19.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.18 23-Mar-2000  thorpej branches: 1.18.4;
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.17 06-Mar-2000  thorpej Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.16 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.15 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.14 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.13 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.12 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.11 04-Nov-1999  thorpej Allow mii_phy_probe() to be called multiple times, and allow the caller
to specify either the PHY number or the PHY `offset' (1st, 2nd, 3rd, etc.)
to configure.
 1.10 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.9 25-Sep-1999  thorpej branches: 1.9.2; 1.9.4; 1.9.8;
Add a PHY `offset' (e.g. "first PHY on bus, second PHY on bus, ...") to
the PHY's softc.
 1.8 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.7 05-Nov-1998  thorpej branches: 1.7.6;
Common code for media-from-bmcr.
 1.6 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.5 04-Nov-1998  thorpej Routines common between the Uknown PHY driver (forthcoming) and other
PHY drivers. This file has ukphy_status(), which is what PHY drivers
should use if media detection is done by decoding NWay.
 1.4 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.3 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.2 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.1 10-Aug-1998  thorpej Near complete rewrite of the MII layer to present an interface compatible
with BSDI's MII layer to device drivers.
 1.7.6.1 23-Apr-1999  perry branches: 1.7.6.1.2;
pullup 1.7->1.8 (thorpej): Fix PR7361
 1.7.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.9.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.4.1 15-Nov-1999  fvdl Sync with -current
 1.9.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.9.2.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.18.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.19.2.8 11-Nov-2002  nathanw Catch up to -current
 1.19.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.19.2.6 20-Jun-2002  nathanw Catch up to -current.
 1.19.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.19.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.19.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.19.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.19.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.27.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.27.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.27.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.27.2.1 03-Aug-2001  lukem update to -current
 1.37.2.7 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.37.2.6 18-Dec-2004  skrll Sync with HEAD.
 1.37.2.5 21-Sep-2004  skrll Fix the sync with head I botched.
 1.37.2.4 18-Sep-2004  skrll Sync with HEAD.
 1.37.2.3 03-Sep-2004  skrll Sync with HEAD
 1.37.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.37.2.1 03-Aug-2004  skrll Sync with HEAD
 1.42.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.42.2.1 29-Apr-2005  kent sync with -current
 1.43.4.4 17-Mar-2008  yamt sync with head.
 1.43.4.3 21-Jan-2008  yamt sync with head
 1.43.4.2 30-Dec-2006  yamt sync with head.
 1.43.4.1 21-Jun-2006  yamt sync with head.
 1.44.6.1 22-Apr-2006  simonb Sync with head.
 1.44.4.1 09-Sep-2006  rpaulo sync with head
 1.44.2.1 01-Mar-2006  yamt sync with head.
 1.45.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.45.4.1 19-Apr-2006  elad sync with head.
 1.45.2.1 01-Apr-2006  yamt sync with head.
 1.46.10.1 10-Dec-2006  yamt sync with head.
 1.46.8.1 18-Nov-2006  ad Sync with head.
 1.47.36.1 11-Dec-2007  yamt sync with head.
 1.47.34.1 26-Dec-2007  ad Sync with head.
 1.47.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.47.24.2 23-Mar-2008  matt sync with HEAD
 1.47.24.1 09-Jan-2008  matt sync with HEAD
 1.47.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.47.2.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1342):
sys/dev/pci/if_bge.c: revisions 1.135, 1.146, 1.151-1.152,
1.155-1.167 via patch
sys/dev/pci/if_bgereg.h: revisions 1.43, 1.48-1.52
sys/dev/pci/if_bgevar.h: revision 1.1
sys/dev/mii/brgphy.c: revisions 1.36, 1.40, 1.43-1.44 and
1.47-1.48 via patch
sys/dev/mii/brgphyreg.h: revisions 1.3-1.4
sys/dev/mii/miidevs: revisions 1.75, 1.77, 1.85
sys/dev/mii/miidevs.h: regen
sys/dev/mii/miidevs_data.h: regen
sys/dev/mii/miivar.h: revision 1.54
For bge:
- Really set Tx threshold.
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the "link changed" bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
- Add BCM5786 support.
for brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2, BCM5708C, BCM5722, and BCM5906.
 1.48.2.1 10-Jan-2008  bouyer Sync with HEAD
 1.49.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.49.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.49.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.49.2.1 24-Mar-2008  keiichi sync with head.
 1.50.4.5 11-Aug-2010  yamt sync with head.
 1.50.4.4 11-Mar-2010  yamt sync with head
 1.50.4.3 16-May-2009  yamt sync with head
 1.50.4.2 04-May-2009  yamt sync with head.
 1.50.4.1 16-May-2008  yamt sync with head.
 1.50.2.1 18-May-2008  yamt sync with head.
 1.52.10.3 09-Nov-2015  sborrill Pull up the following revisions(s) (requested by msaitoh in ticket #1983):
sys/dev/pci/pcidevs: revisions 1.1079, 1.1134, 1.1148-1.1149, 1.1151
sys/dev/pci/pcidevs.h: regen
sys/dev/pci/pcidevs_data.h: regen
sys/dev/pci/if_bge.c: revisions 1.183-1.185, 1.187, 1.189-1.193, 1.195-1.199, 1.202-1.226, 1.228-1.237, 1.240-1.264, 1.267-1.276, 1.278-1.280, 1.283-1.287 via patch
sys/dev/pci/if_bgereg.h: revisions 1.57-1.74, 1.76-1.90 via patch
sys/dev/pci/if_bgevar.h: revisions 1.6, 1.10-1.13, 1.15-1.17 via patch
sys/dev/pci/if_bnx.c: revisions 1.32, 1.34-1.43, 1.48-1.49, 1.52
sys/dev/pci/if_bnxreg.h: revisions 1.8, 1.11-1.14
sys/dev/pci/if_bnxvar.h: revisions 1.1-1.3
sys/dev/mii/brgphy.c: revisions 1.53-1.63, 1.65-69, 1.72-1.74 via patch
sys/dev/mii/brgphyreg.h: revisions 1.5-1.8
sys/dev/mii/miivar.h: revisions 1.61
sys/dev/pci/pcireg.h: patch

Sync bge(4) up to if_bge.c rev. 1.287. Sync brgphy(4) up to 1.74.
Fix some bugs on bnx(4).

Common:
- Add device IDs for Broadcom BCM57710, BCM57711(E), BCM57712(E) and
BCM57766 (pcidevs only).
- Fix BCM5709 PHY detection.
- Fix detection of BGEPHYF_FIBER_{MII|TBI}
- Add BCM5708S support in brgphy(4).
- Don't use the WIRESPEED function for fiber devices.
bge(4):
- Add some Fujitsu's device support from Michael Moll.
- Add BCM57762 support (PR#46961 from Ryo Onodera).
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F. BCM5785G,
BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- Fix DMA setting for read/write on conventional PCI bus devices.
This bug was added in rev. 1.166.
- Fix printing "discarding oversize frame (len=-4)" message and
crash by NULL pointer dereferencing.
- The BCM5785 is a PCIe chip but does not report PCIe capabilities.
Check for this chip explicitely and enable PCIe. Fixes
'firmware handshake timeout'.
- Allow disabling interrupt mitigation.
- Workaround for BCM5906 silicon bug. When auto-negotiation results
in half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292).
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785. (FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf. (FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC. (FreeBSD
r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems we have
seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case. Note that
{tcp,udp}6csum flag is currently not added in the capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking.
- Do not touch the jumbo replenish threshold register on chips that do
not have jumbo support.
- Wait for the bootcode to complete initialization for 5717 and newer
devices.
- 5718 and 57785 document say we should wait 100us in init.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix the setting of Tx Random Backoff Register.
- Check the hardware config words and print them.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind(). Fixes PR#47716.
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Set DMA watermark depend on the PCI max payload size.
- Set BGE_JUMBO_CAPABLE correctly.
- Fix a link detect bug on non-autopoll systems.
- Change the TX ring size for 5717 series and 57764 series.
- Set maximum read byte count to 2048 for PCI-X BCM5703/5704 devices.
- For PCI-X BCM5704, set maximum outstanding split transactions to 0.
- Add 40bit DMA bug workaround(BGEF_40BIT_BUG) from FreeBSD.
This workaround is for 5714/5715 controllers and is not actually a
MAC controller bug but an issue with the embedded PCIe to PCI-X
bridge in the device. This change uses bus_dmatag_subregion(),
so this workaround won't work on some archs which doesn't support
bus_dmatag_subregion().
- Add 2500SX support (not tested).
- Don't use the PHY Auto Poll Mode on many chips. This fixes a bug
that MII Fiber NIC drop packet about 50%. Tested on HP Moonshot.
- Add workaround for PR#48451. Some BCM5717-5720 based systems getNMI
on boot. This problem doesn't occur when we don't use prefetchable
memory in the APE area. Tested with HP MicroServer Gen8.
- In the BCM5703, the DMA read watermark should be set to less than
or equal to the maximum memory read byte count of the PCI-X command
register.
- Fix a bug that BGE_PHY_TEST_CTRL_REG isn't set correctly on some
PCIe devices.
- Use another firmware command in bge_asf_driver_up(). Same as Linux.
This change fixes a bug that watchdog timeout occurs every 25-30
minutes on HP ML110 G6 reported enami@ in PR#49657.
- Fix mbuf leak on failure.
- Remove PCI_PRODUCT_BROADCOM_BCM5724 and
PCI_PRODUCT_BROADCOM_BCM5750M. These devices have not released to
public.
- Add some workaround code for BGE_ASICREV_BCM5784 from Linux.
- Change some printf() to aprint_*().
- Fix typo in comments.
- Cleanup.
brgphy(4):
- Fix bit definition of BRGPHY_MRBE_MSG_PG5_NP_T2 from FreeBSD.
- Add BCM5481, BCM5709S, BCM5756, BCM5717C, BCM5720C, BCM5785,
BCM57765(PR#46961), BCM57780
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this
commit, only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK
calls MI mii_phy_auto(). That was not intended.
- Remove extra delay in brgphy_mii_phy_auto. Same as {Free,Open}BSD.
bnx(4):
- Add missing ifmedia_delete_instance() in bnx_detach().
- Fix a bug that BNX_NO_WOL_FLAG isn't correctly set on some chips.
Reported by From Henning Petersen in PR#44151.
- Fix SERDES initialization.
- Get out of the interrupt handler early if !IFF_RUNNING.
 1.52.10.2 04-Aug-2009  snj Apply patch (requested by msaitoh in ticket #866):
For bge:
- Fix the case of setting a flag in BGE_PCI_DMA_RW_CTL on
conventional PCI.
- Fix some bugs that the driver unable to detect link loss
(OpenBSD 1.135, FreeBSD 1.102)
- bge_tick(): fix some extra input error (OpenBSD 1.221 FreeBSD 1.212)
- Acknowledge link change interrupts by setting the 'link changed' bit
in the status register (used to have no effect). FreeBSD 1.44
(OpenBSD 1.21)
- Add some fiber support (OpenBSD 1.220)
- Set BGE_MISCCFG_KEEP_GPHY_POWER as {Open,Free}BSD and linux.
- Add special case code to fix a problem with the BCM5704 in TBI
mode (FreeBSD rev. 1.71, OpenBSD rev. 1.35)
- Force an interrupt in bge_ifmedia_upd (FreeBSD rev. 1.205, OpenBSD
rev. 1.242)
- Add missing workaround for 5705 (FreeBSD rev. 1.44, OpenBSD rev.
1.21)
- Don't print error message only when the register is BGE_SRS_MODE.
It occurs on some environment (and once after boot?). Other *BSDs
and Linux don't print the error message for all registers.
- Fix comments.
- Remove obsolete codes.
For brgphy:
- Add some quirk codes.
- Add support for BCM5462, BCM54K2 and BCM5722.
 1.52.10.1 23-Apr-2009  snj branches: 1.52.10.1.4;
Pull up following revision(s) (requested by sborrill in ticket #715):
sys/dev/mii/mii_physubr.c: revision 1.62
sys/dev/mii/miivar.h: revision 1.53
add mii_anar(). From OpenBSD.
 1.52.10.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.52.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.52.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.53.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.57.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.57.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.58.2.1 03-Jul-2010  rmind sync with head
 1.59.14.1 07-Sep-2013  bouyer sys/dev/pci/if_bge.c 1.203-1.237, 1.239-1.241, 1.243-1.258 via patch
sys/dev/pci/if_bgereg.h 1.58-1.74, 1.76-1.83 via patch
sys/dev/pci/if_bgevar.h 1.10-1.16 via patch
sys/dev/pci/pcidevs 1.1149 via patch
sys/dev/pci/pcidevs.h regen
sys/dev/pci/pcidevs_data.h regen
sys/dev/mii/brgphy.c 1.61-1.63, 1.65, 1.67 via patch
sys/dev/mii/miivar.h 1.61 via patch
sys/dev/mii/miidevs 1.112-1.113 via patch
sys/dev/mii/miidevs.h regen
sys/dev/mii/miidevs_data.h regen
share/man/man4/bge.4 1.13-1.15 via patch

Add some device support, fix a lot of bugs and add some enahcements.
- Add Altima AC1003, APPLE BCM5701, Broadcom BCM5785F,
BCM5785G, BCM5787F, BCM5719, BCM5720, BCM57766, BCM57782 and BCM57786.
- brgphy(4): Add BCM5756, BCM5717C, BCM5719C, BCM5720C and BCM57780.
- Add some bugfixes and enhancement from FreeBSD:
- Workaround for BCM5906 silicon bug. When auto-negotiation results in
half-duplex operation, excess collision on the ethernet link may
cause internal chip delays that may result in subsequent valid
frames being dropped due to insufficient receive buffer resources.
(FreeBSD: r214219, r214251, r214292)
- Allow write DMA to request larger DMA burst size to get better
performance on BCM5785.
(FreeBSD r213333: OpenBSD 1.294)
- Enable TX MAC state machine lockup fix for both BCM5755 or higher
and BCM5906. Publicly available data sheet just says it may happen
due to corrupted TxMbuf.
(FreeBSD r214216)
- Follow Broadcom datasheet:
Delay 100 microseconds after enabling transmit MAC.
Delay 10 microseconds after enabling receive MAC.
(FreeBSD r241220)
- Insert the completion barrier between register write and the
consecutive delay(). It will fix some device timeout problems
we have seen before.
- Add DELAY(40) after turning on write DMA state machine.
- Add some workarounds for 5717 A0 and 5776[56] to be stable.
From Linux tg3 driver.
- Sync with *BSD. No functional change:
- make bge_chipid() and use it.
- use switch() instead of a lot of if()s.
- Check BGE_RXBDFLAG_IPV6 flag for 5717_PLUS case.
Note that {tcp,udp}6csum flag is currently not added in the
capability.
- Add delay after clearing BGE_MACMODE_TBI_SEND_CFGS for the link
checking. FreeBSD has the same delay().
- Rename PHY related flags for the consistency. It's the same as
FreeBSD.
- Remove BGE_10_100_ONLY flag because this was not used.
For 10/100 devices, when calling mii_attach(), mask BMSR_EXTSTAT
flag to not to check Gigabit flags. It's the same as FreeBSD.
- In brgphyattach(), set sc_isbge, sc_isbnx and sc_phyflags before
PHY_RESET() because brgphy_reset() refers those flags.
- Call brgpy specific autonego function in MII_TICK. Before this commit,
only MII_MEDIACHG calls brgphy_mii_phy_auto() and MII_TICK calls MI
mii_phy_auto(). That was not intended.
- Sync with FreeBSD and OpenBSD. Almost the same as OpenBSD rev. 1.325:
- Sync the ring setup code closer to FreeBSD's driver
- Do not touch the jumbo replenish threshold register on chips that
do not have jumbo support
- Wait for the bootcode to complete initialization for 5717 and newer
devices. See BCM5718 programmer's guide's "step 13,
Device reset Procedure, Section7".
57781's document has the same note.
- 5718 and 57785 document say we should wait 100us.
- Change the order of register settings a little to match both
Broadcom's document and Linux tg3.
- Add detach function.
- Fix a bug that chips which have BCM5906 ASIC touch GPIO wrongly.
- Fix a bug that the NVRAM lock timeout occured on sparc64 onboard bge.
- Check BGE_SGDIG_STS when the chip is NOT a 5717 A0, like freebsd
(OpenBSD rev. 1.327).
- Fix the setting of Tx Random Backoff Register.
- Add BGE_PCIMISCCTL_PCISTATE_RW in BGE_INIT. It's required to set the
PCISTATE register correctly.
- Update comments from 57XX-PG105-R.pdf and 5718-PG106-R.pdf.
- Add missing bus_dmamap_sync() in bge_intr(). The status word is
in DMAed area. Same as other *BSDs.
- Check the hardware config words and print them. This change only
read them and print the values.
- Set BGE_MISC_CTL's byte/word swap options before using
bge_readmem_ind().
- For BGE_IS_575X_PLUS() devices, don't set
BGE_RXLPSTATCONTROL_DACK_FIX bits because these bits are reserved.
- bge_init_tx_ring() uses BGE_RSLOTS (==256) but bge_free_tx_ring() uses
BGE_TX_RING_CNT (== 512). Delete BGE_RSLOTS and use BGE_TX_RING_CNT.
Same as OpenBSD's if_bge.c rev. 1.86.
- Document says 5717 and newer chips have no
BGE_PCISTATE_INTR_NOT_ACTIVE bit, so don't use the bit on those
chips. Same as OpenBSD.
- Fix a bug that the PHY address bits in MI_MODE register is wrongly
cleard. Set the PHY address correctly.
- Use BGE_SETBIT() instead of CSR_WRITE_4() for the BGE_MISC_LOCAL_CTL
register to not to modify some GPIO bits.
- Call bge_poll_fw() before writing BGE_MODE_CTL register like the
latest linux tg3 dirver.
- Set DMA watermark depend on the PCI max payload size.
- Add BGE_JUMBO_CAPABLE flag to some chips. With this commit, 5714,
5780, 5717, 5718, 5719 (exclude rev. A0), 5720, 57765 and 57766 are
added to support jumbo frame.
- Fix the setting of sc->bge_flags for 5717 and newer devices.
- Fix a link detect bug on non-autopoll systems. Same as OpenBSD
(rev.1.329 and 1.336) and FreeBSD (r213710).
- 57765 series is not based on 5717 series. 5717 series is based on
57765 series.
- Set the TX DMA segment size based on the MTU size.
- Change the TX ring size for 5717 series and 57764 series.
- For 57766, set BGE_RDMAMODE_JMB_2K_MMRR for non-jumbo frame.
Same as Linux tg3.
- For 57765 and newer devices, set BGE_MAX_RX_FRAME_LOWAT to 1.
This value is recommended by the document.
- Change sysctl related functions for consistency.
- Style change.
- Use macro. Remove duplicated macro. Remove unused variable.
- Fix comments. Add comments.
- Remove extra semicolon. Remove unused code.
[msaitoh, ticket #939]
 1.59.8.2 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.59.8.1 30-Oct-2012  yamt sync with head
 1.60.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.60.2.1 23-Jun-2013  tls resync from head
 1.61.10.1 10-Aug-2014  tls Rebase.
 1.62.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.62.28.1 10-Jun-2019  christos Sync with HEAD
 1.62.26.2 26-Jan-2019  pgoyette Sync with HEAD
 1.62.26.1 18-Jan-2019  pgoyette Synch with HEAD
 1.62.20.1 21-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1454:

sys/dev/mii/atphy.c 1.22-1.23, 1.25 via patch
sys/dev/mii/mii_physubr.c 1.88 via patch
sys/dev/mii/miivar.h 1.69 via patch

- Fix a bug that atphy(4) can't negotiate correctly when the media
setting is neither auto nor 1000baseT.
- Code cleanup.
 1.68.4.1 21-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #459):

sys/dev/mii/atphy.c: revision 1.23
sys/dev/mii/atphy.c: revision 1.25
sys/dev/mii/miivar.h: revision 1.69
sys/dev/mii/mii_physubr.c: revision 1.88

s/etphy/atphy/. No functional change.

Fix a bug that atphy(4) can't negotiate correctly when the media setting is
neither auto nor 1000baseT. Use correct index for mii_media_table[].

History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD,
only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar()
for simplify. It changed the argument from the ifmedia word to ifm_data used
in our MII API, but the caller have not been changed. And then, PR kern/50206
was reported and the caller was modified by me to prevent panic but it was not
correct fix.
 1.73.6.1 01-Aug-2021  thorpej Sync with HEAD.
 1.15 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.14 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.13 25-Mar-2019  msaitoh KNF. No functional change.
 1.12 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.11 23-Jan-2019  msaitoh Make evbmips/conf/WGT624V3 compilable:
- Modify for new read/write API
- Do "#if 0" for unused structures.
 1.10 16-Jun-2014  msaitoh branches: 1.10.26; 1.10.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.9 18-Jun-2009  rjs branches: 1.9.18; 1.9.22; 1.9.36;
Make it compile. Change a commented out printf() to aprint_error_dev().
 1.8 17-Nov-2008  dyoung branches: 1.8.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.7 04-May-2008  xtraeme branches: 1.7.6; 1.7.8; 1.7.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.6 08-Apr-2008  cegger branches: 1.6.2; 1.6.4;
use aprint_*_dev and device_xname
 1.5 29-Dec-2007  dyoung branches: 1.5.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.4 09-Dec-2007  jmcneill branches: 1.4.2;
Merge jmcneill-pm branch.
 1.3 17-Feb-2007  jmcneill branches: 1.3.16; 1.3.18; 1.3.24; 1.3.26; 1.3.28;
Add a default "dumb" mode, that adds all ports to the same interface.
 1.2 16-Nov-2006  christos branches: 1.2.4; 1.2.6;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.1 21-Jul-2006  gdamore branches: 1.1.4; 1.1.6; 1.1.8; 1.1.10;
Initial implementation for Marvell 88E6060 10/100 5-port PHY switch, from
Sam Leffler, used in various products including AR5312-based designs. This
is not enabled in any configs yet, nor tested by anyone other than Sam. I
will be testing this more later, and adding it to appropriate configs once
I have verified (unless someone else beats me to the punch.)
 1.1.10.1 10-Dec-2006  yamt sync with head.
 1.1.8.2 09-Sep-2006  rpaulo sync with head
 1.1.8.1 21-Jul-2006  rpaulo file mvphy.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:52:03 +0000
 1.1.6.1 18-Nov-2006  ad Sync with head.
 1.1.4.2 11-Aug-2006  yamt sync with head
 1.1.4.1 21-Jul-2006  yamt file mvphy.c was added on branch yamt-pdpolicy on 2006-08-11 15:44:24 +0000
 1.2.6.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.2.4.4 21-Jan-2008  yamt sync with head
 1.2.4.3 26-Feb-2007  yamt sync with head.
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 16-Nov-2006  yamt file mvphy.c was added on branch yamt-lazymbuf on 2006-12-30 20:48:38 +0000
 1.3.28.1 11-Dec-2007  yamt sync with head.
 1.3.26.1 26-Dec-2007  ad Sync with head.
 1.3.24.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.18.1 09-Jan-2008  matt sync with HEAD
 1.3.16.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.3.16.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.4.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.5.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.5.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.4.3 20-Jun-2009  yamt sync with head
 1.6.4.2 04-May-2009  yamt sync with head.
 1.6.4.1 16-May-2008  yamt sync with head.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.7.14.1 28-Jan-2010  matt Fix a split device_t/softc botch.
 1.7.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.7.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.8.4.1 23-Jul-2009  jym Sync with HEAD.
 1.9.36.1 10-Aug-2014  tls Rebase.
 1.9.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.10.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10.28.1 10-Jun-2019  christos Sync with HEAD
 1.10.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.1 21-Jul-2006  gdamore branches: 1.1.4; 1.1.8; 1.1.14;
Initial implementation for Marvell 88E6060 10/100 5-port PHY switch, from
Sam Leffler, used in various products including AR5312-based designs. This
is not enabled in any configs yet, nor tested by anyone other than Sam. I
will be testing this more later, and adding it to appropriate configs once
I have verified (unless someone else beats me to the punch.)
 1.1.14.2 30-Dec-2006  yamt sync with head.
 1.1.14.1 21-Jul-2006  yamt file mvphyreg.h was added on branch yamt-lazymbuf on 2006-12-30 20:48:38 +0000
 1.1.8.2 09-Sep-2006  rpaulo sync with head
 1.1.8.1 21-Jul-2006  rpaulo file mvphyreg.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:52:03 +0000
 1.1.4.2 11-Aug-2006  yamt sync with head
 1.1.4.1 21-Jul-2006  yamt file mvphyreg.h was added on branch yamt-pdpolicy on 2006-08-11 15:44:24 +0000
 1.66 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.65 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.64 25-Mar-2019  msaitoh KNF. No functional change.
 1.63 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.62 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.61 12-Aug-2017  martin branches: 1.61.2; 1.61.4;
Do not deref a NULL pointer if no current media has been selected.
This error condition does not happen with properly working hardware, but it is
no good reason for a kernel panic either.
 1.60 07-Jul-2016  msaitoh KNF. Remove extra spaces. No functional change.
 1.59 16-Jun-2014  msaitoh branches: 1.59.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.58 16-Jun-2014  msaitoh No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.57 19-Oct-2009  bouyer branches: 1.57.18; 1.57.22; 1.57.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.56 16-Feb-2009  cegger fix media priorities:

IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:

1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T

Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.

Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html

got no comments, no objections.
 1.55 17-Nov-2008  dyoung branches: 1.55.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.54 04-May-2008  xtraeme branches: 1.54.6; 1.54.8; 1.54.10; 1.54.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.53 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.52 08-Apr-2008  cegger branches: 1.52.2; 1.52.4;
use aprint_*_dev and device_xname
 1.51 29-Dec-2007  dyoung branches: 1.51.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.50 09-Dec-2007  jmcneill branches: 1.50.2;
Merge jmcneill-pm branch.
 1.49 16-Nov-2006  christos branches: 1.49.22; 1.49.24; 1.49.30; 1.49.34; 1.49.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.48 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.47 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.46 29-Mar-2006  thorpej branches: 1.46.8; 1.46.10;
Use device_private().
 1.45 20-Feb-2006  thorpej branches: 1.45.2; 1.45.4; 1.45.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.44 11-Dec-2005  christos branches: 1.44.2; 1.44.4; 1.44.6;
merge ktrace-lwp.
 1.43 27-Feb-2005  perry branches: 1.43.4;
nuke trailing whitespace
 1.42 23-Aug-2004  thorpej branches: 1.42.4; 1.42.6;
Make use of static.
 1.41 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.40 02-Nov-2003  briggs Implement a separate nsphy_reset(). There are two reasons for this:

1) This PHY can take an inordinate amount of time to reset if
media is attached. Under fairly normal circumstances, up
to near one second. This is because it appears to go through
an implicit autonegotiation cycle as part of the reset.

2) During reset and autonegotiation, the BMCR will clear the reset
bit before the process is complete. It will return 0 until the
process is complete and it's safe to access the PHY again.

This gets the on-board pcnet + nsphy ethernet working properly for me on
an IBM PC Server/325. Fixes PR/16346.
 1.39 29-Apr-2003  thorpej branches: 1.39.2;
Use aprint*().
 1.38 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.37 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.36 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.35 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.34 25-Mar-2002  thorpej branches: 1.34.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.33 13-Nov-2001  lukem add RCSID
 1.32 25-Aug-2001  thorpej ANSI'ify.
 1.31 02-Jun-2001  thorpej branches: 1.31.2;
Make PHY matching all table-driven.
 1.30 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.29 28-Mar-2001  drochner update for miidevs changes
 1.28 27-Jul-2000  martin branches: 1.28.2;
Fix to autonegotiation problem with some fxp cards. Fix found and reported
by Erich T. Enke et al. on current-users. This fixes PR 10550.
 1.27 04-Jul-2000  thorpej Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.26 06-Mar-2000  thorpej branches: 1.26.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.25 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.24 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.23 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.22 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.21 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.20 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.19 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.18 14-Jul-1999  thorpej branches: 1.18.2; 1.18.4; 1.18.8;
Correct the sense of the PCR_FLINK100 bit. From Dave Sainty, PR #7832.
 1.17 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.16 05-Nov-1998  thorpej branches: 1.16.6;
Common code for media-from-bmcr.
 1.15 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.14 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.13 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.12 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.11 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.10 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.9 14-Aug-1998  thorpej Make sure CIMDIS is set and FLINK is clear in the PCR.
 1.8 12-Aug-1998  thorpej If the autonegotiation is enabled, the PAR doesn't indicate duplex mode
properly! Work around this by determing current active media by taking
the highest-order common bit of our advertised capabilites and the link
partner's.

If the link partner doens't do autonegotiation, then parallel detection will
pick up the media type, which will never be full-duplex, so reading the PAR
is ok in this case.

Bug pointed out by Matthias Drochner, work-around inspired by reading
the dp83840 manual, section 3.9 (IEEE 802.3u auto-negotiation).
 1.7 12-Aug-1998  thorpej If autonegotiation is enabled in the BMSR, and the BMCR doens't claim
that it has completed, report "none" as the active media type.
 1.6 12-Aug-1998  thorpej Ugh, don't print out "autonegotiation failed to complete" if it did.
We get these once a second if we're in auto mode, the interface is up,
and there's no carrier.
 1.5 10-Aug-1998  thorpej Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.
 1.4 09-Jun-1998  thorpej Nuke __BROKEN_INDIRECT_CONFIG.
 1.3 12-Jan-1998  thorpej Adjust for config changes.
 1.2 17-Nov-1997  thorpej KNF.
 1.1 17-Oct-1997  bouyer Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.16.6.2 31-Jul-2000  he Pull up revision 1.28 (requested by martin):
Fix autonegotiation problem with some fxp cards. Fixes PR#10550.
 1.16.6.1 23-Apr-1999  perry branches: 1.16.6.1.2;
pullup 1.16->1.17 (thorpej): Fix PR7361
 1.16.6.1.2.2 02-Aug-1999  thorpej Update from trunk.
 1.16.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.18.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.4.1 15-Nov-1999  fvdl Sync with -current
 1.18.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.18.2.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.26.4.2 28-Jul-2000  martin Pullup revision 1.28 (approved by Jason Thorpe)

Fix to autonegotiation problem with some fxp cards. Fix found and reported
by Erich T. Enke et al. on current-users.

Fixes PR 10550.
 1.26.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.28.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.28.2.6 01-Aug-2002  nathanw Catch up to -current.
 1.28.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.28.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.28.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.28.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.28.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.31.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.31.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.31.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.31.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.31.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.34.2.1 15-Jul-2002  gehenna catch up with -current.
 1.39.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.39.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.39.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.39.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.39.2.1 03-Aug-2004  skrll Sync with HEAD
 1.42.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.42.4.1 29-Apr-2005  kent sync with -current
 1.43.4.3 21-Jan-2008  yamt sync with head
 1.43.4.2 30-Dec-2006  yamt sync with head.
 1.43.4.1 21-Jun-2006  yamt sync with head.
 1.44.6.1 22-Apr-2006  simonb Sync with head.
 1.44.4.1 09-Sep-2006  rpaulo sync with head
 1.44.2.1 01-Mar-2006  yamt sync with head.
 1.45.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.45.4.1 19-Apr-2006  elad sync with head.
 1.45.2.1 01-Apr-2006  yamt sync with head.
 1.46.10.2 10-Dec-2006  yamt sync with head.
 1.46.10.1 22-Oct-2006  yamt sync with head
 1.46.8.1 18-Nov-2006  ad Sync with head.
 1.49.36.1 11-Dec-2007  yamt sync with head.
 1.49.34.1 26-Dec-2007  ad Sync with head.
 1.49.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.49.24.1 09-Jan-2008  matt sync with HEAD
 1.49.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.49.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.50.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.51.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.51.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.52.4.3 11-Mar-2010  yamt sync with head
 1.52.4.2 04-May-2009  yamt sync with head.
 1.52.4.1 16-May-2008  yamt sync with head.
 1.52.2.1 18-May-2008  yamt sync with head.
 1.54.14.1 21-Apr-2010  matt sync to netbsd-5
 1.54.10.1 01-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #474):
sys/dev/mii/inphy.c: revision 1.51
sys/dev/mii/iophy.c: revision 1.35
sys/dev/mii/nsphy.c: revision 1.56
sys/dev/mii/rlphy.c: revision 1.25
sys/dev/mii/ukphy_subr.c: revision 1.11
sys/dev/pci/if_txp.c: revision 1.28
fix media priorities:
IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:
1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T
Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.
Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html
got no comments, no objections.
 1.54.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.54.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.54.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.55.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.57.36.1 10-Aug-2014  tls Rebase.
 1.57.22.2 03-Dec-2017  jdolecek update from HEAD
 1.57.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.57.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.59.4.2 28-Aug-2017  skrll Sync with HEAD
 1.59.4.1 09-Jul-2016  skrll Sync with HEAD
 1.61.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.61.4.1 10-Jun-2019  christos Sync with HEAD
 1.61.2.1 26-Jan-2019  pgoyette Sync with HEAD
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 10-Aug-1998  thorpej branches: 1.1.144; 1.1.146; 1.1.148;
Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.
 1.1.148.1 16-May-2008  yamt sync with head.
 1.1.146.1 18-May-2008  yamt sync with head.
 1.1.144.1 02-Jun-2008  mjf Sync with HEAD.
 1.46 28-Mar-2020  thorpej Don't set DVF_DETACH_SHUTDOWN. The MII layer wants to manage the lifecycle
of the PHY devices, and if a NIC driver chooses not to detach its PHYs
at shutdown, that's the driver's business.

PR kern/55121.
 1.45 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.44 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.43 25-Mar-2019  msaitoh KNF. No functional change.
 1.42 08-Mar-2019  msaitoh Use static.
 1.41 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.40 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.39 07-Jul-2016  msaitoh branches: 1.39.16; 1.39.18;
KNF. Remove extra spaces. No functional change.
 1.38 16-Jun-2014  msaitoh branches: 1.38.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.37 24-Aug-2012  msaitoh branches: 1.37.2; 1.37.12;
Fix typos
 1.36 25-Nov-2011  jakllsch branches: 1.36.4;
Match on DP83849. From Kurt Lidl in PR 41256.
 1.35 19-Oct-2009  bouyer branches: 1.35.12;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.34 02-Apr-2009  dyoung During shutdown, detach devices in an orderly fashion.

Call the detach routine for every device in the device tree, starting
with the leaves and moving toward the root, expecting that each
(pseudo-)device driver will use the opportunity to gracefully commit
outstandings transactions to the underlying (pseudo-)device and to
relinquish control of the hardware to the system BIOS.

Detaching devices is not suitable for every shutdown: in an emergency,
or if the system state is inconsistent, we should resort to a fast,
simple shutdown that uses only the pmf(9) shutdown hooks and the
(deprecated) shutdownhooks. For now, if the flag RB_NOSYNC is set in
boothowto, opt for the fast, simple shutdown.

Add a device flag, DVF_DETACH_SHUTDOWN, that indicates by its presence
that it is safe to detach a device during shutdown. Introduce macros
CFATTACH_DECL3() and CFATTACH_DECL3_NEW() for creating autoconf
attachments with default device flags. Add DVF_DETACH_SHUTDOWN
to configuration attachments for atabus(4), atw(4) at cardbus(4),
cardbus(4), cardslot(4), com(4) at isa(4), elanpar(4), elanpex(4),
elansc(4), gpio(4), npx(4) at isa(4), nsphyter(4), pci(4), pcib(4),
pcmcia(4), ppb(4), sip(4), wd(4), and wdc(4) at isa(4).

Add a device-detachment "reason" flag, DETACH_SHUTDOWN, that tells the
autoconf code and a device driver that the reason for detachment is
system shutdown.

Add a sysctl, kern.detachall, that tells the system to try to detach
every device at shutdown, regardless of any device's DVF_DETACH_SHUTDOWN
flag. The default for kern.detachall is 0. SET IT TO 1, PLEASE, TO
HELP TEST AND DEBUG DEVICE DETACHMENT AT SHUTDOWN.

This is a work in progress. In future work, I aim to treat
pseudo-devices more thoroughly, and to gracefully tear down a stack of
(pseudo-)disk drivers and filesystems, including cgd(4), vnd(4), and
raid(4) instances at shutdown.

Also commit some changes that are not easily untangled from the rest:

(1) begin to simplify device_t locking: rename struct pmf_private to
device_lock, and incorporate device_lock into struct device.

(2) #include <sys/device.h> in sys/pmf.h in order to get some
definitions that it needs. Stop unnecessarily #including <sys/device.h>
in sys/arch/x86/include/pic.h to keep the amd64, xen, and i386 releases
building.
 1.33 17-Nov-2008  dyoung branches: 1.33.4;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.32 05-May-2008  tsutsui branches: 1.32.6; 1.32.8;
Use device_private() where appropriate.
 1.31 04-May-2008  xtraeme device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.30 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.29 08-Apr-2008  cegger branches: 1.29.2; 1.29.4;
use aprint_*_dev and device_xname
 1.28 20-Jan-2008  msaitoh branches: 1.28.6;
mii_physubr.c::mii_phy_reset() has gphyter and nsphyter specific delay(500).
This delay cause 500us loops under splnet() per linkdown port per mii_tick.
It causes periodically drop packets. It's not acceptable for other devices.

Move gphyter and nsphyter specific delay(500) into the drivers from
mii_physubr.c.
 1.27 09-Dec-2007  jmcneill branches: 1.27.2;
Merge jmcneill-pm branch.
 1.26 16-Nov-2006  christos branches: 1.26.22; 1.26.24; 1.26.30; 1.26.34; 1.26.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.25 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.24 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.23 18-Feb-2006  thorpej branches: 1.23.14; 1.23.16;
Add the DP83847 PHY. From seebs in kern/32866
 1.22 11-Dec-2005  christos branches: 1.22.2; 1.22.4; 1.22.6;
merge ktrace-lwp.
 1.21 23-Aug-2004  thorpej branches: 1.21.12;
Make use of static.
 1.20 16-May-2004  thorpej Get flow control negotiation status.
 1.19 29-Apr-2003  thorpej branches: 1.19.2;
Use aprint*().
 1.18 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.17 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.16 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.15 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.14 25-Mar-2002  thorpej branches: 1.14.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.13 13-Nov-2001  lukem add RCSID
 1.12 25-Aug-2001  thorpej ANSI'ify.
 1.11 02-Jun-2001  thorpej branches: 1.11.2;
Make PHY matching all table-driven.
 1.10 31-May-2001  thorpej Add support for the DP83815 MacPHYTER internal PHY to the DP83843 PHYTER
driver, since for our purposes, they are compatible.
 1.9 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.8 28-Mar-2001  drochner update for miidevs changes
 1.7 04-Jul-2000  thorpej branches: 1.7.2; 1.7.4;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.6 06-Mar-2000  thorpej branches: 1.6.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.5 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.4 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.3 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.2 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.1 07-Dec-1999  thorpej branches: 1.1.2;
Add a driver for the National Semiconductor DP83843 `PHYTER' 10/100
Ethernet PHY.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.7.4.7 18-Oct-2002  nathanw Catch up to -current.
 1.7.4.6 01-Aug-2002  nathanw Catch up to -current.
 1.7.4.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.7.4.4 14-Nov-2001  nathanw Catch up to -current.
 1.7.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.7.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.7.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.7.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.7.2.2 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.7.2.1 04-Jul-2000  bouyer file nsphyter.c was added on branch thorpej_scsipi on 2000-11-20 11:42:11 +0000
 1.11.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.11.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.11.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.11.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.11.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.14.2.1 15-Jul-2002  gehenna catch up with -current.
 1.19.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.19.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.19.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.19.2.1 03-Aug-2004  skrll Sync with HEAD
 1.21.12.3 21-Jan-2008  yamt sync with head
 1.21.12.2 30-Dec-2006  yamt sync with head.
 1.21.12.1 21-Jun-2006  yamt sync with head.
 1.22.6.1 22-Apr-2006  simonb Sync with head.
 1.22.4.1 09-Sep-2006  rpaulo sync with head
 1.22.2.1 18-Feb-2006  yamt sync with head.
 1.23.16.2 10-Dec-2006  yamt sync with head.
 1.23.16.1 22-Oct-2006  yamt sync with head
 1.23.14.1 18-Nov-2006  ad Sync with head.
 1.26.36.1 11-Dec-2007  yamt sync with head.
 1.26.34.1 26-Dec-2007  ad Sync with head.
 1.26.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.26.24.2 23-Mar-2008  matt sync with HEAD
 1.26.24.1 09-Jan-2008  matt sync with HEAD
 1.26.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.26.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.27.2.1 20-Jan-2008  bouyer Sync with HEAD
 1.28.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.28.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.29.4.3 11-Mar-2010  yamt sync with head
 1.29.4.2 04-May-2009  yamt sync with head.
 1.29.4.1 16-May-2008  yamt sync with head.
 1.29.2.1 18-May-2008  yamt sync with head.
 1.32.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.32.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.32.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.33.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.35.12.2 30-Oct-2012  yamt sync with head
 1.35.12.1 17-Apr-2012  yamt sync with head
 1.36.4.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.37.12.1 10-Aug-2014  tls Rebase.
 1.37.2.2 03-Dec-2017  jdolecek update from HEAD
 1.37.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.4.1 09-Jul-2016  skrll Sync with HEAD
 1.39.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.39.18.1 10-Jun-2019  christos Sync with HEAD
 1.39.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 31-May-2001  thorpej branches: 1.2.22; 1.2.30; 1.2.32;
Add support for the DP83815 MacPHYTER internal PHY to the DP83843 PHYTER
driver, since for our purposes, they are compatible.
 1.1 07-Dec-1999  thorpej branches: 1.1.2; 1.1.8; 1.1.10;
Add a driver for the National Semiconductor DP83843 `PHYTER' 10/100
Ethernet PHY.
 1.1.10.1 21-Jun-2001  nathanw Catch up to -current.
 1.1.8.2 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.8.1 07-Dec-1999  bouyer file nsphyterreg.h was added on branch thorpej_scsipi on 2000-11-20 11:42:12 +0000
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.32.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.30.1 29-Apr-2005  kent sync with -current
 1.2.22.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.26 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.25 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.24 25-Mar-2019  msaitoh KNF. No functional change.
 1.23 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.22 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.21 07-Jul-2016  msaitoh branches: 1.21.16; 1.21.18;
KNF. Remove extra spaces. No functional change.
 1.20 17-Nov-2008  dyoung branches: 1.20.26; 1.20.44;
Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.19 04-May-2008  xtraeme branches: 1.19.6; 1.19.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.18 08-Apr-2008  cegger branches: 1.18.2; 1.18.4;
use aprint_*_dev and device_xname
 1.17 09-Dec-2007  jmcneill branches: 1.17.10;
Merge jmcneill-pm branch.
 1.16 16-Nov-2006  christos branches: 1.16.22; 1.16.24; 1.16.34; 1.16.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.15 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.14 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.13 29-Mar-2006  thorpej branches: 1.13.8; 1.13.10;
Use device_private().
 1.12 11-Dec-2005  christos branches: 1.12.4; 1.12.6; 1.12.8; 1.12.10; 1.12.12;
merge ktrace-lwp.
 1.11 23-Aug-2004  thorpej branches: 1.11.12;
Make use of static.
 1.10 29-Apr-2003  thorpej branches: 1.10.2;
Use aprint*().
 1.9 13-Oct-2002  fair If pnaphy attaches, make sure the mii_flags has MIIF_IS_HPNA in it.
 1.8 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.7 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.6 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.5 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.4 25-Mar-2002  thorpej branches: 1.4.2; 1.4.4;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.3 13-Nov-2001  lukem add RCSID
 1.2 25-Aug-2001  thorpej branches: 1.2.4; 1.2.6;
ANSI'ify.
 1.1 25-Aug-2001  thorpej Add a driver for generic HomePNA PHYs. Currently supports the HomePNA
portion of the AMD Am79c901.
 1.2.6.6 18-Oct-2002  nathanw Catch up to -current.
 1.2.6.5 01-Aug-2002  nathanw Catch up to -current.
 1.2.6.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.2.6.3 14-Nov-2001  nathanw Catch up to -current.
 1.2.6.2 21-Sep-2001  nathanw Catch up to -current.
 1.2.6.1 25-Aug-2001  nathanw file pnaphy.c was added on branch nathanw_sa on 2001-09-21 22:35:51 +0000
 1.2.4.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.4.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.4.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.4.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.2.4.1 25-Aug-2001  thorpej file pnaphy.c was added on branch kqueue on 2001-09-13 01:15:47 +0000
 1.4.4.1 07-Dec-2002  he Pull up revision 1.9 (requested by fair in ticket #912):
Fix media detection on this PHY. Part of fix for PR#18590.
 1.4.2.1 15-Jul-2002  gehenna catch up with -current.
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.11.12.3 21-Jan-2008  yamt sync with head
 1.11.12.2 30-Dec-2006  yamt sync with head.
 1.11.12.1 21-Jun-2006  yamt sync with head.
 1.12.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.12.10.1 19-Apr-2006  elad sync with head.
 1.12.8.1 01-Apr-2006  yamt sync with head.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.13.10.2 10-Dec-2006  yamt sync with head.
 1.13.10.1 22-Oct-2006  yamt sync with head
 1.13.8.1 18-Nov-2006  ad Sync with head.
 1.16.36.1 11-Dec-2007  yamt sync with head.
 1.16.34.1 26-Dec-2007  ad Sync with head.
 1.16.24.1 09-Jan-2008  matt sync with HEAD
 1.16.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.16.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.17.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.17.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.4.2 04-May-2009  yamt sync with head.
 1.18.4.1 16-May-2008  yamt sync with head.
 1.18.2.1 18-May-2008  yamt sync with head.
 1.19.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.19.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.20.44.1 09-Jul-2016  skrll Sync with HEAD
 1.20.26.1 03-Dec-2017  jdolecek update from HEAD
 1.21.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21.18.1 10-Jun-2019  christos Sync with HEAD
 1.21.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.55 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.54 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.53 26-Nov-2019  msaitoh KNF. No functional change.
 1.52 25-Mar-2019  msaitoh KNF. No functional change.
 1.51 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.50 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.49 07-Jul-2016  msaitoh branches: 1.49.16; 1.49.18;
KNF. Remove extra spaces. No functional change.
 1.48 16-Jun-2014  msaitoh branches: 1.48.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.47 19-Oct-2009  bouyer branches: 1.47.18; 1.47.22; 1.47.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.46 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.45 04-May-2008  xtraeme branches: 1.45.6; 1.45.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.44 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.43 08-Apr-2008  cegger branches: 1.43.2; 1.43.4;
use aprint_*_dev and device_xname
 1.42 29-Dec-2007  dyoung branches: 1.42.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.41 09-Dec-2007  jmcneill branches: 1.41.2;
Merge jmcneill-pm branch.
 1.40 16-Nov-2006  christos branches: 1.40.22; 1.40.24; 1.40.30; 1.40.34; 1.40.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.39 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.38 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.37 29-Mar-2006  thorpej branches: 1.37.8; 1.37.10;
Use device_private().
 1.36 20-Feb-2006  thorpej branches: 1.36.2; 1.36.4; 1.36.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.35 11-Dec-2005  christos branches: 1.35.2; 1.35.4; 1.35.6;
merge ktrace-lwp.
 1.34 27-Feb-2005  perry branches: 1.34.4;
nuke trailing whitespace
 1.33 23-Aug-2004  thorpej branches: 1.33.4; 1.33.6;
Make use of static.
 1.32 29-Apr-2003  thorpej branches: 1.32.2;
Use aprint*().
 1.31 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.30 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.29 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.28 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.27 25-Mar-2002  thorpej branches: 1.27.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.26 13-Nov-2001  lukem add RCSID
 1.25 25-Aug-2001  thorpej ANSI'ify.
 1.24 02-Jun-2001  thorpej branches: 1.24.2;
Make PHY matching all table-driven.
 1.23 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.22 28-Mar-2001  drochner update for miidevs changes
 1.21 04-Jul-2000  thorpej branches: 1.21.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.20 06-Mar-2000  thorpej branches: 1.20.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.19 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.18 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.17 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.16 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.15 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.14 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.13 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.12 23-Apr-1999  thorpej branches: 1.12.2; 1.12.4; 1.12.8;
Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.11 05-Nov-1998  thorpej branches: 1.11.6;
Common code for media-from-bmcr.
 1.10 05-Nov-1998  thorpej In the status routine, always use the media selected in the BMCR if
autonegotiation is not enabled. This is more reliable on many PHYs,
and requires fewer register reads.
 1.9 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.8 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.7 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.6 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.5 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.4 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.3 12-Aug-1998  thorpej If autonegotiation is enabled in the BMSR, and the BMCR doens't claim
that it has completed, report "none" as the active media type.
 1.2 12-Aug-1998  thorpej Ugh, don't print out "autonegotiation failed to complete" if it did.
We get these once a second if we're in auto mode, the interface is up,
and there's no carrier.
 1.1 11-Aug-1998  thorpej Device driver for the Quality Semiconductor QS6612 PHY, found in
SMC EtherPower-II cards.
 1.11.6.1 23-Apr-1999  perry branches: 1.11.6.1.2;
pullup 1.11->1.12 (thorpej): Fix PR7361
 1.11.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.12.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.4.1 15-Nov-1999  fvdl Sync with -current
 1.12.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.12.2.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.20.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.21.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.21.2.6 01-Aug-2002  nathanw Catch up to -current.
 1.21.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.21.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.21.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.21.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.24.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.24.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.24.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.24.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.24.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.27.2.1 15-Jul-2002  gehenna catch up with -current.
 1.32.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.32.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.32.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.32.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.33.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.33.4.1 29-Apr-2005  kent sync with -current
 1.34.4.3 21-Jan-2008  yamt sync with head
 1.34.4.2 30-Dec-2006  yamt sync with head.
 1.34.4.1 21-Jun-2006  yamt sync with head.
 1.35.6.1 22-Apr-2006  simonb Sync with head.
 1.35.4.1 09-Sep-2006  rpaulo sync with head
 1.35.2.1 01-Mar-2006  yamt sync with head.
 1.36.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.36.4.1 19-Apr-2006  elad sync with head.
 1.36.2.1 01-Apr-2006  yamt sync with head.
 1.37.10.2 10-Dec-2006  yamt sync with head.
 1.37.10.1 22-Oct-2006  yamt sync with head
 1.37.8.1 18-Nov-2006  ad Sync with head.
 1.40.36.1 11-Dec-2007  yamt sync with head.
 1.40.34.1 26-Dec-2007  ad Sync with head.
 1.40.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.40.24.1 09-Jan-2008  matt sync with HEAD
 1.40.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.40.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.41.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.42.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.42.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.43.4.3 11-Mar-2010  yamt sync with head
 1.43.4.2 04-May-2009  yamt sync with head.
 1.43.4.1 16-May-2008  yamt sync with head.
 1.43.2.1 18-May-2008  yamt sync with head.
 1.45.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.45.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.47.36.1 10-Aug-2014  tls Rebase.
 1.47.22.2 03-Dec-2017  jdolecek update from HEAD
 1.47.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.47.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.48.4.1 09-Jul-2016  skrll Sync with HEAD
 1.49.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.49.18.1 10-Jun-2019  christos Sync with HEAD
 1.49.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 11-Dec-2005  christos branches: 1.3.70; 1.3.72; 1.3.74;
merge ktrace-lwp.
 1.2 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.1 11-Aug-1998  thorpej branches: 1.1.46;
Device driver for the Quality Semiconductor QS6612 PHY, found in
SMC EtherPower-II cards.
 1.1.46.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.46.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.46.1 03-Aug-2004  skrll Sync with HEAD
 1.3.74.1 16-May-2008  yamt sync with head.
 1.3.72.1 18-May-2008  yamt sync with head.
 1.3.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.8 08-Apr-2020  msaitoh Add two new RDC PHYs from Andrius V.
 1.7 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.6 05-Feb-2020  msaitoh RDC -> xxRDC. No functional change.
 1.5 27-Nov-2019  msaitoh branches: 1.5.2;
- Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.4 25-Mar-2019  msaitoh branches: 1.4.4;
KNF. No functional change.
 1.3 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.2 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.1 26-Jan-2011  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.54; 1.1.60; 1.1.62;
Add a driver for the RDC Semiconductor RDC R6040 10/100 Ethernet controller,
as found in the vortex86 SoCs (http://www.vortex86dx.com).
Ported from freebsd.
Not added to amd64's GENERIC because this CPU is 32bit only.

thanks to DM&P Electronics, Inc for providing documentation and sample
devices for this work.
 1.1.62.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.62.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.62.1 10-Jun-2019  christos Sync with HEAD
 1.1.60.1 26-Jan-2019  pgoyette Sync with HEAD
 1.1.54.1 14-Apr-2020  martin Pull up the following revisions, requested by msaitoh in ticket #1529:

sys/dev/mii/miidevs 1.154, 1.162-1.167
sys/dev/mii/atphy.c 1.28 via patch
sys/dev/mii/brgphy.c 1.87 via patch
sys/dev/mii/etphy.c 1.5, 1.6 via patch
sys/dev/mii/rdcphy.c 1.6, 1.8 via patch

- Add support Broadcom BCM54213PE and some new RDC devices.
- Rename RDC to xxRDC.
- Use xxVIA instead of VIA.
- etphy(4):
- Rename ET1011 to ET1011C and add ET1011 support.
- Use mii_phy_flowstatus() to reflect flow status from negotiated
result.
- Use static.
- KNF.
 1.1.8.2 06-Jun-2011  jruoho Sync with HEAD.
 1.1.8.1 26-Jan-2011  jruoho file rdcphy.c was added on branch jruoho-x86intr on 2011-06-06 09:08:07 +0000
 1.1.4.2 05-Mar-2011  rmind sync with head
 1.1.4.1 26-Jan-2011  rmind file rdcphy.c was added on branch rmind-uvmplock on 2011-03-05 20:53:32 +0000
 1.1.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 26-Jan-2011  bouyer file rdcphy.c was added on branch bouyer-quota2 on 2011-02-08 16:19:49 +0000
 1.4.4.1 14-Apr-2020  martin Pull up following revision(s) (requested by msaitoh in ticket #831):

sys/dev/mii/rdcphy.c: revision 1.6
sys/dev/mii/rdcphy.c: revision 1.8
sys/dev/mii/miidevs: revision 1.162
sys/dev/mii/miidevs: revision 1.163
sys/dev/mii/miidevs: revision 1.164
sys/dev/mii/miidevs: revision 1.165
sys/dev/mii/miidevs: revision 1.167
sys/dev/mii/brgphy.c: revision 1.87

Change the OUI macro name of RDC to xxRDC. 0x00d02d is non-bitreverse value
of official 0x000bb4. From Andrius V.
RDC -> xxRDC. No functional change.

Add BCM54213PE

Match BCM54213PE

Use xxVIA instead of VIA.
0x004063 is VIA's official OUI but VT6103 use 0x0002c6.
0x0002c6 is non-bitreversed value of 0x004063. Reported by Andrius V.

- Add Quake Technologies and Aeluros' OUI
- Add Teranetics TN1010 10GBase-T PHY
Add two new RDC PHYs from Andrius V.
Add two new RDC PHYs from Andrius V.
 1.5.2.1 29-Feb-2020  ad Sync with head.
 1.1 26-Jan-2011  bouyer branches: 1.1.2; 1.1.4; 1.1.8;
Add a driver for the RDC Semiconductor RDC R6040 10/100 Ethernet controller,
as found in the vortex86 SoCs (http://www.vortex86dx.com).
Ported from freebsd.
Not added to amd64's GENERIC because this CPU is 32bit only.

thanks to DM&P Electronics, Inc for providing documentation and sample
devices for this work.
 1.1.8.2 06-Jun-2011  jruoho Sync with HEAD.
 1.1.8.1 26-Jan-2011  jruoho file rdcphyreg.h was added on branch jruoho-x86intr on 2011-06-06 09:08:07 +0000
 1.1.4.2 05-Mar-2011  rmind sync with head
 1.1.4.1 26-Jan-2011  rmind file rdcphyreg.h was added on branch rmind-uvmplock on 2011-03-05 20:53:32 +0000
 1.1.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 26-Jan-2011  bouyer file rdcphyreg.h was added on branch bouyer-quota2 on 2011-02-08 16:19:49 +0000
 1.59 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.58 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.57 11-Oct-2019  msaitoh - Indicat master mode if the negotiated result say so.
- KNF
 1.56 11-Oct-2019  msaitoh Make new rgephy_linkup() function and share it like FreeBSD.
No functional change intended.
 1.55 05-Jun-2019  triaxx branches: 1.55.2;
Cosmetic changes

Assignment made during declaration.
 1.54 11-Apr-2019  msaitoh KNF. No functional change.
 1.53 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. Same as a part of
FreeBSD r217413.
 1.52 25-Mar-2019  msaitoh KNF. No functional change.
 1.51 26-Feb-2019  msaitoh Add MI MII clause 45 MMD MDIO access macros via clause 22 indirect registers:

DESCRIPTION
static inline int
MMD_INDIRECT(struct mii_softc *sc, uint16_t daddr, uint16_t regnum):
Setup MMD device address and register number. It also setup
address incrementation function.

static inline int
MMD_INDIRECT_READ(struct mii_softc *sc, uint16_t daddr, uint16_t regnum,
uint16_t *valp)):
Do MMD_INDIRECT() and then read the register.

static inline int
MMD_INDIRECT_WRITE(struct mii_softc *sc, uint16_t daddr, uint16_t regnum,
uint16_t val):
Do MMD_INDIRECT() and then write the register.

RETURN VALUE
Retruns 0 on success. Non-zero vaule on failure.

Note that old PHYs have no indirect access registers. Accessing such
devices with these functions cause timeout and return non-zero value
(e.g. ETIMEDOUT).

EXAMPLE
Read MMD Auto negotiation device's EEE advertisement register,
drop 100BASE-TX support and write it.

uint16_t eeadvert;

/* Post increment is not required */
MMD_INDIRECT_READ(sc, MDIO_MMD_AN | MMDACR_FN_DATA,
MDIO_AN_EEEADVERT, &eeadvert);
eeadvert &= ~AN_EEEADVERT_100_TX;

/*
* MMD device address and the register number are already set, so it's
* enough to read MII_MMDACR.
*/
PHY_WRITE(sc. MII_MMDACR, eeadvert);
 1.50 25-Feb-2019  msaitoh MMDACR_FN_{DATANPI,DATAPIRW,DATAPIW} are little hard to identify and might be
misread, so rename them to MMDACR_FN_{DATA,DATA_INC_RW,DATA_INC_W}.
 1.49 25-Feb-2019  msaitoh It seems EEE support is not only on 8211F but on 8211D and newer.
 1.48 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.47 21-Feb-2019  msaitoh Revision 2..5 == RTL8211B...F
 1.46 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.45 16-Jan-2019  msaitoh Pass flags correctly. See also:
http://mail-index.netbsd.org/source-changes/2002/03/25/msg100515.html
 1.44 27-Jun-2018  msaitoh branches: 1.44.2;
Use definitions in mii.h and mdio.h.
 1.43 19-Jun-2018  jmcneill Use symbolic names for chip revision. NFC.
 1.42 03-Feb-2018  jmcneill branches: 1.42.2;
Avoid using proplib in rgephy_reset to make LOCKDEBUG happy.
 1.41 23-Dec-2017  jmcneill Add a no-rx-delay device property for RGE8211E that disables RX internal
delay using some undocumented registers. Required for stable gigabit links
on Pine64+.
 1.40 21-Aug-2015  jmcneill branches: 1.40.10;
Disable link down power save mode and energy efficient ethernet on RTL8211F.
 1.39 31-Mar-2015  jmcneill when resetting RTL8211F, make sure to disable manual MDI mode
 1.38 04-Mar-2015  jmcneill add RTL8211F support
 1.37 09-Nov-2014  nonaka branches: 1.37.2;
more mention RTL8251.
 1.36 09-Nov-2014  nonaka match Realtek RTL8251.
 1.35 17-Dec-2013  martin branches: 1.35.4;
Remove unused variables.
 1.34 16-Dec-2013  jakllsch Use (new) mii_mpd_rev in struct mii_softc rather than providing our own
mii_revision in struct rgephy_softc.
 1.33 16-Jun-2013  msaitoh branches: 1.33.2;
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.32 09-Jun-2013  msaitoh Update link status quickly. This change is a part of FreeBSD's mii_physubr.c
r158649.
 1.31 09-Jun-2013  msaitoh atphy, ciphy, ihphy and rgephy are gigabit PHY, so not only check IFM_AUTO
for autonegotiation but also check IFM_1000_T, too.
 1.30 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.29 18-Jul-2010  jakllsch branches: 1.29.8; 1.29.14; 1.29.18;
Use standard MII register definitions from mii.h. No binary change.
 1.28 23-Aug-2009  tsutsui branches: 1.28.2; 1.28.4;
Remove duplicated PHY_READ() against RGEPHY_MII_BMSR
that FreeBSD said a copy/paste error.
 1.27 28-Apr-2009  tsutsui Remove magic reset sequence except wakeup for rev 2 chips which breaks 8111D.
Problem reported and fix confirmed by Thomas Bieg on current-users.

Also tested on 8111C (no bad side effect) by several users privately.
 1.26 11-Feb-2009  cegger revert changes in rgephy_reset() done in rev. 1.25.
Should fix PR 40586
 1.25 14-Jan-2009  cegger branches: 1.25.2;
pull in changes from FreeBSD:

- reset autonegotation timer if media option is not IFM_AUTO or we got a invalid link.
- Announce link loss right after it happens.
- Autonegotiation is retried every mii_anegticks seconds.
- Report link state changes right after setting autonegotiation.
- use rgephy_reset consistently
- change rgephy_reset to use mii_phy_reset and rgephy_load_dspcode.

These changes give me a speedup from 6.5MB/s to 9.1MB/s on a 100MBit link.
 1.24 09-Jan-2009  cegger add flow control support. From OpenBSD.
 1.23 09-Jan-2009  cegger add support for RTL8211C(L) phy.

From FreeBSD.
 1.22 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.21 04-May-2008  xtraeme branches: 1.21.6; 1.21.8; 1.21.10; 1.21.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.20 08-Apr-2008  cegger branches: 1.20.2; 1.20.4;
use aprint_*_dev and device_xname
 1.19 05-Apr-2008  tsutsui Add support for RealTek RTL8211B(L) PHY. From FreeBSD.
 1.18 26-Jan-2008  tsutsui branches: 1.18.6;
Add a wakeup instruction which is taken from Realtek driver.
Untested on newer chips, but no bad side effect on my 8169S.
 1.17 09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.16 03-Dec-2006  tsutsui branches: 1.16.18; 1.16.20; 1.16.26; 1.16.28; 1.16.30;
- pull the following fix from FreeBSD's rgephy.c rev 1.14:
> - Don't set MIIF_NOISOLATE so rgephy(4) can be used in configurations
> with multiple PHYs and un-comment case IFM_NONE in case MII_MEDIACHG
> rgephy_service(). There doesn't seem to be a problem with isolating
> RTL8169S and their internal PHY.
and rev 1.12:
> - Fix some spelling in comments.
> - Remove superfluous returns at the end of void functions.
> - Remove unused static global rgephy_mii_model.
- remove #ifdef'ed out code whcih has also been removed in FreeBSD
- some style cosmetics
 1.15 29-Nov-2006  tsutsui branches: 1.15.2;
KNF, ANSIfy, unwrap lines.
 1.14 29-Nov-2006  tsutsui Pull some updates from the Realtek's driver:
- set RGEPHY_1000CTL_AHD in rge_reset()
- reset RGEPHY_MII_BMCR register in rge_reset() too

While here, use proper macro rather than magic numbers for
ANAR and BMCR registers there.
 1.13 28-Nov-2006  tsutsui Pull fixes from FreeBSD's rgephy.c:

Revision 1.9:
> 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.

Revision 1.11:
> Due to the poor PHY documentation from RealTek I can't sure but I
> think the RealTek PHY needs driver to set RGEPHY_BMCR_AUTOEN bit of
> RGEPHY_MII_BMCR register and proper ANAR register setting for manual
> media type selection.
> This fixes long standing manual media type selection bug in rgephy(4).
 1.12 16-Nov-2006  christos - don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.11 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.10 09-Nov-2006  tsutsui Add #include <sys/device.h> for struct device.
Fixes compile error on sparc64.
 1.9 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.8 29-Mar-2006  thorpej branches: 1.8.8; 1.8.10;
Use device_private().
 1.7 11-Dec-2005  christos branches: 1.7.4; 1.7.6; 1.7.8; 1.7.10; 1.7.12;
merge ktrace-lwp.
 1.6 23-Mar-2005  wiz branches: 1.6.2;
rgephy(4)'s struct mii_phydesc array doesn't end with NULL.
Fix it. From Satoshi Suetake in PR 29770.
 1.5 27-Feb-2005  perry branches: 1.5.2;
nuke trailing whitespace
 1.4 08-Feb-2005  yamt remove a mysterious printf(" complete\n").
 1.3 04-Feb-2005  kanaoka - Deal with status properly,if BMCR_ISO is set.

Fixes kern/29113.
 1.2 21-Jan-2005  yamt branches: 1.2.2;
remove a duplicated prototype of rgephy_reset.
 1.1 23-Dec-2004  jonathan branches: 1.1.2; 1.1.4;
Snapshot of incomplete-but-working split of re(4) driver into a
bus-independent backend, with PCI and CardBus attachment code.
The committed code has two serious bugs:

1. The driver makes no attempt to recover resources when a (Cardbus)
instance is removed; bus resources are leaked.

2. In testing with a NetGear GA-511, the Cardbus card never responded
to a reset/wakeup if the card is powered down after attachment.
So for now, leave cardbus instances powered up at attachment
(insertion, or at boot if a card is already present).

That aside, it acutally works on my GA-511. Committed as-is despite
the bugs, after repeated requests to make the code available for
further testing. Also requires sys/dev/mii/miidevs rev 1.54 -> 1.55,
and consequent regen of miidevs{,_data}.h.
 1.1.4.7 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.6 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.5 09-Feb-2005  skrll Sync with HEAD.
 1.1.4.4 06-Feb-2005  skrll Sync with HEAD.
 1.1.4.3 24-Jan-2005  skrll Sync with HEAD.
 1.1.4.2 17-Jan-2005  skrll Sync with HEAD.
 1.1.4.1 23-Dec-2004  skrll file rgephy.c was added on branch ktrace-lwp on 2005-01-17 19:31:11 +0000
 1.1.2.1 29-Apr-2005  kent sync with -current
 1.2.2.3 26-Mar-2005  yamt sync with head.
 1.2.2.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.2.1 12-Feb-2005  yamt sync with head.
 1.5.2.2 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.5.2.1 27-Mar-2005  tron Pull up revision 1.6 (requested by wiz in ticket #55):
rgephy(4)'s struct mii_phydesc array doesn't end with NULL.
Fix it. From Satoshi Suetake in PR 29770.
 1.6.2.4 04-Feb-2008  yamt sync with head.
 1.6.2.3 21-Jan-2008  yamt sync with head
 1.6.2.2 30-Dec-2006  yamt sync with head.
 1.6.2.1 21-Jun-2006  yamt sync with head.
 1.7.12.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.7.10.1 19-Apr-2006  elad sync with head.
 1.7.8.1 01-Apr-2006  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.8.10.2 10-Dec-2006  yamt sync with head.
 1.8.10.1 22-Oct-2006  yamt sync with head
 1.8.8.2 12-Jan-2007  ad Sync with head.
 1.8.8.1 18-Nov-2006  ad Sync with head.
 1.15.2.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1339):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114, 1.115, 1.116,
1.117 (via patch), 1.118 (via patch),
1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36, 1.37, 1.38, 1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revisions 1.16, 1.18, 1.19, 1.27 (via patch)
sys/dev/mii/rgephyreg.h: revision 1.3
sys/dev/pci/if_re_pci.c: revision 1.36
- add support for RTL8211B(L) to rgephy(4)
- add a wakeup instruction for rgephy(4) on newer re(4) chips
- detect RTL8169CP, RTL8168D/8111D, and RTL8103E variants
- fix rgephy(4) problem on RTL8111D reported on current-users:
http://mail-index.NetBSD.org/current-users/2009/04/12/msg008977.html
http://mail-index.NetBSD.org/current-users/2009/04/19/msg009096.html
- pull more quirk handling from FreeBSD
- fix RX hwcksum for DESCV2 chips for PR kern/40605
- remove "B" suffix from RTL8168 device names in attach message
 1.16.30.1 11-Dec-2007  yamt sync with head.
 1.16.28.1 26-Dec-2007  ad Sync with head.
 1.16.26.1 18-Feb-2008  mjf Sync with HEAD.
 1.16.20.2 23-Mar-2008  matt sync with HEAD
 1.16.20.1 09-Jan-2008  matt sync with HEAD
 1.16.18.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.16.18.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.18.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.18.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.20.4.4 11-Aug-2010  yamt sync with head.
 1.20.4.3 16-Sep-2009  yamt sync with head
 1.20.4.2 04-May-2009  yamt sync with head.
 1.20.4.1 16-May-2008  yamt sync with head.
 1.20.2.1 18-May-2008  yamt sync with head.
 1.21.14.1 21-Apr-2010  matt sync to netbsd-5
 1.21.10.1 19-Jun-2009  snj Pull up following revision(s) (requested by tsutsui in ticket #821):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114-1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36-1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revision 1.27 via patch
sys/dev/pci/if_re_pci.c: revision 1.36
remove extra semicolons.
--
Add HWREV values of RTL8168CP and RTL8168D. From FreeBSD.

XXX: needs more quirk handling after wakeup for newer chips.
--
Add HWREV of RTL8102EL variant. From FUKAUMI Naoki.
--
Assume an unknown HWREV chip has the same features with the latest one.
--
Remove suffix "B" from rtk_name of PCI_PRODUCT_REALTEK_RT8168 devices.
All 8168/8111 variants (8168/8168B/8168C/8168CP/8168D/8111B/8111C/8111CP)
have the same PCI device ID.
--
Remove magic reset sequence except wakeup for rev 2 chips which breaks 8111D.
Problem reported and fix confirmed by Thomas Bieg on current-users.

Also tested on 8111C (no bad side effect) by several users privately.
--
Pull some changes for newer chips from FreeBSD:
- pull MACSTAT and CMDSTOP quirks for 8168/8111 chips
- always set CPLUSCMD_PCI_MRW on reset
- set VLANSTRIP and RXCSUM_ENB bits on CPLUS register per if_capenable

Tested on 8111C and 8111D by several users, and
no bad side effect on my old 8169S.
--
Remove unused sc_rev settings (all quirks are handled by sc_quirk)
and merge HWREV cases which have the same quirks.
--
- rename RTK_HWREV_8102EL_SPIN2 -> RTK_HWREV_8103E
- add a HWREV value for 8168DP
Per Realtek's Linux drivers.
--
Two fixes for RX hwcsum on DESCV2 chips:
* On checking TCPv4/UDPv4 RX checksum on DESCV2 chips, also check
RE_RDESC_VLANCTL_IPV4 bit because those DESCV2 chips may also recognize
IPv6 packets and set RE_PROTOID_TCPIP or RE_PROTOID_UDPIP bits for
TCPv6/UDPv6 packets. This may fix PR kern/40605.
* According to Realtek's Linux driver, DESCV2 chips don't set RE_PROTOID_IP
for non-TCP/UDP IP packets (set only RE_RDESC_VLANCTL_IPV[46]) so
remove PROTOID check for IPv4 RX cheksum on DESCV2 chips.
 1.21.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.21.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.21.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.25.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.28.4.1 05-Mar-2011  rmind sync with head
 1.28.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.29.18.3 03-Dec-2017  jdolecek update from HEAD
 1.29.18.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.18.1 23-Jun-2013  tls resync from head
 1.29.14.2 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.29.14.1 04-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1146):
sys/dev/mii/mii_physubr.c: revision 1.79
sys/dev/mii/rgephy.c: revision 1.33
sys/dev/mii/brgphy.c: revision 1.66
sys/dev/mii/atphy.c: revision 1.15
sys/dev/mii/mii.h: revision 1.17
The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro. Same as other *BSDs.
 1.29.8.1 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.33.2.1 18-May-2014  rmind sync with head
 1.35.4.4 04-Nov-2015  riz Pull up following revision(s) (requested by jmcneill in ticket #960):
sys/dev/mii/rgephy.c: revision 1.40
sys/dev/mii/rgephyreg.h: revision 1.9
Disable link down power save mode and energy efficient ethernet on RTL8211F.
add some more RTL8211F bits
 1.35.4.3 30-Apr-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #722):
sys/dev/mii/rgephy.c: revision 1.39
sys/dev/mii/rgephyreg.h: revision 1.8
when resetting RTL8211F, make sure to disable manual MDI mode
 1.35.4.2 21-Mar-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #624):
sys/dev/mii/rgephy.c: revision 1.38
sys/dev/mii/rgephyreg.h: revision 1.7
add RTL8211F support
 1.35.4.1 17-Jan-2015  martin Pull up following revision(s) (requested by nonaka in ticket #434):
sys/dev/mii/rgephy.c: revision 1.36, 1.37

Add support for Realtek RTL8251.
 1.37.2.2 22-Sep-2015  skrll Sync with HEAD
 1.37.2.1 06-Apr-2015  skrll Sync with HEAD
 1.40.10.3 24-Oct-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1413:

sys/dev/mii/rgephy.c 1.43, 1.47, 1.49, 1.54-1.57
sys/dev/mii/rgephyreg.h 1.10, 1.12
(both via patch)

- It seems EEE support is not only on 8211F but on 8211D and newer.
- Indicate master mode if the negotiated result say so.
- Use symbolic names for chip revision.
- Cosmetic changes.
- KNF.
 1.40.10.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.40.10.1 31-Jan-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1177):

sys/dev/mii/rgephy.c: revision 1.45
sys/dev/mii/urlphy.c: revision 1.32

Pass flags correctly. See also:
http://mail-index.netbsd.org/source-changes/2002/03/25/msg100515.html
 1.42.2.4 26-Jan-2019  pgoyette Sync with HEAD
 1.42.2.3 18-Jan-2019  pgoyette Synch with HEAD
 1.42.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.42.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.44.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.44.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.44.2.1 10-Jun-2019  christos Sync with HEAD
 1.55.2.1 17-Oct-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #347):

sys/dev/mii/ciphy.c: revision 1.35
sys/dev/mii/rgephy.c: revision 1.56
sys/dev/mii/rgephy.c: revision 1.57

Make new rgephy_linkup() function and share it like FreeBSD.
No functional change intended.

- Indicate master mode if the negotiated result say so.
- KNF
 1.12 25-Feb-2019  msaitoh It seems EEE support is not only on 8211F but on 8211D and newer.
 1.11 27-Jun-2018  msaitoh branches: 1.11.2;
Use definitions in mii.h and mdio.h.
 1.10 19-Jun-2018  jmcneill Use symbolic names for chip revision. NFC.
 1.9 21-Aug-2015  jmcneill branches: 1.9.10; 1.9.16;
add some more RTL8211F bits
 1.8 31-Mar-2015  jmcneill when resetting RTL8211F, make sure to disable manual MDI mode
 1.7 04-Mar-2015  jmcneill add RTL8211F support
 1.6 18-Jul-2010  jakllsch branches: 1.6.18; 1.6.34; 1.6.36;
Use standard MII register definitions from mii.h. No binary change.
 1.5 09-Jan-2009  cegger branches: 1.5.4; 1.5.6;
add support for RTL8211C(L) phy.

From FreeBSD.
 1.4 03-Dec-2008  tsutsui Add RCS Id.
 1.3 05-Apr-2008  tsutsui branches: 1.3.4; 1.3.10; 1.3.12;
Add support for RealTek RTL8211B(L) PHY. From FreeBSD.
 1.2 29-Nov-2006  tsutsui branches: 1.2.2; 1.2.48;
Fix #ifdef/#endif comment mismatch.
 1.1 23-Dec-2004  jonathan branches: 1.1.4; 1.1.12; 1.1.40; 1.1.42;
Snapshot of incomplete-but-working split of re(4) driver into a
bus-independent backend, with PCI and CardBus attachment code.
The committed code has two serious bugs:

1. The driver makes no attempt to recover resources when a (Cardbus)
instance is removed; bus resources are leaked.

2. In testing with a NetGear GA-511, the Cardbus card never responded
to a reset/wakeup if the card is powered down after attachment.
So for now, leave cardbus instances powered up at attachment
(insertion, or at boot if a card is already present).

That aside, it acutally works on my GA-511. Committed as-is despite
the bugs, after repeated requests to make the code available for
further testing. Also requires sys/dev/mii/miidevs rev 1.54 -> 1.55,
and consequent regen of miidevs{,_data}.h.
 1.1.42.1 10-Dec-2006  yamt sync with head.
 1.1.40.1 12-Jan-2007  ad Sync with head.
 1.1.12.1 30-Dec-2006  yamt sync with head.
 1.1.4.2 17-Jan-2005  skrll Sync with HEAD.
 1.1.4.1 23-Dec-2004  skrll file rgephyreg.h was added on branch ktrace-lwp on 2005-01-17 19:31:11 +0000
 1.2.48.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.48.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1339):
sys/dev/ic/rtl8169.c: revisions 1.107, 1.114, 1.115, 1.116,
1.117 (via patch), 1.118 (via patch),
1.119, 1.121
sys/dev/ic/rtl81x9reg.h: revisions 1.36, 1.37, 1.38, 1.39
sys/dev/ic/rtl81x9var.h: revision 1.47
sys/dev/mii/rgephy.c: revisions 1.16, 1.18, 1.19, 1.27 (via patch)
sys/dev/mii/rgephyreg.h: revision 1.3
sys/dev/pci/if_re_pci.c: revision 1.36
- add support for RTL8211B(L) to rgephy(4)
- add a wakeup instruction for rgephy(4) on newer re(4) chips
- detect RTL8169CP, RTL8168D/8111D, and RTL8103E variants
- fix rgephy(4) problem on RTL8111D reported on current-users:
http://mail-index.NetBSD.org/current-users/2009/04/12/msg008977.html
http://mail-index.NetBSD.org/current-users/2009/04/19/msg009096.html
- pull more quirk handling from FreeBSD
- fix RX hwcksum for DESCV2 chips for PR kern/40605
- remove "B" suffix from RTL8168 device names in attach message
 1.3.12.1 19-Jan-2009  skrll Sync with HEAD.
 1.3.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.4.2 11-Aug-2010  yamt sync with head.
 1.3.4.1 04-May-2009  yamt sync with head.
 1.5.6.1 05-Mar-2011  rmind sync with head
 1.5.4.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.6.36.2 22-Sep-2015  skrll Sync with HEAD
 1.6.36.1 06-Apr-2015  skrll Sync with HEAD
 1.6.34.3 04-Nov-2015  riz Pull up following revision(s) (requested by jmcneill in ticket #960):
sys/dev/mii/rgephy.c: revision 1.40
sys/dev/mii/rgephyreg.h: revision 1.9
Disable link down power save mode and energy efficient ethernet on RTL8211F.
add some more RTL8211F bits
 1.6.34.2 30-Apr-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #722):
sys/dev/mii/rgephy.c: revision 1.39
sys/dev/mii/rgephyreg.h: revision 1.8
when resetting RTL8211F, make sure to disable manual MDI mode
 1.6.34.1 21-Mar-2015  snj Pull up following revision(s) (requested by jmcneill in ticket #624):
sys/dev/mii/rgephy.c: revision 1.38
sys/dev/mii/rgephyreg.h: revision 1.7
add RTL8211F support
 1.6.18.1 03-Dec-2017  jdolecek update from HEAD
 1.9.16.2 28-Jul-2018  pgoyette Sync with HEAD
 1.9.16.1 25-Jun-2018  pgoyette Sync with HEAD
 1.9.10.1 24-Oct-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1413:

sys/dev/mii/rgephy.c 1.43, 1.47, 1.49, 1.54-1.57
sys/dev/mii/rgephyreg.h 1.10, 1.12
(both via patch)

- It seems EEE support is not only on 8211F but on 8211D and newer.
- Indicate master mode if the negotiated result say so.
- Use symbolic names for chip revision.
- Cosmetic changes.
- KNF.
 1.11.2.1 10-Jun-2019  christos Sync with HEAD
 1.39 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.38 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.37 19-Sep-2019  msaitoh - ICPLUS -> xxICPLUS
- Print model name if it's ICPLUS IP101 to avoid "Realtek internal PHY".
 1.36 25-Mar-2019  msaitoh branches: 1.36.4;
KNF. No functional change.
 1.35 08-Mar-2019  msaitoh Use static.
 1.34 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.33 09-Feb-2019  rin Support RTL8152. Tested on ure(4) (RTL8152).
 1.32 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.31 07-Jan-2019  msaitoh Fix a bug that rlphy might ignore the link partner's advertised speed.
 1.30 07-Jul-2016  msaitoh branches: 1.30.10; 1.30.16; 1.30.18;
KNF. Remove extra spaces. No functional change.
 1.29 16-Jun-2014  msaitoh branches: 1.29.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.28 16-Jun-2014  msaitoh No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.27 20-Jan-2011  pooka branches: 1.27.10; 1.27.14; 1.27.28;
Match only first instance of rlphy, following suite from Free/OpenBSD.

should fix PR kern/42950, variant of patch from "js" on irc
 1.26 14-Nov-2010  mlelstv branches: 1.26.2; 1.26.4;
rlphy fails to work without autonegotiation.

Reason is that ifm_data does not store BMCR data but a media index
that gets poked into the BMCR register.

Setting the BMCR and ANAR registers is correctly handled by the
generic function mii_phy_setmedia.
 1.25 16-Feb-2009  cegger branches: 1.25.4;
fix media priorities:

IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:

1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T

Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.

Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html

got no comments, no objections.
 1.24 16-Jan-2009  cegger branches: 1.24.2;
Use mii_anar(). No functional change.
 1.23 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.22 04-May-2008  xtraeme branches: 1.22.6; 1.22.8; 1.22.10; 1.22.14;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.21 08-Apr-2008  cegger branches: 1.21.2; 1.21.4;
use aprint_*_dev and device_xname
 1.20 29-Dec-2007  dyoung branches: 1.20.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.19 09-Dec-2007  jmcneill branches: 1.19.2;
Merge jmcneill-pm branch.
 1.18 06-Nov-2007  uwe branches: 1.18.2; 1.18.4;
Add missing aprint_naive("\n"); in rlphyattach.
 1.17 19-Oct-2007  ad branches: 1.17.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.16 13-Oct-2007  isaki branches: 1.16.2;
Correct indent.
 1.15 09-May-2007  tsutsui branches: 1.15.6; 1.15.8; 1.15.10;
Fix wrong softc size (missed in the previous).
 1.14 20-Mar-2007  tsutsui Prepare sc_rtl8201l flag in softc and use it in rlphy_status() so that
we don't have to check device names of device_parent(). From FreeBSD.
 1.13 19-Mar-2007  tsutsui Prepare rlphy_reset() and set BMCR_AUTOEN in it.
This makes autonegotiation on rlphy(4) at re(4)
on landisk (8139C+) select 100baseTX full-duplex
at boot time (before first ifconfig) properly,
and there is no bad side effect on rlphy(4) at nfe(4).

This may also fix PR kern/34109.
 1.12 16-Nov-2006  christos branches: 1.12.2; 1.12.4; 1.12.8; 1.12.10; 1.12.12; 1.12.14; 1.12.16;
__unused removal on arguments; approved by core.
 1.11 03-Nov-2006  tsutsui Make rlphy also match if parent MII is re(4) for RTL8139C+ case.
Tested by Brian A. Seklecki.
 1.10 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.9 29-Mar-2006  thorpej branches: 1.9.6; 1.9.10; 1.9.12;
Use device_private().
 1.8 25-Mar-2006  thorpej Use device_parent().
 1.7 14-Mar-2006  chs branches: 1.7.2;
add an rlphy clone from IC Plus. from openbsd.
 1.6 12-Mar-2006  chs fix match for RealTek 8201L.
 1.5 28-Feb-2006  kleink branches: 1.5.2; 1.5.4;
Reduce previous (!is(...) != 0) to (!is(...)).
 1.4 27-Feb-2006  thorpej Use device_is_a() more.
 1.3 27-Feb-2006  thorpej Use device_is_a().
 1.2 20-Feb-2006  thorpej Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.1 04-Jan-2006  xtraeme branches: 1.1.2; 1.1.4; 1.1.6;
Add rlphy(4) (Realtek 8139/8201L PHY) from OpenBSD.
 1.1.6.1 22-Apr-2006  simonb Sync with head.
 1.1.4.1 09-Sep-2006  rpaulo sync with head
 1.1.2.3 01-Mar-2006  yamt sync with head.
 1.1.2.2 15-Jan-2006  yamt sync with head.
 1.1.2.1 04-Jan-2006  yamt file rlphy.c was added on branch yamt-uio_vmspace on 2006-01-15 10:02:48 +0000
 1.5.4.1 19-Apr-2006  elad sync with head.
 1.5.2.2 01-Apr-2006  yamt sync with head.
 1.5.2.1 13-Mar-2006  yamt sync with head.
 1.7.2.2 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.7.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.9.12.2 10-Dec-2006  yamt sync with head.
 1.9.12.1 22-Oct-2006  yamt sync with head
 1.9.10.1 18-Nov-2006  ad Sync with head.
 1.9.6.7 21-Jan-2008  yamt sync with head
 1.9.6.6 15-Nov-2007  yamt sync with head.
 1.9.6.5 27-Oct-2007  yamt sync with head.
 1.9.6.4 03-Sep-2007  yamt sync with head.
 1.9.6.3 30-Dec-2006  yamt sync with head.
 1.9.6.2 21-Jun-2006  yamt sync with head.
 1.9.6.1 29-Mar-2006  yamt file rlphy.c was added on branch yamt-lazymbuf on 2006-06-21 15:04:46 +0000
 1.12.16.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.12.14.1 29-Mar-2007  reinoud Pullup to -current
 1.12.12.1 11-Jul-2007  mjf Sync with head.
 1.12.10.3 23-Oct-2007  ad Sync with head.
 1.12.10.2 27-May-2007  ad Sync with head.
 1.12.10.1 10-Apr-2007  ad Sync with head.
 1.12.8.2 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1673):
distrib/sets/lists/man/mi 1.844, 1.871
share/man/man4/Makefile 1.372, 1.379 via patch
share/man/man4/re.4 1.8, 1.9, 1.11, 1.12
share/man/man4/rgephy.4 1.1
share/man/man4/rlphy.4 1.1, 1.2
sys/arch/amd64/conf/GENERIC 1.79, 1.89
sys/arch/amd64/conf/INSTALL 1.45, 1.49
sys/arch/i386/conf/GENERIC 1.717, 1.747
sys/arch/i386/conf/GENERIC_LAPTOP 1.164
sys/arch/i386/conf/INSTALL 1.277, 1.283
sys/arch/i386/conf/INSTALL_LAPTOP 1.96, 1.98
sys/arch/i386/conf/XEN2_DOM0 1.22 via patch
sys/arch/macppc/conf/GENERIC 1.220, 1.246
sys/arch/macppc/conf/INSTALL 1.96, 1.100
sys/dev/cardbus/if_re_cardbus.c 1.10
sys/dev/cardbus/if_rtk_cardbus.c 1.29-1.31
sys/dev/ic/rtl8169.c 1.14, 1.20, 1.24, 1.25, 1.28-1.61, 1.63, 1.64-1.81 via patch
sys/dev/ic/rtl81x9.c 1.52, 1.54-1.63, 1.65, 1.67-1.70
sys/dev/ic/rtl81x9reg.h 1.15-1.26
sys/dev/ic/rtl81x9var.h 1.19, 1.21-1.37
sys/dev/mii/files.mii 1.38
sys/dev/mii/miidevs 1.62, 1.64
sys/dev/mii/rgephy.c 1.10, 1.13-1.16
sys/dev/mii/rlphy.c 1.1, 1.6, 1.7, 1.11 via patch
sys/dev/pci/if_re_pci.c 1.13, 1.15-1.17, 1.19-1.23
sys/dev/pci/if_rtk_pci.c 1.25, 1.28, 1.29, 1.31
sys/dev/pci/pcidevs 1.851, 1.852

on re(4):
- improve stability (I believe ;-)
- add a workaround for hardware ip4csum-tx bug
- support newer chips (8169SB/SC, PCIe based 8168 etc.)
- fix 8139C+ support
- enable hardware VLAN
- misc bus_dma(9) fix (which makes re(4) work on mips ports)

on rtk(4):
- fix kern/31348
- fix possible panic on dreamcast
 1.12.8.1 16-Nov-2006  bouyer file rlphy.c was added on branch netbsd-3 on 2007-03-03 23:30:25 +0000
 1.12.4.2 17-May-2007  yamt sync with head.
 1.12.4.1 24-Mar-2007  yamt sync with head.
 1.12.2.2 30-Mar-2008  jdc Pull up revisions 1.14-1.15 (requested by tsutsui in ticket #1111).

Prepare sc_rtl8201l flag in softc and use it in rlphy_status() so that
we don't have to check device names of device_parent(). From FreeBSD.

Fix wrong softc size (missed in the previous).
 1.12.2.1 09-Mar-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1098):
sys/dev/mii/rlphy.c: revision 1.13
Prepare rlphy_reset() and set BMCR_AUTOEN in it.
This makes autonegotiation on rlphy(4) at re(4)
on landisk (8139C+) select 100baseTX full-duplex
at boot time (before first ifconfig) properly,
and there is no bad side effect on rlphy(4) at nfe(4).
This may also fix PR kern/34109.
 1.15.10.1 14-Oct-2007  yamt sync with head.
 1.15.8.2 09-Jan-2008  matt sync with HEAD
 1.15.8.1 06-Nov-2007  matt sync with HEAD
 1.15.6.4 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.15.6.3 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.15.6.2 06-Nov-2007  joerg Sync with HEAD.
 1.15.6.1 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.2.2 13-Nov-2007  bouyer Sync with HEAD
 1.16.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.17.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.17.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.17.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.18.4.1 11-Dec-2007  yamt sync with head.
 1.18.2.1 26-Dec-2007  ad Sync with head.
 1.19.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.20.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.20.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.4.2 04-May-2009  yamt sync with head.
 1.21.4.1 16-May-2008  yamt sync with head.
 1.21.2.1 18-May-2008  yamt sync with head.
 1.22.14.1 21-Apr-2010  matt sync to netbsd-5
 1.22.10.1 01-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #474):
sys/dev/mii/inphy.c: revision 1.51
sys/dev/mii/iophy.c: revision 1.35
sys/dev/mii/nsphy.c: revision 1.56
sys/dev/mii/rlphy.c: revision 1.25
sys/dev/mii/ukphy_subr.c: revision 1.11
sys/dev/pci/if_txp.c: revision 1.28
fix media priorities:
IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:
1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T
Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.
Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html
got no comments, no objections.
 1.22.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.22.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.22.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.24.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.25.4.1 05-Mar-2011  rmind sync with head
 1.26.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.26.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.27.28.1 10-Aug-2014  tls Rebase.
 1.27.14.2 03-Dec-2017  jdolecek update from HEAD
 1.27.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.10.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.29.4.1 09-Jul-2016  skrll Sync with HEAD
 1.30.18.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.30.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.30.18.1 10-Jun-2019  christos Sync with HEAD
 1.30.16.2 26-Jan-2019  pgoyette Sync with HEAD
 1.30.16.1 18-Jan-2019  pgoyette Synch with HEAD
 1.30.10.1 25-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1457:

sys/dev/mii/miidevs 1.155-1.157, 1.159-1.160
sys/dev/mii/rlphy.c 1.37 via patch

- miidevs update:
- Add Teranetics, Aquantia and Renesas.
- Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3).
- Fix typo. from vezhlys.
- Rename JMICRON 0x0021 from JMC250 to JMP211
- Rename JMICRON 0x0022 from JMC260 to JMP202
- rlphy(4): Print model name if it's ICPLUS IP101 to avoid printing
"Realtek internal PHY".
 1.36.4.1 25-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #473):

sys/dev/mii/rlphy.c: revision 1.37
sys/dev/mii/miidevs: revision 1.155
sys/dev/mii/miidevs: revision 1.156
sys/dev/mii/miidevs: revision 1.157
sys/dev/mii/miidevs: revision 1.159
sys/dev/mii/miidevs: revision 1.160

Add Teranetics, Aquantia and Renesas.

Use uppercase for vendor name.

Change ICPLUS(0x0090c3) to xxICPLUS(0x0009c3)
- ICPLUS -> xxICPLUS
- Print model name if it's ICPLUS IP101 to avoid "Realtek internal PHY".

Fix typo. from vezhlys
- Rename JMICRON 0x0021 from JMC250 to JMP211
- Rename JMICRON 0x0022 from JMC260 to JMP202
 1.4 25-Aug-2021  andvar Add missing RCSID and __KERNEL_RCSID().
 1.3 15-Mar-2020  thorpej branches: 1.3.4;
Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.2 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.1 01-Nov-2019  msaitoh branches: 1.1.2;
Port SMSC LAN87xx 10/100 Ethernet PHY driver from FreeBSD with some cleanup
and IFM_NONE support.
 1.1.2.2 25-Nov-2019  martin Regen for ticket 479
 1.1.2.1 01-Nov-2019  martin file smscphy.c was added on branch netbsd-9 on 2019-11-25 16:53:55 +0000
 1.3.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.4.1 15-Mar-2020  martin file smscphy.c was added on branch phil-wifi on 2020-04-13 08:04:24 +0000
 1.56 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.55 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.54 25-Mar-2019  msaitoh KNF. No functional change.
 1.53 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.52 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.51 07-Jul-2016  msaitoh branches: 1.51.16; 1.51.18;
KNF. Remove extra spaces. No functional change.
 1.50 16-Jun-2014  msaitoh branches: 1.50.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.49 19-Oct-2009  bouyer branches: 1.49.18; 1.49.22; 1.49.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.48 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.47 04-May-2008  xtraeme branches: 1.47.6; 1.47.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.46 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.45 08-Apr-2008  cegger branches: 1.45.2; 1.45.4;
use aprint_*_dev and device_xname
 1.44 29-Dec-2007  dyoung branches: 1.44.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.43 09-Dec-2007  jmcneill branches: 1.43.2;
Merge jmcneill-pm branch.
 1.42 16-Nov-2006  christos branches: 1.42.22; 1.42.24; 1.42.30; 1.42.34; 1.42.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.41 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.40 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.39 29-Mar-2006  thorpej branches: 1.39.8; 1.39.10;
Use device_private().
 1.38 20-Feb-2006  thorpej branches: 1.38.2; 1.38.4; 1.38.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.37 11-Dec-2005  christos branches: 1.37.2; 1.37.4; 1.37.6;
merge ktrace-lwp.
 1.36 27-Feb-2005  perry branches: 1.36.4;
nuke trailing whitespace
 1.35 23-Aug-2004  thorpej branches: 1.35.4; 1.35.6;
Make use of static.
 1.34 29-Apr-2003  thorpej branches: 1.34.2;
Use aprint*().
 1.33 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.32 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.31 28-Sep-2002  thorpej Remove a debugging printf.
 1.30 28-Sep-2002  scw Try a little harder to work around the "Isolated After Reset" lossage.
 1.29 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.28 26-Aug-2002  scw Add support for the SMsC LAN83C183 PHY, which actually probes as a
Seeq 84220.

Also add an 84220-specific work-around for some braindamage (at least
in the PHY I'm working with) where the PHY always comes out of reset
isolated, regardless of the previous state of the BMCR_ISO bit. This
happens even if the PHY has address zero, which is contrary to the
part's datasheet...

The work-around is only applied if we notice BMCR_ISO is set when it
should be clear following reset. The fix is to wait 30mS and clear
it manually. (The change doesn't stick if it's cleared sooner than this)
 1.27 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.26 25-Mar-2002  thorpej branches: 1.26.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.25 13-Nov-2001  lukem add RCSID
 1.24 25-Aug-2001  thorpej ANSI'ify.
 1.23 19-Jun-2001  thorpej branches: 1.23.2;
Add support for the Seeq 80225 10/100 Ethernet PHY. This is just
a stripped-down version of the 80220/80223.
 1.22 02-Jun-2001  thorpej Make PHY matching all table-driven.
 1.21 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.20 28-Mar-2001  drochner update for miidevs changes
 1.19 04-Jul-2000  thorpej branches: 1.19.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.18 06-Mar-2000  thorpej branches: 1.18.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.17 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.16 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.15 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.14 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.13 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.12 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.11 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.10 14-May-1999  drochner branches: 1.10.2; 1.10.4; 1.10.8;
use the new "xx" prefixed OUIs because the mapping to the ID register
bits differs from the MII_OUI() way
 1.9 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.8 05-Nov-1998  thorpej branches: 1.8.6;
Common code for media-from-bmcr.
 1.7 05-Nov-1998  thorpej In the status routine, always use the media selected in the BMCR if
autonegotiation is not enabled. This is more reliable on many PHYs,
and requires fewer register reads.
 1.6 05-Nov-1998  thorpej Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.5 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.4 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.3 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.2 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.1 03-Nov-1998  thorpej Driver for Seeq 80220/80221/80223 10/100 Ethernet PHYs.
 1.8.6.1 23-Apr-1999  perry branches: 1.8.6.1.2;
pullup 1.8->1.9 (thorpej): Fix PR7361
 1.8.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.10.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.10.4.1 15-Nov-1999  fvdl Sync with -current
 1.10.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.10.2.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.18.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.19.2.9 18-Oct-2002  nathanw Catch up to -current.
 1.19.2.8 27-Aug-2002  nathanw Catch up to -current.
 1.19.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.19.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.19.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.19.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.19.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.19.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.19.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.23.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.23.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.23.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.23.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.23.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.26.2.2 29-Aug-2002  gehenna catch up with -current.
 1.26.2.1 15-Jul-2002  gehenna catch up with -current.
 1.34.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.34.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.34.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.34.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.35.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.35.4.1 29-Apr-2005  kent sync with -current
 1.36.4.3 21-Jan-2008  yamt sync with head
 1.36.4.2 30-Dec-2006  yamt sync with head.
 1.36.4.1 21-Jun-2006  yamt sync with head.
 1.37.6.1 22-Apr-2006  simonb Sync with head.
 1.37.4.1 09-Sep-2006  rpaulo sync with head
 1.37.2.1 01-Mar-2006  yamt sync with head.
 1.38.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.38.4.1 19-Apr-2006  elad sync with head.
 1.38.2.1 01-Apr-2006  yamt sync with head.
 1.39.10.2 10-Dec-2006  yamt sync with head.
 1.39.10.1 22-Oct-2006  yamt sync with head
 1.39.8.1 18-Nov-2006  ad Sync with head.
 1.42.36.1 11-Dec-2007  yamt sync with head.
 1.42.34.1 26-Dec-2007  ad Sync with head.
 1.42.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.42.24.1 09-Jan-2008  matt sync with HEAD
 1.42.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.42.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.43.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.44.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.44.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.45.4.3 11-Mar-2010  yamt sync with head
 1.45.4.2 04-May-2009  yamt sync with head.
 1.45.4.1 16-May-2008  yamt sync with head.
 1.45.2.1 18-May-2008  yamt sync with head.
 1.47.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.47.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.49.36.1 10-Aug-2014  tls Rebase.
 1.49.22.2 03-Dec-2017  jdolecek update from HEAD
 1.49.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.49.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.50.4.1 09-Jul-2016  skrll Sync with HEAD
 1.51.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.18.1 10-Jun-2019  christos Sync with HEAD
 1.51.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 11-Dec-2005  christos branches: 1.4.70; 1.4.72; 1.4.74;
merge ktrace-lwp.
 1.3 02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.2 19-Jun-2001  thorpej branches: 1.2.22;
Add support for the Seeq 80225 10/100 Ethernet PHY. This is just
a stripped-down version of the 80220/80223.
 1.1 03-Nov-1998  thorpej branches: 1.1.24;
Driver for Seeq 80220/80221/80223 10/100 Ethernet PHYs.
 1.1.24.1 24-Aug-2001  nathanw Catch up with -current.
 1.2.22.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.22.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.22.1 03-Aug-2004  skrll Sync with HEAD
 1.4.74.1 16-May-2008  yamt sync with head.
 1.4.72.1 18-May-2008  yamt sync with head.
 1.4.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.72 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.71 07-Jul-2020  msaitoh branches: 1.71.20;
- Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.70 07-Jul-2020  msaitoh - Call tlphy_auto correctly.
- It's not required to do busy-wait by mii_phy_auto(sc, 1). Now there is
no any PHY driver which calls mii_phy_auto(sc, 1).
 1.69 07-Jul-2020  msaitoh "no media present" is intended case on tlphy(4), so don't use
aprint_error_dev().
 1.68 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.67 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.66 25-Mar-2019  msaitoh KNF. No functional change.
 1.65 05-Mar-2019  msaitoh mii_phy_add_media() automatically install power handler, but if_media_add()
doesn't. When mii_phy_add_media() isn't used, call pmf_device_register().
 1.64 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.63 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.62 16-Jun-2014  msaitoh branches: 1.62.20; 1.62.26; 1.62.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.61 11-Jun-2013  msaitoh branches: 1.61.6;
Remove duplicated code. The code to check IFF_UP and autonegotiation
is in mii_phy_tick(), too.
 1.60 09-Jun-2013  msaitoh Don't "return" but "break" in MII_TICK when the interface isn't doing
autonegotiaton or the link is up to update the status.
 1.59 19-Oct-2009  bouyer branches: 1.59.12; 1.59.18; 1.59.22;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.58 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.57 06-May-2008  tsutsui branches: 1.57.6; 1.57.8;
Rename some softc variables for readability.
 1.56 04-May-2008  xtraeme device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.55 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.54 08-Apr-2008  cegger branches: 1.54.2; 1.54.4;
use aprint_*_dev and device_xname
 1.53 29-Dec-2007  dyoung branches: 1.53.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.52 09-Dec-2007  jmcneill branches: 1.52.2;
Merge jmcneill-pm branch.
 1.51 19-Oct-2007  ad branches: 1.51.2; 1.51.4; 1.51.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.50 16-Nov-2006  christos branches: 1.50.8; 1.50.22; 1.50.24; 1.50.28;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.49 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.48 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.47 29-Mar-2006  thorpej branches: 1.47.8; 1.47.10;
Fix an oversight in previous.
 1.46 29-Mar-2006  thorpej Use device_private().
 1.45 25-Mar-2006  thorpej Use device_parent().
 1.44 20-Feb-2006  thorpej branches: 1.44.2; 1.44.4; 1.44.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.43 11-Dec-2005  christos branches: 1.43.2; 1.43.4; 1.43.6;
merge ktrace-lwp.
 1.42 27-Feb-2005  perry branches: 1.42.4;
nuke trailing whitespace
 1.41 23-Aug-2004  thorpej branches: 1.41.4; 1.41.6;
Make use of static.
 1.40 30-Sep-2003  tron Fix build problem caused by integration of new I2C framework.
 1.39 29-Apr-2003  thorpej branches: 1.39.2;
Use aprint*().
 1.38 23-Oct-2002  perry fix lint warnings about things being stringified under cpp -traditional
 1.37 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.36 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.35 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.34 25-Mar-2002  thorpej Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.33 13-Nov-2001  lukem add RCSID
 1.32 25-Aug-2001  thorpej ANSI'ify.
 1.31 04-Aug-2001  bouyer Ops, forgot to commit this one:
- kill carrier detection code, it's not that usefull and give false indications
on loaded ethernet segments
 1.30 02-Jun-2001  thorpej branches: 1.30.2;
Make PHY matching all table-driven.
 1.29 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.28 28-Mar-2001  drochner update for miidevs changes
 1.27 11-Oct-2000  sommerfeld branches: 1.27.2;
Silence format warning.
 1.26 04-Jul-2000  thorpej Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.25 06-Mar-2000  thorpej branches: 1.25.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.24 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 1.23 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.22 02-Feb-2000  thorpej Bring some order to the chaos which was the MII code function naming
"conventions".
 1.21 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.20 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.19 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.18 14-May-1999  drochner branches: 1.18.2; 1.18.4; 1.18.8;
use the new "xx" prefixed OUIs because the mapping to the ID register
bits differs from the MII_OUI() way
 1.17 23-Apr-1999  thorpej Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.16 05-Nov-1998  thorpej branches: 1.16.6;
Place the essentially common "ticks" and "active" members into the
mii_softc (generic phy goo), and just switch all of the PHY drivers
(except tlphy, which really does have special stuff) to use an mii_softc
instead of a private one.
 1.15 04-Nov-1998  thorpej Return a higher-priority match than 1. These are specific drivers. This
allows for a "generic unknown PHY" driver to be implemented.
 1.14 04-Nov-1998  thorpej Factor out the common reset code. Use the NOISOLATE flags as appropriate
to prevent a PHY from being isolated in the event the MAC can't deal with
this. (3Com 3c905B-TX, and Intel i82557).
 1.13 04-Nov-1998  thorpej Factor out some common code from all the PHY drivers (autonegotiation, for
now.)
 1.12 04-Nov-1998  thorpej Define and use generic PHY read/write reg macros.
 1.11 02-Nov-1998  thorpej When doing a media change service request, use the media word from the
current ifmedia_entry, not from the user-supplied media word. The
user supplied media word may not necessarily match e.g. instance (if
the parent MAC driver is intentionally ignoring instance if its expecting
multiple PHYs with non-overlapping media, e.g. TI ThunderLAN) the media
word we are actually switching to.

Since PHY drivers use `instance' to determine if they should isolate
themselves, the ThunderLAN PHY was sometimes being incorrectly isolated
when in fact the user attempted to select that PHY (for e.g. BNC operation).
 1.10 17-Aug-1998  bouyer - use sc_tlphycap with bitmasks instead of direct comparaison (needed now
that we may have (TLPHY_MEDIA_10_x | TLPHY_MEDIA_NO_10_T).
- add carrier detect for AUI/BNC.

This now works properly with a "Compaq Netelligent 10/100 TX" and a
"Compaq ProLiant Integrated Netelligent 10/100 TX", untested with others
(but should work as well).
 1.9 12-Aug-1998  thorpej If autonegotiation is enabled in the BMSR, and the BMCR doens't claim
that it has completed, report "none" as the active media type.
 1.8 12-Aug-1998  thorpej Ugh, don't print out "autonegotiation failed to complete" if it did.
We get these once a second if we're in auto mode, the interface is up,
and there's no carrier.
 1.7 10-Aug-1998  thorpej Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.

XXX There is still some work to do wrt. autonegotiation and the
BNC/AUI support in the ThunderLAN PHY.
 1.6 09-Jun-1998  thorpej Nuke __BROKEN_INDIRECT_CONFIG.
 1.5 12-Jan-1998  thorpej Adjust for config changes.
 1.4 17-Nov-1997  thorpej KNF.
 1.3 16-Nov-1997  christos PR/4510: William Coldwell: Recognize TI thunderlan.
 1.2 21-Oct-1997  bouyer Correct 'ThunderLAN' spelling
 1.1 17-Oct-1997  bouyer branches: 1.1.2;
Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.1.2.2 17-Nov-1997  thorpej sync w/ trunk.
 1.1.2.1 21-Oct-1997  mrg pull up from trunk: Correct ThunderLAN spelling
 1.16.6.1 23-Apr-1999  perry branches: 1.16.6.1.2;
pullup 1.16->1.17 (thorpej): Fix PR7361
 1.16.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.18.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.4.1 15-Nov-1999  fvdl Sync with -current
 1.18.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.18.2.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.25.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.27.2.8 11-Nov-2002  nathanw Catch up to -current
 1.27.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.27.2.6 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.27.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.27.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.27.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.27.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.27.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.30.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.30.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.30.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.30.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.30.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.39.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.39.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.39.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.39.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.39.2.1 03-Aug-2004  skrll Sync with HEAD
 1.41.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.41.4.1 29-Apr-2005  kent sync with -current
 1.42.4.4 21-Jan-2008  yamt sync with head
 1.42.4.3 27-Oct-2007  yamt sync with head.
 1.42.4.2 30-Dec-2006  yamt sync with head.
 1.42.4.1 21-Jun-2006  yamt sync with head.
 1.43.6.1 22-Apr-2006  simonb Sync with head.
 1.43.4.1 09-Sep-2006  rpaulo sync with head
 1.43.2.1 01-Mar-2006  yamt sync with head.
 1.44.6.2 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.44.6.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.44.4.1 19-Apr-2006  elad sync with head.
 1.44.2.1 01-Apr-2006  yamt sync with head.
 1.47.10.2 10-Dec-2006  yamt sync with head.
 1.47.10.1 22-Oct-2006  yamt sync with head
 1.47.8.1 18-Nov-2006  ad Sync with head.
 1.50.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.50.24.2 09-Jan-2008  matt sync with HEAD
 1.50.24.1 06-Nov-2007  matt sync with HEAD
 1.50.22.3 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.50.22.2 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.50.22.1 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.50.8.1 23-Oct-2007  ad Sync with head.
 1.51.6.1 11-Dec-2007  yamt sync with head.
 1.51.4.1 26-Dec-2007  ad Sync with head.
 1.51.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.52.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.53.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.53.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.54.4.3 11-Mar-2010  yamt sync with head
 1.54.4.2 04-May-2009  yamt sync with head.
 1.54.4.1 16-May-2008  yamt sync with head.
 1.54.2.1 18-May-2008  yamt sync with head.
 1.57.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.57.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.59.22.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.59.22.1 23-Jun-2013  tls resync from head
 1.59.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.59.12.1 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.61.6.1 10-Aug-2014  tls Rebase.
 1.62.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.62.28.1 10-Jun-2019  christos Sync with HEAD
 1.62.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.62.20.1 29-Mar-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1224):

sys/dev/mii/tlphy.c: revision 1.65
sys/dev/usb/if_url.c: revision 1.62
sys/dev/usb/if_aue.c: revision 1.148

mii_phy_add_media() automatically install power handler, but if_media_add()
doesn't. When mii_phy_add_media() isn't used, call pmf_device_register().

-

Use pmf(9).

-

Use pmf(9).
 1.71.20.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.4 10-Aug-1998  thorpej Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.

XXX There is still some work to do wrt. autonegotiation and the
BNC/AUI support in the ThunderLAN PHY.
 1.3 17-Nov-1997  thorpej Cosmetic changes.
 1.2 21-Oct-1997  bouyer Correct 'ThunderLAN' spelling
 1.1 17-Oct-1997  bouyer branches: 1.1.2;
Generic functions for the MII layer. mii attaches to mii-capable network
adapters, and provide media-selections and status to the parent.
This includes drivers for the Thunderland integrated PHY, and
National Semiconductor's DP83840A.
Note: The interface betweeen network controller and mii is not complete yet,
and will need some minors tweaks to support media auto-selection.
 1.1.2.1 21-Oct-1997  mrg pull up from trunk: Correct ThunderLAN spelling
 1.5 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.4 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.3 11-Dec-2005  christos branches: 1.3.74;
merge ktrace-lwp.
 1.2 27-Feb-2005  perry nuke trailing whitespace
 1.1 10-Aug-1998  thorpej branches: 1.1.46; 1.1.54; 1.1.56;
Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.

XXX There is still some work to do wrt. autonegotiation and the
BNC/AUI support in the ThunderLAN PHY.
 1.1.56.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.54.1 29-Apr-2005  kent sync with -current
 1.1.46.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.3.74.1 11-Mar-2010  yamt sync with head
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 10-Aug-1998  thorpej branches: 1.1.144; 1.1.146; 1.1.148;
Adapt to the new MII layer. This PHY driver now properly supports
802.3u autonegotiation, and will report the precise media selected
by autonegotiation by reading PHY-specific registers.

XXX There is still some work to do wrt. autonegotiation and the
BNC/AUI support in the ThunderLAN PHY.
 1.1.148.1 16-May-2008  yamt sync with head.
 1.1.146.1 18-May-2008  yamt sync with head.
 1.1.144.1 02-Jun-2008  mjf Sync with HEAD.
 1.45 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.44 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.43 25-Mar-2019  msaitoh KNF. No functional change.
 1.42 24-Feb-2019  christos use a macro to tidy up the phydesc array initialization, from FreeBSD
 1.41 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.40 07-Jul-2016  msaitoh branches: 1.40.16; 1.40.18;
KNF. Remove extra spaces. No functional change.
 1.39 16-Jun-2014  msaitoh branches: 1.39.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.38 19-Oct-2009  bouyer branches: 1.38.18; 1.38.22; 1.38.36;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.37 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.36 04-May-2008  xtraeme branches: 1.36.6; 1.36.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.35 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.34 08-Apr-2008  cegger branches: 1.34.2; 1.34.4;
use aprint_*_dev and device_xname
 1.33 29-Dec-2007  dyoung branches: 1.33.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.32 09-Dec-2007  jmcneill branches: 1.32.2;
Merge jmcneill-pm branch.
 1.31 16-Nov-2006  christos branches: 1.31.22; 1.31.24; 1.31.30; 1.31.34; 1.31.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.30 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.29 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.28 29-Mar-2006  thorpej branches: 1.28.8; 1.28.10;
Use device_private().
 1.27 20-Feb-2006  thorpej branches: 1.27.2; 1.27.4; 1.27.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.26 11-Dec-2005  christos branches: 1.26.2; 1.26.4; 1.26.6;
merge ktrace-lwp.
 1.25 27-Feb-2005  perry branches: 1.25.4;
nuke trailing whitespace
 1.24 23-Aug-2004  thorpej branches: 1.24.4; 1.24.6;
Make use of static.
 1.23 29-Apr-2003  thorpej branches: 1.23.2;
Use aprint*().
 1.22 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.21 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.20 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.19 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.18 15-Apr-2002  mycroft branches: 1.18.2;
For 78Q2120 revisions 3 and earlier, punt to ukphy, as our special media status
routine does not work on those chips.
 1.17 25-Mar-2002  thorpej Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.16 13-Nov-2001  lukem add RCSID
 1.15 25-Aug-2001  thorpej ANSI'ify.
 1.14 02-Jun-2001  thorpej branches: 1.14.2;
Make PHY matching all table-driven.
 1.13 31-May-2001  thorpej Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.12 28-Mar-2001  drochner update for miidevs changes
 1.11 04-Jul-2000  thorpej branches: 1.11.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.10 06-Mar-2000  thorpej branches: 1.10.4;
Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.9 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.8 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 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 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.4 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.3 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.2 07-Sep-1999  soren branches: 1.2.2; 1.2.4; 1.2.8;
Note 78Q2121.
 1.1 05-Sep-1999  soren Add driver for the TDK Semiconductor 78Q2120 PHY.
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.1 15-Nov-1999  fvdl Sync with -current
 1.2.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.2.2.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.10.4.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.11.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.11.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.11.2.6 17-Apr-2002  nathanw Catch up to -current.
 1.11.2.5 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.11.2.4 14-Nov-2001  nathanw Catch up to -current.
 1.11.2.3 21-Sep-2001  nathanw Catch up to -current.
 1.11.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.11.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.14.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.14.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.14.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.14.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.14.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.18.2.1 15-Jul-2002  gehenna catch up with -current.
 1.23.2.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.23.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.24.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.24.4.1 29-Apr-2005  kent sync with -current
 1.25.4.3 21-Jan-2008  yamt sync with head
 1.25.4.2 30-Dec-2006  yamt sync with head.
 1.25.4.1 21-Jun-2006  yamt sync with head.
 1.26.6.1 22-Apr-2006  simonb Sync with head.
 1.26.4.1 09-Sep-2006  rpaulo sync with head
 1.26.2.1 01-Mar-2006  yamt sync with head.
 1.27.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.27.4.1 19-Apr-2006  elad sync with head.
 1.27.2.1 01-Apr-2006  yamt sync with head.
 1.28.10.2 10-Dec-2006  yamt sync with head.
 1.28.10.1 22-Oct-2006  yamt sync with head
 1.28.8.1 18-Nov-2006  ad Sync with head.
 1.31.36.1 11-Dec-2007  yamt sync with head.
 1.31.34.1 26-Dec-2007  ad Sync with head.
 1.31.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.31.24.1 09-Jan-2008  matt sync with HEAD
 1.31.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.31.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.32.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.33.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.33.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.34.4.3 11-Mar-2010  yamt sync with head
 1.34.4.2 04-May-2009  yamt sync with head.
 1.34.4.1 16-May-2008  yamt sync with head.
 1.34.2.1 18-May-2008  yamt sync with head.
 1.36.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.36.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.38.36.1 10-Aug-2014  tls Rebase.
 1.38.22.2 03-Dec-2017  jdolecek update from HEAD
 1.38.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.39.4.1 09-Jul-2016  skrll Sync with HEAD
 1.40.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.40.18.1 10-Jun-2019  christos Sync with HEAD
 1.40.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 27-Feb-2005  perry nuke trailing whitespace
 1.2 16-Sep-1999  soren branches: 1.2.36; 1.2.44; 1.2.46;
Fix botched RCS IDs.
 1.1 05-Sep-1999  soren TDK Semiconductor 78Q2120 PHY, commonly used in low-power Cardbus cards.
 1.2.46.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.44.1 29-Apr-2005  kent sync with -current
 1.2.36.1 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.55 29-Jun-2021  pgoyette Rework the xxxVERBOSE option to share the common module-hook-based
verbose mechanism with MIIVERBOSE. This reduces some duplicated code
and allows us to once again permit auto-unload of MIIVERBOSE.

Change details:
* Update dev/devlist2h.awk to accomodate miidevs, including generation
of MII_STR_oui_model definitions and use of oui and model rather than
vendor and product. This also changes the compressed data in the
xxxdevs_data.h files to uint32_t (since mii oui's are up to 6 hex
digits long)
* Update a couple of phy drivers to use new calls to get verbose data
* Regen all of the xxxdevs{,_data}.h files (separate commit, coming
very soon)
* Update mii/mii_verbose.[ch] and mii/mii_physubr.c to use the various
DEV_VERBOSE_xxx macros
* Update the pci, usb, and hdaudio code as needed, to #include the
xxxdevs.h files (in order to get the proper printf format strings)
* Since dev/dev_verbose.c now uses non-literal printf format strings,
(to deal with the vendor/product vs oui/model issue), we need to
make sure it gets compiled with -Wno-error=format-nonliteral, even
in userland's libpci and librumpdev!
* Bump kernel version for the change in module interfaces

Welcome to 9.99.86!

XXX It might be useful in the future to extend the MII_STR_oui_model
XXX definitions to PCI as well (and perhaps USB and HDAUDIO). This
XXX would allow for a single centralized location for the products'
XXX descriptions, rather than being dispersed among individual
XXX drivers' xxx_match tables.
 1.54 28-Mar-2020  thorpej branches: 1.54.8;
Don't set DVF_DETACH_SHUTDOWN. The MII layer wants to manage the lifecycle
of the PHY devices, and if a NIC driver chooses not to detach its PHYs
at shutdown, that's the driver's business.

PR kern/55121.
 1.53 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.52 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.51 25-Mar-2019  msaitoh KNF. No functional change.
 1.50 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.49 07-Jul-2016  msaitoh branches: 1.49.16; 1.49.18;
KNF. Remove extra spaces. No functional change.
 1.48 30-Oct-2015  msaitoh igphy(4),ukphy(4): Set mii_mpd_* entries.
wm(4): check PHY type correctly.
 1.47 24-Aug-2015  pooka add some _KERNEL_OPT as the finishing touch
 1.46 11-Jun-2013  msaitoh branches: 1.46.8; 1.46.10;
Remove wrong autonegotiation check. The mii_phy_tick() checks about
autonegotiation correctly. This change fixes the problem that the
autonegotiation timer doesn't work correctly with
"ifcongig xxx media 1000BaseT"
 1.45 09-Jun-2013  msaitoh Tabify. No functional change.
 1.44 09-Jun-2013  msaitoh Don't "return" but "break" in MII_TICK when the interface isn't doing
autonegotiaton or the link is up to update the status.
 1.43 06-Jun-2010  pgoyette branches: 1.43.8; 1.43.14; 1.43.18;
Update miiverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
 1.42 02-Jun-2010  martin Move all miiverbose/module related functions from ukphy.c to mii_physubr.c -
ukphy is not included in all kernels, but mii_physubr.c should be in every
kernel that has a phy.
 1.41 30-May-2010  pgoyette Extract MIIVERBOSE into a kernel module. The module can be builtin
by defining 'options MIIVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.
 1.40 11-Mar-2010  mrg branches: 1.40.2;
various aprint_* fixes.
 1.39 24-Feb-2010  dyoung 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.38 19-Oct-2009  bouyer branches: 1.38.2;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.37 23-Aug-2009  jmcneill Save a line of dmesg by printing the OUI/model after the locators.
 1.36 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.35 04-May-2008  xtraeme branches: 1.35.6; 1.35.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.34 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.33 08-Apr-2008  cegger branches: 1.33.2; 1.33.4;
use aprint_*_dev and device_xname
 1.32 29-Dec-2007  dyoung branches: 1.32.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.31 09-Dec-2007  jmcneill branches: 1.31.2;
Merge jmcneill-pm branch.
 1.30 16-Nov-2006  christos branches: 1.30.22; 1.30.24; 1.30.30; 1.30.34; 1.30.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.29 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.28 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.27 29-Mar-2006  thorpej branches: 1.27.8; 1.27.10;
Use device_private().
 1.26 20-Feb-2006  thorpej branches: 1.26.2; 1.26.4; 1.26.6;
Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.25 11-Dec-2005  christos branches: 1.25.2; 1.25.4; 1.25.6;
merge ktrace-lwp.
 1.24 23-Aug-2004  thorpej branches: 1.24.12;
Make use of static.
 1.23 29-Apr-2003  thorpej branches: 1.23.2;
Use aprint*().
 1.22 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.21 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.20 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.19 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.18 25-Mar-2002  thorpej branches: 1.18.2;
Get flags passed down to PHY drivers correctly. This was done on
an adhoc basis in a couple of PHY drivers, this fixes it more generally.

Per a discussion w/ Cliff Neighbors <cliff@allegronetworks.com>.
 1.17 13-Nov-2001  lukem add RCSID
 1.16 25-Aug-2001  thorpej ANSI'ify.
 1.15 31-May-2001  thorpej branches: 1.15.2;
Make the number of ticks between auto-negotiation tries PHY-specific,
and default every PHY to 5 seconds (what we used before). If we find
Gig-E media on a PHY, bump it to 10 seconds, since it can take 5
seconds just to negotiate a Gig-E link.
 1.14 30-Apr-2001  thorpej Add code to recognize and set media on GMII (Gigabit MII) PHYs.

802.3 doens't specify ANAR or ANLPAR bits for GMII. Need to
use PHY-specific registers for this, for now, which means we
need specific drivers for the Gigabit-capable PHYs (I think the
most common is the BCM5400).
 1.13 04-Jul-2000  thorpej branches: 1.13.2;
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.12 11-Jun-2000  sommerfeld branches: 1.12.2;
defopt MIIVERBOSE
 1.11 08-May-2000  augustss branches: 1.11.2;
Allow a verbose description to be printed with the option MIIVERBOSE.
 1.10 06-Mar-2000  thorpej Factor out the tick handling code into a common function, and send
rt_ifmsg's when the link speed or link status changes.
 1.9 02-Feb-2000  thorpej Let mii_phy_setmedia() handle the IFM_AUTO case, too.
 1.8 02-Feb-2000  thorpej Make PHY drivers provide a pointer to their status routine, and add
a generic mii_phy_status() that calls back into the PHY. It doesn't
do anything interesting yet, but it will soon.
 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 27-Jan-2000  thorpej Add detachment support to the MII layer.
 1.4 12-Nov-1999  thorpej Add mii_down(), which is used by MAC drivers to inform PHYs that the
interface is now down. PHYs use this to cancel pending asynchronous
operations.
 1.3 03-Nov-1999  thorpej Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.2 23-Apr-1999  thorpej branches: 1.2.2; 1.2.4; 1.2.8;
Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
 1.1 05-Nov-1998  thorpej branches: 1.1.6;
Add a driver for "generic unknown PHYs", meant as a catch-all for
PHYs we don't have specific drivers for. While this will not give
optimum operation, it will allow network interface drivers to at least
function while drivers for their specific PHYs are written.
 1.1.6.1 23-Apr-1999  perry branches: 1.1.6.1.2;
pullup 1.1->1.2 (thorpej): Fix PR7361
 1.1.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.1 15-Nov-1999  fvdl Sync with -current
 1.2.2.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.11.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.1 04-Jul-2000  thorpej Update from trunk:
Restructure the PHY entry points to use a structure of entry points
instead of discrete function pointers, and extend this to include
a "reset" entry point. Make sure any PHY-specific reset routine is
always used, and provide one for the LXT-970 which disables MII
interrupts (as is done for a few other PHYs we have drivers for).
 1.13.2.6 18-Oct-2002  nathanw Catch up to -current.
 1.13.2.5 01-Aug-2002  nathanw Catch up to -current.
 1.13.2.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.13.2.3 14-Nov-2001  nathanw Catch up to -current.
 1.13.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.13.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.2.5 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.15.2.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.15.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.15.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.15.2.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.18.2.1 15-Jul-2002  gehenna catch up with -current.
 1.23.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.23.2.1 25-Aug-2004  skrll Sync with HEAD.
 1.24.12.3 21-Jan-2008  yamt sync with head
 1.24.12.2 30-Dec-2006  yamt sync with head.
 1.24.12.1 21-Jun-2006  yamt sync with head.
 1.25.6.1 22-Apr-2006  simonb Sync with head.
 1.25.4.1 09-Sep-2006  rpaulo sync with head
 1.25.2.1 01-Mar-2006  yamt sync with head.
 1.26.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.26.4.1 19-Apr-2006  elad sync with head.
 1.26.2.1 01-Apr-2006  yamt sync with head.
 1.27.10.2 10-Dec-2006  yamt sync with head.
 1.27.10.1 22-Oct-2006  yamt sync with head
 1.27.8.1 18-Nov-2006  ad Sync with head.
 1.30.36.1 11-Dec-2007  yamt sync with head.
 1.30.34.1 26-Dec-2007  ad Sync with head.
 1.30.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.30.24.1 09-Jan-2008  matt sync with HEAD
 1.30.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.30.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.31.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.32.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.32.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.33.4.5 11-Aug-2010  yamt sync with head.
 1.33.4.4 11-Mar-2010  yamt sync with head
 1.33.4.3 16-Sep-2009  yamt sync with head
 1.33.4.2 04-May-2009  yamt sync with head.
 1.33.4.1 16-May-2008  yamt sync with head.
 1.33.2.1 18-May-2008  yamt sync with head.
 1.35.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.35.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.38.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.38.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.40.2.1 03-Jul-2010  rmind sync with head
 1.43.18.2 03-Dec-2017  jdolecek update from HEAD
 1.43.18.1 23-Jun-2013  tls resync from head
 1.43.14.1 06-May-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1366):
sys/dev/pci/if_wm.c: 1.281, 1.318, 1.320, 1.324-1.332, 1.334, 1.336, 1.343-1.344, 1.347-1.348, 1.350, 1.376-1.382, 1.386-1.387, 1.389 via patch
sys/dev/pci/if_wmreg.h: 1.68-1.70, 1.73-1.77, 1.79-1.80, 1.82, 1.86-1.88 via patch
sys/dev/pci/if_wmvar.h: 1.22-1.23, 1.25-1.30 via patch
sys/dev/mii/igphy.c: 1.25
sys/dev/mii/ukphy.c: 1.48
Sync wm(4) as of if_wm.c rev 1.389 except SERDES, MSI/MSI-X, multiqueue
and NET_MPSAFE:
- Set ICH9 and ICH10's PBA size to 14K if the RX buffer size is more
than 4096. Almost the same as other OSes.
- For 82576 and newer devices, the PBA register is deleted. Don't write
PBA for those chips. Also change the calculation of RX packet buffer
size in new way.
- Print NVM image version and option ROM version.
- Add workaround for I210 Errata 25 and I211 Errata 10 (PLL bug). This
workaround is required if the NVM image version < 3.25.
- Fix a bug that wm_detach() didn't unmap the FHASH's area. Now
"drvctl -d wm0" -> "drvctl -r pci0" works on ICH* and PCH*.
- Add workaround for 82574 Errata 25 and 82583 Errata 12 "Dropped RX
packets" and for 82573 (unknown). Set GCR_L1_ACT_WITHOUT_L0S_RX bit.
The NVM Image version 2.1.4 and newer have this workaround.
- Check PHY type correctly. This change is required to use igphy(4)
device correctly.
- Disable LPLU (Low Power Link Up) on D0 state on 82574, 82583 and ICH*
too.
- Call wm_get_hw_control() correctly. This change fixes a bug that some
AMT based systems doesn't linkup at 1000BaseT. The problem was
observed on HP Compaq dc7700. A lot of fixes have been done for wm(4)
and igphy(4), so now PR#44893 should be fixed.
- Call wm_get_wakeup(sc) before checking WM_F_HAS_AMT. It's required to
check the existence of AMT correctly.
- Fix a problem that wm_gate_hw_phy_config_ich8lan() isn't called in
wm_reset() on PCH2.
- Clear WMREG_WUC in wm_reset() if the chip >= 82544. This might fix
the behavior on suspend/resume.
- Fix logic of wm_check_reset_block() on ICH* and PCH*. This change
might fix a problem that PHY's read/write functions can't get
semaphore.
- On ICH8, call wm_gig_downshift_workaround_ich8lan() when link changed
down.
- Drop PHY_CTRL_GBE_DIS explicitly in wm_lplu_d0_disable() in case BIOS
sets this bit.
- Fix two bugs in wm_kmrn_lock_loss_workaround_ich8lan(). Now the
function checks the status correctly but it causes linkdown up to 10
times, so it's disabled for the time being.
- PR/50527: David Binderman: Fix impossible code. Odd offsets need
special treatment.
- Fix RAL table's size of PCH2 and PCH_LPT.
- PCH_LPT (and newer device) is required to check FWSM_WLOCK_MAC bit to
determine the range of the RAL.
- Use sc->sc_itr instead of hard-coded number.
- Rename wm_tbi_check_link() to wm_tbi_tick() because this function
acts as mii_tick().
- ACK Accelerate Disable in the RFCTL register is not bit 13 but 12.
No binary change because this definition has not used yet.
- Add ACK data Disable bit's definition (not used yet).
- PHY_CTRL_GBE_DIS is not bit 4 but bit 6. This change has no any
effect by default because WM_WOL is not defined yet and
m_kmrn_lock_loss_workaround_ich8lan() is broken.
- Fix wm_check_mng_mode_ich8lan(). This function is used only when
WM_WOL is defined and it's disabled by default.
- Rename wm_check_reset_block() to wm_phy_resetisblocked() and make it
returns bool. No functional change.
- Reorder function definitions and macro definitions. No functional
change.
- Fix comment. Add comment. Update comment.
- KNF.
 1.43.8.1 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.46.10.3 09-Jul-2016  skrll Sync with HEAD
 1.46.10.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.46.10.1 22-Sep-2015  skrll Sync with HEAD
 1.46.8.1 26-Feb-2016  snj Pull up following revision(s) (requested by msaitoh in ticket #1102):
sys/dev/mii/igphy.c: 1.25
sys/dev/mii/ukphy.c: 1.48
sys/dev/pci/if_wm.c: revisions 1.308, 1.318, 1.320, 1.324-1.332, 1.334, 1.336, 1.343-1.344, 1.347-1.348, 1.350, 1.376-1.382, 1.386-1.389 via patch
sys/dev/pci/if_wmreg.h: revisions 1.68-1.70, 1.73-1.77, 1.79-1.80, 1.82, 1.86-1.88 via patch
sys/dev/pci/if_wmvar.h: revisions 1.22-1.23, 1.25-1.30 via patch
Sync wm(4) as of if_wm.c rev 1.389 except MSI/MSI-X, multiqueue and NET_MPSAFE:
- Add C2000 KX and 2.5G support.
- Set ICH9 and ICH10's PBA size to 14K if the RX buffer size is more than
4096. Almost the same as other OSes.
- For 82576 and newer devices, the PBA register is deleted. Don't write PBA
for those chips. Also change the calculation of RX packet buffer size in
new way.
- Fix a lot of bugs to make 82575 and newer SERDES based systems work.
- Print NVM image version and option ROM version.
- Add workaround for I210 Errata 25 and I211 Errata 10 (PLL bug). This
workaround is required if the NVM image version < 3.25.
- Fix a bug that wm_detach() didn't unmap the FHASH's area. Now
"drvct -d wm0" -> "drvctl -r pci0" works on ICH* and PCH*.
- Add workaround for 82574 Errata 25 and 82583 Errata 12 "Dropped RX packets"
and for 82573 (unknown). Set GCR_L1_ACT_WITHOUT_L0S_RX bit. The NVM Image
version 2.1.4 and newer have this workaround.
- Check PHY type correctly. This change is required to use igphy(4) device
correctly.
- Disable LPLU (Low Power Link Up) on D0 state on 82574, 82583 and ICH* too.
- Call wm_get_hw_control() correctly. This change fixes a bug that some AMT
based systems doesn't linkup at 1000BaseT. The problem was observed on HP
Compaq dc7700. A lot of fixes have been done for wm(4) and igphy(4), so now
PR#44893 should be fixed.
- Call wm_get_wakeup(sc) before checking WM_F_HAS_AMT. It's required to
check the existence of AMT correctly.
- Fix a problem that wm_gate_hw_phy_config_ich8lan() isn't called in
wm_reset() on PCH2.
- Clear WMREG_WUC in wm_reset() if the chip >= 82544. This might fix the
behavior on suspend/resume.
- Fix logic of wm_check_reset_block() on ICH* and PCH*. This change might fix
a problem that PHY's read/write functions can't get semaphore.
- On ICH8, call wm_gig_downshift_workaround_ich8lan() when link changed down.
- Drop PHY_CTRL_GBE_DIS explicitly in wm_lplu_d0_disable() in case BIOS sets
this bit.
- Fix two bugs in wm_kmrn_lock_loss_workaround_ich8lan(). Now the function
checks the status correctly but it causes linkdown up to 10 times, so it's
disabled for the time being.
- PR/50527: David Binderman: Fix impossible code. Odd offsets need special
treatment.
- Fix RAL table's size of PCH2 and PCH_LPT.
- PCH_LPT (and newer device) is required to check FWSM_WLOCK_MAC bit to
determine the range of the RAL.
- Use sc->sc_itr instead of hard-coded number.
- Rename wm_tbi_check_link() to wm_tbi_tick() because this function acts as
mii_tick().
- ACK Accelerate Disable in the RFCTL register is not bit 13 but 12.
No binary change because this definition has not used yet.
- Add ACK data Disable bit's definition (not used yet).
- PHY_CTRL_GBE_DIS is not bit 4 but bit 6. This change has no any effect by
default because WM_WOL is not defined yet and
m_kmrn_lock_loss_workaround_ich8lan() is broken.
- Fix wm_check_mng_mode_ich8lan(). This function is used only when WM_WOL is
defined and it's disabled by default.
- Rename wm_check_reset_block() to wm_phy_resetisblocked() and make it returns
bool. No functional change.
- Reorder function definitions and macro definitions. No functional change.
- Fix comment. Add comment. Update comment.
- KNF.
 1.49.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.49.18.1 10-Jun-2019  christos Sync with HEAD
 1.49.16.1 26-Jan-2019  pgoyette Sync with HEAD
 1.54.8.1 01-Aug-2021  thorpej Sync with HEAD.
 1.17 15-Mar-2020  thorpej Define and implement a locking protocol for the ifmedia / mii layers:
- MP-safe drivers provide a mutex to ifmedia that is used to serialize
access to media-related structures / hardware regsiters. Converted
drivers use the new ifmedia_init_with_lock() function for this. The
new name is provided to ease the transition.
- Un-converted drivers continue to call ifmedia_init(), which will supply
a compatibility lock to be used instead. Several media-related entry
points must be aware of this compatibility lock, and are able to acquire
it recursively a limited number of times, if needed. This is a SPIN
mutex with priority IPL_NET.
- This same lock is used to serialize access to PHY registers and other
MII-related data structures.

The PHY drivers are modified to acquire and release the lock, as needed,
and assert the lock is held as a diagnostic aid.

The "usbnet" framework has had an overhaul of its internal locking
protocols to fit in with the media / mii changes, and the drivers adapted.

USB wifi drivers have been changed to provide their own adaptive mutex
to the ifmedia later via a new ieee80211_media_init_with_lock() function.
This is required because the USB drivers need an adaptive mutex.

Besised "usbnet", a few other drivers are converted: vmx, wm, ixgbe / ixv.

mcx also now calls ifmedia_init_with_lock() because it needs to also use
an adaptive mutex. The mcx driver still needs to be fully converted to
NET_MPSAFE.
 1.16 24-Oct-2019  msaitoh Fix a bug that ukphy_status() misunderstand master mode.
 1.15 25-Mar-2019  msaitoh branches: 1.15.4;
KNF. No functional change.
 1.14 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.13 16-Jun-2014  msaitoh branches: 1.13.20; 1.13.26; 1.13.28;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.12 16-Jun-2014  msaitoh No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
 1.11 16-Feb-2009  cegger branches: 1.11.18; 1.11.22; 1.11.36;
fix media priorities:

IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:

1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T

Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.

Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html

got no comments, no objections.
 1.10 28-Apr-2008  martin branches: 1.10.8; 1.10.10; 1.10.14; 1.10.18;
Remove clause 3 and 4 from TNF licenses
 1.9 11-Dec-2005  christos branches: 1.9.70; 1.9.72; 1.9.74;
merge ktrace-lwp.
 1.8 17-May-2004  thorpej If the PHY has 1000BASE-T capability, check to see if a 1000BASE-T speed
was negotiated, and check if we ended up mastering the clock if so.
 1.7 16-May-2004  thorpej Get flow control negotiation status.
 1.6 03-Jul-2002  simonb branches: 1.6.6; 1.6.8;
Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.5 13-Nov-2001  lukem branches: 1.5.8;
add RCSID
 1.4 25-Aug-2001  thorpej ANSI'ify.
 1.3 03-Nov-1999  thorpej branches: 1.3.6; 1.3.8;
Clean up the code that adds media a little, and make media selection
table-driven in preparation for some other changes to be made.
 1.2 05-Nov-1998  thorpej branches: 1.2.12; 1.2.14; 1.2.18;
Common code for media-from-bmcr.
 1.1 04-Nov-1998  thorpej Routines common between the Uknown PHY driver (forthcoming) and other
PHY drivers. This file has ukphy_status(), which is what PHY drivers
should use if media detection is done by decoding NWay.
 1.2.18.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.14.1 15-Nov-1999  fvdl Sync with -current
 1.2.12.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.3.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.8.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.8.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.3.6.3 01-Aug-2002  nathanw Catch up to -current.
 1.3.6.2 14-Nov-2001  nathanw Catch up to -current.
 1.3.6.1 21-Sep-2001  nathanw Catch up to -current.
 1.5.8.1 15-Jul-2002  gehenna catch up with -current.
 1.6.8.1 12-Aug-2004  jmc Pullup patch (requested by toshii in ticket #743)

If the PHY has 1000BASE-T capability, check to see if a 1000BASE-T speed
was negotiated, and check if we ended up mastering the clock if so.
 1.6.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.6.6.1 03-Aug-2004  skrll Sync with HEAD
 1.9.74.2 04-May-2009  yamt sync with head.
 1.9.74.1 16-May-2008  yamt sync with head.
 1.9.72.1 18-May-2008  yamt sync with head.
 1.9.70.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.18.1 21-Apr-2010  matt sync to netbsd-5
 1.10.14.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.10.1 01-May-2009  snj Pull up following revision(s) (requested by cegger in ticket #474):
sys/dev/mii/inphy.c: revision 1.51
sys/dev/mii/iophy.c: revision 1.35
sys/dev/mii/nsphy.c: revision 1.56
sys/dev/mii/rlphy.c: revision 1.25
sys/dev/mii/ukphy_subr.c: revision 1.11
sys/dev/pci/if_txp.c: revision 1.28
fix media priorities:
IEEE 802.3 Annex 28B.3 specifies the following relative
priorities of the technologies supported by
802.3 Selector Field value:
1000BASE-T full duplex
1000BASE-T
100BASE-T2 full duplex
100BASE-TX full duplex
100BASE-T2
100BASE-T4
100BASE-TX
10BASE-T full duplex
10BAST-T
Our drivers give 100BASE-T4 a higher priority than
100BASE-TX full duplex.
Fix this. This patch is based on changes in FreeBSD and OpenBSD.
Patch presented on tech-kern and tech-net:
http://mail-index.netbsd.org/tech-kern/2009/02/15/msg004397.html
http://mail-index.netbsd.org/tech-net/2009/02/15/msg001064.html
got no comments, no objections.
 1.10.8.1 03-Mar-2009  skrll Sync with HEAD.
 1.11.36.1 10-Aug-2014  tls Rebase.
 1.11.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.18.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.13.28.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.13.28.1 10-Jun-2019  christos Sync with HEAD
 1.13.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.13.20.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1426):

sys/dev/mii/ukphy_subr.c: revision 1.16

Fix a bug that ukphy_status() misunderstand master mode.
 1.15.4.1 06-Nov-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #402):

sys/dev/mii/ukphy_subr.c: revision 1.16

Fix a bug that ukphy_status() misunderstand master mode.
 1.40 22-Feb-2023  msaitoh Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.39 08-Jan-2022  riastradh branches: 1.39.4;
urlphy(4): Fix missing mii locking in urlphy_attach.
 1.38 24-Aug-2020  msaitoh Remove extra PHY_RESET(sc) in the MII_TICK path because it's not requierd
to just restart autonego.
 1.37 24-Aug-2020  msaitoh Don't do full initialization for autonego when just restarting autonego
because it's not required.

This change reduce extra initialization which include PHY_RESET() which
caused long delay(max 500ms).
 1.36 07-Jul-2020  msaitoh - Remove the waitfor argument from mii_phy_auto().
- Whitespace fix.
 1.35 27-Nov-2019  msaitoh - Simplify sc->mii_anegticks setting. Same as FreeBSD.

Don't set the default value not in the attach function. Instead, set the
default value (MII_ANEGTICKS) first in the beginning of the
mii_phy_add_media(). The function already has the code to change the value to
MII_ANEGTICKS_GIGE if it's gigabit capable.

- Remove extra pmf_device_register() call. It's done in mii_phy_add_media().
 1.34 25-Mar-2019  msaitoh KNF. No functional change.
 1.33 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.32 16-Jan-2019  msaitoh Pass flags correctly. See also:
http://mail-index.netbsd.org/source-changes/2002/03/25/msg100515.html
 1.31 07-Jul-2016  msaitoh branches: 1.31.10; 1.31.16; 1.31.18;
KNF. Remove extra spaces. No functional change.
 1.30 16-Jun-2014  msaitoh branches: 1.30.4;
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.29 09-Jun-2013  msaitoh branches: 1.29.6;
Fix a bug in last commit that mii_ticks isn't inclemented.
 1.28 09-Jun-2013  msaitoh Update link status quickly. This change is a part of FreeBSD's mii_physubr.c
r158649.
 1.27 09-Jun-2013  msaitoh Don't "return" but "break" in MII_TICK when the interface isn't doing
autonegotiaton or the link is up to update the status.
 1.26 06-Jun-2013  msaitoh Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.25 31-Jan-2009  hira branches: 1.25.14; 1.25.20; 1.25.24;
Fix typo in comment (OUT -> OUI).
 1.24 17-Nov-2008  dyoung Reduce code duplication: most PHY drivers call mii_phy_add_media()
when they attach to the device tree, so call pmf_device_register(9)
once there instead of once in more than twenty drivers.
 1.23 04-May-2008  xtraeme branches: 1.23.6; 1.23.8;
device_t/softc split for all mii(4) devices, and other related
cosmetic changes.
 1.22 08-Apr-2008  cegger branches: 1.22.2; 1.22.4;
use aprint_*_dev and device_xname
 1.21 29-Dec-2007  dyoung branches: 1.21.6;
Remove the device_is_active() check from each individual PHY's
service routine. Add a wrapper for PHY_SERVICE(), called phy_service(),
and check device_is_active() there. Make the mii_*() routines call
the PHY service routines thorugh phy_service() instead of PHY_SERVICE().

In mii_phy_resume(), restore a PHY's state after resetting it by
sending a MII_MEDIACHG command. This change makes bnx(4) resume
more reliably and more quickly; it should help other NICs to resume,
too, if they attach PHYs through MII.
 1.20 15-Dec-2007  perry __FUNCTION__ -> __func__
 1.19 09-Dec-2007  jmcneill branches: 1.19.2;
Merge jmcneill-pm branch.
 1.18 16-Nov-2006  christos branches: 1.18.22; 1.18.24; 1.18.30; 1.18.34; 1.18.36;
- don't hardcode 5, 10 define and use MII_ANEGTICKS{,_GIGE}
- instead of != limit, use <= limit (conservative)
 1.17 16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.16 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.15 29-Mar-2006  thorpej branches: 1.15.8; 1.15.10;
Use device_private().
 1.14 28-Feb-2006  kleink branches: 1.14.2; 1.14.4; 1.14.6;
Fix inverted device_is_a() use logic in previous.
 1.13 27-Feb-2006  thorpej Use device_is_a().
 1.12 20-Feb-2006  thorpej Use device_is_active() rather than testing dv_flags for DVF_ACTIVE
directly.
 1.11 11-Dec-2005  christos branches: 1.11.2; 1.11.4; 1.11.6;
merge ktrace-lwp.
 1.10 23-Aug-2004  thorpej branches: 1.10.12;
Make use of static.
 1.9 04-Sep-2003  tsutsui Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.
 1.8 29-Apr-2003  thorpej branches: 1.8.2;
Use aprint*().
 1.7 04-Apr-2003  kristerw Save some text segment space by not defining URLPHY_DEBUG.
 1.6 02-Oct-2002  thorpej Add trailing ; to CFATTACH_DECL.
 1.5 30-Sep-2002  thorpej Use CFATTACH_DECL().
 1.4 27-Sep-2002  thorpej Declare all cfattach structures const.
 1.3 27-Sep-2002  thorpej Rather than referencing the cfdriver directly in the cfdata entries,
instead use a string naming the driver. The cfdriver is then looked
up in a list which is built at run-time.
 1.2 03-Jul-2002  simonb Don't include <malloc.h> - no memory management style functions are use
in any of the MII drivers.
 1.1 28-Mar-2002  ichiro branches: 1.1.2; 1.1.4; 1.1.8;
Add a driver for the Realtek RL8150L Ethernet PHY.
 1.1.8.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.8.3 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 28-Mar-2002  jdolecek file urlphy.c was added on branch kqueue on 2002-06-23 17:47:28 +0000
 1.1.4.1 15-Jul-2002  gehenna catch up with -current.
 1.1.2.4 18-Oct-2002  nathanw Catch up to -current.
 1.1.2.3 01-Aug-2002  nathanw Catch up to -current.
 1.1.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.1 28-Mar-2002  nathanw file urlphy.c was added on branch nathanw_sa on 2002-04-01 07:46:15 +0000
 1.8.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.2 25-Aug-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.12.3 21-Jan-2008  yamt sync with head
 1.10.12.2 30-Dec-2006  yamt sync with head.
 1.10.12.1 21-Jun-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.1 01-Mar-2006  yamt sync with head.
 1.14.6.1 31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.14.4.1 19-Apr-2006  elad sync with head.
 1.14.2.1 01-Apr-2006  yamt sync with head.
 1.15.10.2 10-Dec-2006  yamt sync with head.
 1.15.10.1 22-Oct-2006  yamt sync with head
 1.15.8.1 18-Nov-2006  ad Sync with head.
 1.18.36.1 11-Dec-2007  yamt sync with head.
 1.18.34.1 26-Dec-2007  ad Sync with head.
 1.18.30.1 18-Feb-2008  mjf Sync with HEAD.
 1.18.24.1 09-Jan-2008  matt sync with HEAD
 1.18.22.2 08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.18.22.1 27-Nov-2007  joerg Register MII PHY drives with the PM framework. Nothing to do on suspend,
just reset the PHY on resume.
 1.19.2.1 02-Jan-2008  bouyer Sync with HEAD
 1.21.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.21.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.4.2 04-May-2009  yamt sync with head.
 1.22.4.1 16-May-2008  yamt sync with head.
 1.22.2.1 18-May-2008  yamt sync with head.
 1.23.8.2 03-Mar-2009  skrll Sync with HEAD.
 1.23.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.23.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.25.24.3 03-Dec-2017  jdolecek update from HEAD
 1.25.24.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.24.1 23-Jun-2013  tls resync from head
 1.25.20.2 04-Feb-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1245):
sys/dev/mii/rgephy.c: revision 1.30
sys/dev/mii/brgphy.c: revision 1.64
sys/dev/mii/atphy.c: revision 1.13
sys/dev/mii/urlphy.c: revision 1.26
sys/dev/mii/ciphy.c: revision 1.20
sys/dev/mii/mii_physubr.c: revision 1.76
Fix a bug that the auto negotiation timer isn't cleard as we expected.
To not to forget clearing the timer and to reduce the code duplication,
clear mii_ticks in *mii_phy_auto().
 1.25.20.1 09-Nov-2014  martin Pull up following revision(s) (requested by msaitoh in ticket #1189):
sys/dev/pci/if_wm.c: revision 1.270
sys/dev/mii/inphy.c: revision 1.53
sys/dev/mii/glxtphy.c: revision 1.24
sys/dev/mii/tlphy.c: revision 1.62
sys/dev/mii/iophy.c: revision 1.37
sys/dev/mii/brgphy.c: revision 1.70
sys/dev/mii/ihphy.c: revision 1.8
sys/dev/mii/bmtphy.c: revision 1.31
sys/dev/mii/urlphy.c: revision 1.30
sys/dev/mii/makphy.c: revision 1.40
sys/dev/mii/qsphy.c: revision 1.48
sys/dev/mii/igphy.c: revision 1.23
sys/dev/mii/nsphy.c: revision 1.58
sys/dev/mii/mvphy.c: revision 1.10
sys/dev/pci/if_txp.c: revision 1.41
sys/dev/mii/nsphy.c: revision 1.59
sys/dev/mii/rlphy.c: revision 1.28
sys/dev/mii/icsphy.c: revision 1.49
sys/dev/mii/rlphy.c: revision 1.29
sys/dev/mii/lxtphy.c: revision 1.49
sys/dev/mii/ciphyreg.h: revision 1.5
sys/dev/mii/nsphyter.c: revision 1.38
sys/dev/mii/sqphy.c: revision 1.50
sys/dev/mii/gentbi.c: revision 1.26
sys/dev/mii/gentbi.c: revision 1.27
sys/dev/mii/tqphy.c: revision 1.39
sys/dev/mii/ikphy.c: revision 1.10
sys/dev/mii/dmphy.c: revision 1.35
sys/dev/mii/amhphy.c: revision 1.20
sys/dev/mii/acphy.c: revision 1.24
sys/dev/mii/ciphy.c: revision 1.25
sys/dev/mii/brgphyreg.h: revision 1.8
sys/dev/mii/ukphy_subr.c: revision 1.12
sys/dev/ic/rtl80x9.c: revision 1.16
sys/arch/mips/adm5120/dev/if_admsw.c: revision 1.12
sys/dev/pci/if_kse.c: revision 1.28
sys/dev/mii/ukphy_subr.c: revision 1.13
sys/dev/mii/mii.h: revision 1.18
sys/dev/mii/gphyter.c: revision 1.29
No functional change:
- Fix typo.
- Remove trailing white spaces.
- Capitalize comments.
- Tabify.
- KNF.
IFM_FDX and IFM_HDX use different bit, so set IFM_HDX bit if it's not full
duplex. For many drivers, it recognize half duplex if IFM_FDX isn't set,
but not for others. Same as {Free|Open}BSD.
 1.25.14.1 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.29.6.1 10-Aug-2014  tls Rebase.
 1.30.4.1 09-Jul-2016  skrll Sync with HEAD
 1.31.18.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.31.18.1 10-Jun-2019  christos Sync with HEAD
 1.31.16.2 26-Jan-2019  pgoyette Sync with HEAD
 1.31.16.1 18-Jan-2019  pgoyette Synch with HEAD
 1.31.10.1 31-Jan-2019  martin Pull up following revision(s) (requested by msaitoh in ticket #1177):

sys/dev/mii/rgephy.c: revision 1.45
sys/dev/mii/urlphy.c: revision 1.32

Pass flags correctly. See also:
http://mail-index.netbsd.org/source-changes/2002/03/25/msg100515.html
 1.39.4.1 21-Jun-2023  martin Pull up following revision(s) (requested by msaitoh in ticket #208):

sys/dev/mii/ciphy.c: revision 1.42
sys/dev/mii/brgphy.c: revision 1.91
sys/dev/mii/mii_physubr.c: revision 1.102
sys/dev/mii/ipgphy.c: revision 1.11
sys/dev/mii/tlphy.c: revision 1.72
sys/dev/mii/jmphy.c: revision 1.5
sys/dev/mii/urlphy.c: revision 1.40
sys/dev/mii/atphy.c: revision 1.31

Retry autonegotiation every mii_anegticks seconds instead of mii_anegticks+1.
 1.3 11-Dec-2005  christos merge ktrace-lwp.
 1.2 04-Sep-2003  tsutsui Remove advertising clauses from code written by Shingo WATANABE.
He has kindly consented it.
 1.1 28-Mar-2002  ichiro branches: 1.1.2; 1.1.8; 1.1.14;
Add a driver for the Realtek RL8150L Ethernet PHY.
 1.1.14.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.14.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.14.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.1.8.1 28-Mar-2002  jdolecek file urlphyreg.h was added on branch kqueue on 2002-06-23 17:47:29 +0000
 1.1.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.1.2.1 28-Mar-2002  nathanw file urlphyreg.h was added on branch nathanw_sa on 2002-04-01 07:46:15 +0000

RSS XML Feed