Annotation of sys/dev/mii/luphy.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: luphy.c,v 1.3 2005/04/15 00:44:39 brad Exp $ */
! 2:
! 3: /*-
! 4: * Copyright (c) 2004 Marius Strobl
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 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.
! 15: *
! 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
! 26: * SUCH DAMAGE.
! 27: */
! 28:
! 29: /*
! 30: * Driver for the Lucent Technologies LU6612 Ethernet 10/100 PHY, which
! 31: * is pin-compatible to the Quality Semiconductor QS6612 but uses a
! 32: * different register layout. Sun Microsystems uses the LU6612 together
! 33: * with their HME chip on a couple of bords originally designed for the
! 34: * QS6612. At least on these boards none of the LU6612 must be isolated
! 35: * otherwise the MII bus wedges and the other one (there can be a maximum
! 36: * of two PHYs connected to the HME) no longer can communicate with the
! 37: * HME (powering down the unused PHY etc. also doesn't help). This is
! 38: * why we can't use the ukphy driver for the LU6612.
! 39: * The datasheet for the LU6612 is no longer available on lucent.com or
! 40: * www.agere.com (former Lucent Microelectronics Group) but you still
! 41: * should be able to find it when searching for DS00355.pdf or LU6612.pdf.
! 42: */
! 43:
! 44: #include <sys/param.h>
! 45: #include <sys/systm.h>
! 46: #include <sys/kernel.h>
! 47: #include <sys/device.h>
! 48: #include <sys/socket.h>
! 49:
! 50: #include <net/if.h>
! 51: #include <net/if_media.h>
! 52:
! 53: #include <dev/mii/mii.h>
! 54: #include <dev/mii/miivar.h>
! 55: #include <dev/mii/miidevs.h>
! 56:
! 57: int luphymatch(struct device *, void *, void *);
! 58: void luphyattach(struct device *, struct device *, void *);
! 59:
! 60: struct cfattach luphy_ca = {
! 61: sizeof(struct mii_softc), luphymatch, luphyattach, mii_phy_detach,
! 62: mii_phy_activate
! 63: };
! 64:
! 65: struct cfdriver luphy_cd = {
! 66: NULL, "luphy", DV_DULL
! 67: };
! 68:
! 69: int luphy_service(struct mii_softc *, struct mii_data *, int);
! 70:
! 71: const struct mii_phy_funcs luphy_funcs = {
! 72: luphy_service, ukphy_status, mii_phy_reset,
! 73: };
! 74:
! 75: static const struct mii_phydesc luphys[] = {
! 76: { MII_OUI_LUCENT, MII_MODEL_LUCENT_LU6612,
! 77: MII_STR_LUCENT_LU6612 },
! 78:
! 79: { 0, 0,
! 80: NULL },
! 81: };
! 82:
! 83: int
! 84: luphymatch(struct device *parent, void *match, void *aux)
! 85: {
! 86: struct mii_attach_args *ma = aux;
! 87:
! 88: if (mii_phy_match(ma, luphys) != NULL)
! 89: return (10);
! 90:
! 91: return (0);
! 92: }
! 93:
! 94: void
! 95: luphyattach(struct device *parent, struct device *self, void *aux)
! 96: {
! 97: struct mii_softc *sc = (struct mii_softc *)self;
! 98: struct mii_attach_args *ma = aux;
! 99: struct mii_data *mii = ma->mii_data;
! 100: const struct mii_phydesc *mpd;
! 101:
! 102: mpd = mii_phy_match(ma, luphys);
! 103: printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
! 104:
! 105: sc->mii_inst = mii->mii_instance;
! 106: sc->mii_phy = ma->mii_phyno;
! 107: sc->mii_funcs = &luphy_funcs;
! 108: sc->mii_pdata = mii;
! 109: sc->mii_flags = ma->mii_flags;
! 110:
! 111: sc->mii_flags |= MIIF_NOISOLATE;
! 112:
! 113: PHY_RESET(sc);
! 114:
! 115: sc->mii_capabilities =
! 116: PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
! 117: if (sc->mii_capabilities & BMSR_MEDIAMASK)
! 118: mii_phy_add_media(sc);
! 119: }
! 120:
! 121: int
! 122: luphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
! 123: {
! 124: struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
! 125:
! 126: switch (cmd) {
! 127: case MII_POLLSTAT:
! 128: /*
! 129: * If we're not polling our PHY instance, just return.
! 130: */
! 131: if (IFM_INST(ife->ifm_media) != sc->mii_inst)
! 132: return (0);
! 133: break;
! 134:
! 135: case MII_MEDIACHG:
! 136: /*
! 137: * If the media indicates a different PHY instance,
! 138: * just return. Isolating unused PHYs from the bus
! 139: * causes at least the MII bus of the HME to wedge.
! 140: */
! 141: if (IFM_INST(ife->ifm_media) != sc->mii_inst)
! 142: return (0);
! 143:
! 144: /*
! 145: * If the interface is not up, don't do anything.
! 146: */
! 147: if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
! 148: break;
! 149:
! 150: mii_phy_setmedia(sc);
! 151: break;
! 152:
! 153: case MII_TICK:
! 154: /*
! 155: * If we're not currently selected, just return.
! 156: */
! 157: if (IFM_INST(ife->ifm_media) != sc->mii_inst)
! 158: return (0);
! 159:
! 160: if (mii_phy_tick(sc) == EJUSTRETURN)
! 161: return (0);
! 162: break;
! 163:
! 164: case MII_DOWN:
! 165: mii_phy_down(sc);
! 166: return (0);
! 167: }
! 168:
! 169: /* Update the media status. */
! 170: mii_phy_status(sc);
! 171:
! 172: /* Callback if something changed. */
! 173: mii_phy_update(sc, cmd);
! 174: return (0);
! 175: }
CVSweb