2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009 M. Warner Losh <imp@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 * driver for internal phy in the AX88x9x chips.
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/socket.h>
43 #include <net/if_media.h>
45 #include <dev/mii/mii.h>
46 #include <dev/mii/miivar.h>
49 #include "miibus_if.h"
51 static int axphy_probe(device_t dev);
52 static int axphy_attach(device_t dev);
54 static device_method_t axphy_methods[] = {
55 /* device interface */
56 DEVMETHOD(device_probe, axphy_probe),
57 DEVMETHOD(device_attach, axphy_attach),
58 DEVMETHOD(device_detach, mii_phy_detach),
59 DEVMETHOD(device_shutdown, bus_generic_shutdown),
63 static devclass_t axphy_devclass;
65 static driver_t axphy_driver = {
68 sizeof(struct mii_softc)
71 DRIVER_MODULE(axphy, miibus, axphy_driver, axphy_devclass, 0, 0);
73 static int axphy_service(struct mii_softc *, struct mii_data *, int);
74 static void axphy_status(struct mii_softc *);
76 static const struct mii_phydesc axphys[] = {
77 MII_PHY_DESC(xxASIX, AX88X9X),
81 static const struct mii_phy_funcs axphy_funcs = {
88 axphy_probe(device_t dev)
91 return (mii_phy_dev_probe(dev, axphys, BUS_PROBE_DEFAULT));
95 axphy_attach(device_t dev)
99 sc = device_get_softc(dev);
101 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
103 mii_phy_setmedia(sc);
109 axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
117 mii_phy_setmedia(sc);
121 if (mii_phy_tick(sc) == EJUSTRETURN)
126 /* Update the media status. */
129 /* Callback if something changed. */
130 mii_phy_update(sc, cmd);
135 axphy_status(struct mii_softc *sc)
137 struct mii_data *mii = sc->mii_pdata;
138 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
141 mii->mii_media_status = IFM_AVALID;
142 mii->mii_media_active = IFM_ETHER;
144 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
145 if (bmsr & BMSR_LINK)
146 mii->mii_media_status |= IFM_ACTIVE;
148 bmcr = PHY_READ(sc, MII_BMCR);
149 if (bmcr & BMCR_ISO) {
150 mii->mii_media_active |= IFM_NONE;
151 mii->mii_media_status = 0;
155 if (bmcr & BMCR_LOOP)
156 mii->mii_media_active |= IFM_LOOP;
158 if (bmcr & BMCR_AUTOEN) {
159 if ((bmsr & BMSR_ACOMP) == 0) {
160 mii->mii_media_active |= IFM_NONE;
165 scr = PHY_READ(sc, MII_AXPHY_SCR);
167 mii->mii_media_active |= IFM_100_TX;
169 mii->mii_media_active |= IFM_10_T;
171 mii->mii_media_active |=
172 IFM_FDX | mii_phy_flowstatus(sc);
174 mii->mii_media_active |= IFM_HDX;
177 mii->mii_media_active = ife->ifm_media;