Home | History | Annotate | Download | only in mii
History log of /src/sys/dev/mii/mii.c
RevisionDateAuthorComments
 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().

RSS XML Feed