Index: head/share/man/man4/Makefile =================================================================== --- head/share/man/man4/Makefile +++ head/share/man/man4/Makefile @@ -266,6 +266,7 @@ malo.4 \ mcd.4 \ md.4 \ + mdio.4 \ me.4 \ mem.4 \ meteor.4 \ Index: head/share/man/man4/mdio.4 =================================================================== --- head/share/man/man4/mdio.4 +++ head/share/man/man4/mdio.4 @@ -0,0 +1,53 @@ +.\" Written by Landon Fuller for the FreeBSD Project. +.\" Based on the miibus(4) manual page written by Tom Rhodes. +.\" Please see the /usr/src/COPYRIGHT file for copyright information. +.\" +.\" $FreeBSD$ +.\" +.Dd December 17, 2015 +.Dt MDIO 4 +.Os +.Sh NAME +.Nm mdio +.Nd IEEE 802.3 Management Data Input/Output interface +.Sh SYNOPSIS +To compile this driver into the kernel, +place the following line in your +kernel configuration file: +.Bd -ragged -offset indent +.Cd "device mdio" +.Ed +.Sh DESCRIPTION +The +.Nm +driver provides an interconnection between the Media Access Control (MAC) +sublayer and Physical Layer (PHY) entities' control and status registers, +as defined by the IEEE 802.3 Standard. +.Pp +The +.Nm +layer allows device drivers to share common support code for various +external PHY devices. +.Pp +.Tn MDIO +is one of two signal interfaces that comprise the +Media Independent Interface (MII) defined by the IEEE 802.3 +Standard. The +.Xr miibus 4 +driver provides support for devices that require full +.Tn MII +support. +.Sh SEE ALSO +.Xr miibus 4 +.Sh STANDARDS +More information on +.Tn MDIO +can be found in the IEEE 802.3 Standard. +.Sh HISTORY +The +.Nm +driver first appeared in +.Fx 10.0 . +.Sh AUTHORS +The driver was written by +.An Stefan Bethke Aq Mt stb@lassitu.de . Index: head/sys/conf/files =================================================================== --- head/sys/conf/files +++ head/sys/conf/files @@ -1404,8 +1404,6 @@ dev/etherswitch/ip17x/ip175d.c optional ip17x dev/etherswitch/ip17x/ip17x_phy.c optional ip17x dev/etherswitch/ip17x/ip17x_vlans.c optional ip17x -dev/etherswitch/mdio_if.m optional miiproxy | mdio -dev/etherswitch/mdio.c optional miiproxy | mdio dev/etherswitch/miiproxy.c optional miiproxy dev/etherswitch/rtl8366/rtl8366rb.c optional rtl8366rb dev/etherswitch/ukswitch/ukswitch.c optional ukswitch @@ -1908,6 +1906,8 @@ dev/mcd/mcd.c optional mcd isa nowerror dev/mcd/mcd_isa.c optional mcd isa nowerror dev/md/md.c optional md +dev/mdio/mdio_if.m optional miiproxy | mdio +dev/mdio/mdio.c optional miiproxy | mdio dev/mem/memdev.c optional mem dev/mem/memutil.c optional mem dev/mfi/mfi.c optional mfi Index: head/sys/dev/etherswitch/arswitch/arswitch.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch.c +++ head/sys/dev/etherswitch/arswitch/arswitch.c @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_7240.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_7240.c +++ head/sys/dev/etherswitch/arswitch/arswitch_7240.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_8216.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_8216.c +++ head/sys/dev/etherswitch/arswitch/arswitch_8216.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_8226.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_8226.c +++ head/sys/dev/etherswitch/arswitch/arswitch_8226.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_8316.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_8316.c +++ head/sys/dev/etherswitch/arswitch/arswitch_8316.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_8327.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_8327.c +++ head/sys/dev/etherswitch/arswitch/arswitch_8327.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_9340.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_9340.c +++ head/sys/dev/etherswitch/arswitch/arswitch_9340.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_phy.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_phy.c +++ head/sys/dev/etherswitch/arswitch/arswitch_phy.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/arswitch/arswitch_reg.c =================================================================== --- head/sys/dev/etherswitch/arswitch/arswitch_reg.c +++ head/sys/dev/etherswitch/arswitch/arswitch_reg.c @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/etherswitch/e6000sw/e6000sw.c =================================================================== --- head/sys/dev/etherswitch/e6000sw/e6000sw.c +++ head/sys/dev/etherswitch/e6000sw/e6000sw.c @@ -54,7 +54,7 @@ #include #include -#include +#include #include #include #include Index: head/sys/dev/etherswitch/ip17x/ip17x.c =================================================================== --- head/sys/dev/etherswitch/ip17x/ip17x.c +++ head/sys/dev/etherswitch/ip17x/ip17x.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include Index: head/sys/dev/etherswitch/mdio.h =================================================================== --- head/sys/dev/etherswitch/mdio.h +++ head/sys/dev/etherswitch/mdio.h @@ -1,35 +0,0 @@ -/*- - * Copyright (c) 2011-2012 Stefan Bethke. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __DEV_ETHERSWITCH_MDIO_H__ -#define __DEV_ETHERSWITCH_MDIO_H__ - -extern driver_t mdio_driver; -extern devclass_t mdio_devclass; - -#endif /* __DEV_ETHERSWITCH_MDIO_H__ */ Index: head/sys/dev/etherswitch/mdio.c =================================================================== --- head/sys/dev/etherswitch/mdio.c +++ head/sys/dev/etherswitch/mdio.c @@ -1,117 +0,0 @@ -/*- - * Copyright (c) 2011-2012 Stefan Bethke. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include - -#include "mdio_if.h" - -static void -mdio_identify(driver_t *driver, device_t parent) -{ - - if (device_find_child(parent, mdio_driver.name, -1) == NULL) - BUS_ADD_CHILD(parent, 0, mdio_driver.name, -1); -} - -static int -mdio_probe(device_t dev) -{ - - device_set_desc(dev, "MDIO"); - - return (BUS_PROBE_SPECIFIC); -} - -static int -mdio_attach(device_t dev) -{ - - bus_generic_probe(dev); - bus_enumerate_hinted_children(dev); - return (bus_generic_attach(dev)); -} - -static int -mdio_detach(device_t dev) -{ - - bus_generic_detach(dev); - return (0); -} - -static int -mdio_readreg(device_t dev, int phy, int reg) -{ - - return (MDIO_READREG(device_get_parent(dev), phy, reg)); -} - -static int -mdio_writereg(device_t dev, int phy, int reg, int val) -{ - - return (MDIO_WRITEREG(device_get_parent(dev), phy, reg, val)); -} - -static void -mdio_hinted_child(device_t dev, const char *name, int unit) -{ - - device_add_child(dev, name, unit); -} - -static device_method_t mdio_methods[] = { - /* device interface */ - DEVMETHOD(device_identify, mdio_identify), - DEVMETHOD(device_probe, mdio_probe), - DEVMETHOD(device_attach, mdio_attach), - DEVMETHOD(device_detach, mdio_detach), - DEVMETHOD(device_shutdown, bus_generic_shutdown), - - /* bus interface */ - DEVMETHOD(bus_add_child, device_add_child_ordered), - DEVMETHOD(bus_hinted_child, mdio_hinted_child), - - /* MDIO access */ - DEVMETHOD(mdio_readreg, mdio_readreg), - DEVMETHOD(mdio_writereg, mdio_writereg), - - DEVMETHOD_END -}; - -driver_t mdio_driver = { - "mdio", - mdio_methods, - 0 -}; - -devclass_t mdio_devclass; Index: head/sys/dev/etherswitch/mdio_if.m =================================================================== --- head/sys/dev/etherswitch/mdio_if.m +++ head/sys/dev/etherswitch/mdio_if.m @@ -1,24 +0,0 @@ -# $FreeBSD$ - -#include - -INTERFACE mdio; - -# -# Read register from device on MDIO bus -# -METHOD int readreg { - device_t dev; - int phy; - int reg; -}; - -# -# Write register to device on MDIO bus -# -METHOD int writereg { - device_t dev; - int phy; - int reg; - int val; -}; Index: head/sys/dev/etherswitch/ukswitch/ukswitch.c =================================================================== --- head/sys/dev/etherswitch/ukswitch/ukswitch.c +++ head/sys/dev/etherswitch/ukswitch/ukswitch.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include Index: head/sys/dev/mdio/mdio.h =================================================================== --- head/sys/dev/mdio/mdio.h +++ head/sys/dev/mdio/mdio.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2011-2012 Stefan Bethke. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __DEV_MDIO_MDIO_H__ +#define __DEV_MDIO_MDIO_H__ + +extern driver_t mdio_driver; +extern devclass_t mdio_devclass; + +#endif /* __DEV_MDIO_MDIO_H__ */ Index: head/sys/dev/mdio/mdio.c =================================================================== --- head/sys/dev/mdio/mdio.c +++ head/sys/dev/mdio/mdio.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2011-2012 Stefan Bethke. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include + +#include + +#include "mdio_if.h" + +static void +mdio_identify(driver_t *driver, device_t parent) +{ + + if (device_find_child(parent, mdio_driver.name, -1) == NULL) + BUS_ADD_CHILD(parent, 0, mdio_driver.name, -1); +} + +static int +mdio_probe(device_t dev) +{ + + device_set_desc(dev, "MDIO"); + + return (BUS_PROBE_SPECIFIC); +} + +static int +mdio_attach(device_t dev) +{ + + bus_generic_probe(dev); + bus_enumerate_hinted_children(dev); + return (bus_generic_attach(dev)); +} + +static int +mdio_detach(device_t dev) +{ + + bus_generic_detach(dev); + return (0); +} + +static int +mdio_readreg(device_t dev, int phy, int reg) +{ + + return (MDIO_READREG(device_get_parent(dev), phy, reg)); +} + +static int +mdio_writereg(device_t dev, int phy, int reg, int val) +{ + + return (MDIO_WRITEREG(device_get_parent(dev), phy, reg, val)); +} + +static void +mdio_hinted_child(device_t dev, const char *name, int unit) +{ + + device_add_child(dev, name, unit); +} + +static device_method_t mdio_methods[] = { + /* device interface */ + DEVMETHOD(device_identify, mdio_identify), + DEVMETHOD(device_probe, mdio_probe), + DEVMETHOD(device_attach, mdio_attach), + DEVMETHOD(device_detach, mdio_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + + /* bus interface */ + DEVMETHOD(bus_add_child, device_add_child_ordered), + DEVMETHOD(bus_hinted_child, mdio_hinted_child), + + /* MDIO access */ + DEVMETHOD(mdio_readreg, mdio_readreg), + DEVMETHOD(mdio_writereg, mdio_writereg), + + DEVMETHOD_END +}; + +driver_t mdio_driver = { + "mdio", + mdio_methods, + 0 +}; + +devclass_t mdio_devclass; + +MODULE_VERSION(mdio, 1); Index: head/sys/dev/mdio/mdio_if.m =================================================================== --- head/sys/dev/mdio/mdio_if.m +++ head/sys/dev/mdio/mdio_if.m @@ -0,0 +1,24 @@ +# $FreeBSD$ + +#include + +INTERFACE mdio; + +# +# Read register from device on MDIO bus +# +METHOD int readreg { + device_t dev; + int phy; + int reg; +}; + +# +# Write register to device on MDIO bus +# +METHOD int writereg { + device_t dev; + int phy; + int reg; + int val; +}; Index: head/sys/dev/mge/if_mge.c =================================================================== --- head/sys/dev/mge/if_mge.c +++ head/sys/dev/mge/if_mge.c @@ -74,7 +74,7 @@ #include #include #include -#include +#include #include #include Index: head/sys/modules/Makefile =================================================================== --- head/sys/modules/Makefile +++ head/sys/modules/Makefile @@ -220,6 +220,7 @@ malo \ mcd \ md \ + mdio \ mem \ mfi \ mii \ Index: head/sys/modules/mdio/Makefile =================================================================== --- head/sys/modules/mdio/Makefile +++ head/sys/modules/mdio/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../dev/mdio + +KMOD= mdio +SRCS= mdio.c +SRCS+= mdio_if.c mdio_if.h +SRCS+= device_if.h bus_if.h + +.include