Index: sys/conf/files =================================================================== --- sys/conf/files +++ sys/conf/files @@ -2406,6 +2406,7 @@ dev/mfi/mfi_cam.c optional mfip scbus dev/mii/acphy.c optional miibus | acphy dev/mii/amphy.c optional miibus | amphy +dev/mii/arphy.c optional miibus | arphy dev/mii/atphy.c optional miibus | atphy dev/mii/axphy.c optional miibus | axphy dev/mii/bmtphy.c optional miibus | bmtphy Index: sys/dev/mii/arphy.c =================================================================== --- /dev/null +++ sys/dev/mii/arphy.c @@ -0,0 +1,166 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Bjoern A. Zeeb + * + * 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +/* + * Driver for the Atheros AR803x (8035) 10/100/1000 PHY + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include "miidevs.h" + +#include "miibus_if.h" + +#define AR_PHY_SPECIFIC_STATUS 0x11 +#define AR_PSS_SPEED (1 << 15 | 1 << 14) +#define AR_PSS_SPEED_10 00 +#define AR_PSS_SPEED_100 01 +#define AR_PSS_SPEED_1000 10 +#define AR_PSS_SPEED_RR 11 +#define AR_PSS_DUPLEX (1 << 13) +#define AR_PSS_DUPLEX_FULL (1 << 13) +#define AR_PSS_DUPLEX_HALF 0 +#define AR_PSS_SPEED_DUPLEX_RESOLVED (1 << 11) + +static const struct mii_phydesc arphys[] = { + MII_PHY_DESC(yyATHEROS, AR803x), + MII_PHY_END +}; + +static int +arphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +{ + + switch (cmd) { + case MII_POLLSTAT: + break; + + case MII_MEDIACHG: + mii_phy_setmedia(sc); + break; + + case MII_TICK: + if (mii_phy_tick(sc) == EJUSTRETURN) + return (0); + break; + } + + /* Update the media status. */ + PHY_STATUS(sc); + + /* Callback if something changed. */ + mii_phy_update(sc, cmd); + return (0); +} + +static void +arphy_status(struct mii_softc *sc) +{ + struct mii_data *mii; + int val; + + mii = sc->mii_pdata; + ukphy_status(sc); + + /* Read the AR803x PHY-specific status register. */ + val = PHY_READ(sc, AR_PHY_SPECIFIC_STATUS); + if (val & AR_PSS_SPEED_DUPLEX_RESOLVED) { + mii->mii_media_active = IFM_ETHER; + + switch (val & AR_PSS_SPEED) { + case AR_PSS_SPEED_1000: + mii->mii_media_active |= IFM_1000_T; + break; + case AR_PSS_SPEED_100: + mii->mii_media_active |= IFM_100_TX; + break; + case AR_PSS_SPEED_10: + mii->mii_media_active |= IFM_10_T; + break; + } + switch (val & AR_PSS_DUPLEX) { + case AR_PSS_DUPLEX_FULL: + mii->mii_media_active |= IFM_FDX; + break; + case AR_PSS_DUPLEX_HALF: + mii->mii_media_active |= IFM_HDX; + break; + } + } +} + +static const struct mii_phy_funcs arphy_funcs = { + arphy_service, + arphy_status, + mii_phy_reset +}; + +static int +arphy_probe(device_t dev) +{ + + return (mii_phy_dev_probe(dev, arphys, BUS_PROBE_DEFAULT)); +} + +static int +arphy_attach(device_t dev) +{ + + mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &arphy_funcs, 1); + return (0); +} + +static device_method_t arphy_methods[] = { + /* Device interface. */ + DEVMETHOD(device_probe, arphy_probe), + DEVMETHOD(device_attach, arphy_attach), + DEVMETHOD(device_detach, mii_phy_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD_END +}; + +static devclass_t arphy_devclass; +static driver_t arphy_driver = { + "arphy", + arphy_methods, + sizeof(struct mii_softc) +}; + +DRIVER_MODULE(arphy, miibus, arphy_driver, arphy_devclass, 0, 0); Index: sys/dev/mii/miidevs =================================================================== --- sys/dev/mii/miidevs +++ sys/dev/mii/miidevs @@ -110,6 +110,7 @@ oui xxPMCSIERRA2 0x009057 PMC-Sierra oui xxREALTEK 0x000732 RealTek Semicondctor oui yyREALTEK 0x000004 RealTek Semicondctor +oui yyATHEROS 0x004dd0 Atheros Communications /* * List of known models. Grouped by oui. @@ -139,6 +140,7 @@ model xxATHEROS F2 0x0002 Atheros F2 10/100 PHY model xxATHEROS AR8021 0x0004 Atheros AR8021 10/100/1000 PHY model xxATHEROS F1_7 0x0007 Atheros F1 10/100/1000 PHY +model yyATHEROS AR803x 0x0003 Atheros AR803x 10/100/1000 PHY /* Asix semiconductor PHYs */ model xxASIX AX88X9X 0x0031 Ax88x9x internal PHY Index: sys/modules/mii/Makefile =================================================================== --- sys/modules/mii/Makefile +++ sys/modules/mii/Makefile @@ -3,7 +3,8 @@ .PATH: ${SRCTOP}/sys/dev/mii KMOD= miibus -SRCS= acphy.c amphy.c atphy.c axphy.c bmtphy.c brgphy.c bus_if.h +SRCS= acphy.c amphy.c arphy.c atphy.c axphy.c +SRCS+= bmtphy.c brgphy.c bus_if.h SRCS+= ciphy.c device_if.h SRCS+= e1000phy.c gentbi.c icsphy.c ip1000phy.c jmphy.c lxtphy.c SRCS+= miibus_if.c miibus_if.h mii.c miidevs.h mii_bitbang.c mii_physubr.c