2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009, M. Warner Losh
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * driver for internal phy in the AX88x9x chips.
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/socket.h>
44 #include <net/if_media.h>
46 #include <dev/mii/mii.h>
47 #include <dev/mii/miivar.h>
50 #include "miibus_if.h"
52 static int axphy_probe(device_t dev);
53 static int axphy_attach(device_t dev);
55 static device_method_t axphy_methods[] = {
56 /* device interface */
57 DEVMETHOD(device_probe, axphy_probe),
58 DEVMETHOD(device_attach, axphy_attach),
59 DEVMETHOD(device_detach, mii_phy_detach),
60 DEVMETHOD(device_shutdown, bus_generic_shutdown),
64 static devclass_t axphy_devclass;
66 static driver_t axphy_driver = {
69 sizeof(struct mii_softc)
72 DRIVER_MODULE(axphy, miibus, axphy_driver, axphy_devclass, 0, 0);
74 static int axphy_service(struct mii_softc *, struct mii_data *, int);
75 static void axphy_status(struct mii_softc *);
77 static const struct mii_phydesc axphys[] = {
78 MII_PHY_DESC(xxASIX, AX88X9X),
82 static const struct mii_phy_funcs axphy_funcs = {
89 axphy_probe(device_t dev)
92 return (mii_phy_dev_probe(dev, axphys, BUS_PROBE_DEFAULT));
96 axphy_attach(device_t dev)
100 sc = device_get_softc(dev);
102 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
104 mii_phy_setmedia(sc);
110 axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
118 mii_phy_setmedia(sc);
122 if (mii_phy_tick(sc) == EJUSTRETURN)
127 /* Update the media status. */
130 /* Callback if something changed. */
131 mii_phy_update(sc, cmd);
136 axphy_status(struct mii_softc *sc)
138 struct mii_data *mii = sc->mii_pdata;
139 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
142 mii->mii_media_status = IFM_AVALID;
143 mii->mii_media_active = IFM_ETHER;
145 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
146 if (bmsr & BMSR_LINK)
147 mii->mii_media_status |= IFM_ACTIVE;
149 bmcr = PHY_READ(sc, MII_BMCR);
150 if (bmcr & BMCR_ISO) {
151 mii->mii_media_active |= IFM_NONE;
152 mii->mii_media_status = 0;
156 if (bmcr & BMCR_LOOP)
157 mii->mii_media_active |= IFM_LOOP;
159 if (bmcr & BMCR_AUTOEN) {
160 if ((bmsr & BMSR_ACOMP) == 0) {
161 mii->mii_media_active |= IFM_NONE;
166 scr = PHY_READ(sc, MII_AXPHY_SCR);
168 mii->mii_media_active |= IFM_100_TX;
170 mii->mii_media_active |= IFM_10_T;
172 mii->mii_media_active |=
173 IFM_FDX | mii_phy_flowstatus(sc);
175 mii->mii_media_active |= IFM_HDX;
178 mii->mii_media_active = ife->ifm_media;