1 /* 2 * Copyright (c) 2000 Berkeley Software Design, Inc. 3 * Copyright (c) 1997, 1998, 1999, 2000 4 * Bill Paul <wpaul@osd.bsdi.com>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Bill Paul. 17 * 4. Neither the name of the author nor the names of any co-contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * driver for homePNA PHYs 36 * This is really just a stub that allows us to identify homePNA-based 37 * transceicers and display the link status. MII-based homePNA PHYs 38 * only support one media type and no autonegotiation. If we were 39 * really clever, we could tweak some of the vendor-specific registers 40 * to optimize the link. 41 */ 42 43 #include <sys/cdefs.h> 44 __FBSDID("$FreeBSD$"); 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/kernel.h> 49 #include <sys/socket.h> 50 #include <sys/errno.h> 51 #include <sys/module.h> 52 #include <sys/bus.h> 53 54 #include <net/if.h> 55 #include <net/if_media.h> 56 57 58 #include <dev/mii/mii.h> 59 #include <dev/mii/miivar.h> 60 #include "miidevs.h" 61 62 #include "miibus_if.h" 63 64 static int pnaphy_probe(device_t); 65 static int pnaphy_attach(device_t); 66 67 static device_method_t pnaphy_methods[] = { 68 /* device interface */ 69 DEVMETHOD(device_probe, pnaphy_probe), 70 DEVMETHOD(device_attach, pnaphy_attach), 71 DEVMETHOD(device_detach, mii_phy_detach), 72 DEVMETHOD(device_shutdown, bus_generic_shutdown), 73 { 0, 0 } 74 }; 75 76 static devclass_t pnaphy_devclass; 77 78 static driver_t pnaphy_driver = { 79 "pnaphy", 80 pnaphy_methods, 81 sizeof(struct mii_softc) 82 }; 83 84 DRIVER_MODULE(pnaphy, miibus, pnaphy_driver, pnaphy_devclass, 0, 0); 85 86 static int pnaphy_service(struct mii_softc *, struct mii_data *,int); 87 88 static int 89 pnaphy_probe(dev) 90 device_t dev; 91 { 92 93 struct mii_attach_args *ma; 94 95 ma = device_get_ivars(dev); 96 97 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_AMD && 98 MII_MODEL(ma->mii_id2) == MII_MODEL_AMD_79c978) { 99 device_set_desc(dev, MII_STR_AMD_79c978); 100 return(0); 101 } 102 103 return(ENXIO); 104 } 105 106 static int 107 pnaphy_attach(dev) 108 device_t dev; 109 { 110 struct mii_softc *sc; 111 struct mii_attach_args *ma; 112 struct mii_data *mii; 113 const char *sep = ""; 114 115 sc = device_get_softc(dev); 116 ma = device_get_ivars(dev); 117 sc->mii_dev = device_get_parent(dev); 118 mii = device_get_softc(sc->mii_dev); 119 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 120 121 sc->mii_inst = mii->mii_instance; 122 sc->mii_phy = ma->mii_phyno; 123 sc->mii_service = pnaphy_service; 124 sc->mii_pdata = mii; 125 126 mii->mii_instance++; 127 128 sc->mii_flags |= MIIF_NOISOLATE; 129 130 #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) 131 #define PRINT(s) printf("%s%s", sep, s); sep = ", " 132 133 mii_phy_reset(sc); 134 135 sc->mii_capabilities = 136 PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 137 device_printf(dev, " "); 138 if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0) 139 printf("no media present"); 140 else { 141 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_HPNA_1, 0, sc->mii_inst), 0); 142 PRINT("HomePNA"); 143 } 144 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), 145 BMCR_ISO); 146 147 printf("\n"); 148 149 #undef ADD 150 #undef PRINT 151 152 MIIBUS_MEDIAINIT(sc->mii_dev); 153 154 return(0); 155 } 156 157 static int 158 pnaphy_service(sc, mii, cmd) 159 struct mii_softc *sc; 160 struct mii_data *mii; 161 int cmd; 162 { 163 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 164 int reg; 165 166 switch (cmd) { 167 case MII_POLLSTAT: 168 /* 169 * If we're not polling our PHY instance, just return. 170 */ 171 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 172 return (0); 173 break; 174 175 case MII_MEDIACHG: 176 /* 177 * If the media indicates a different PHY instance, 178 * isolate ourselves. 179 */ 180 if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 181 reg = PHY_READ(sc, MII_BMCR); 182 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); 183 return (0); 184 } 185 186 /* 187 * If the interface is not up, don't do anything. 188 */ 189 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 190 break; 191 192 switch (IFM_SUBTYPE(ife->ifm_media)) { 193 case IFM_AUTO: 194 case IFM_10_T: 195 case IFM_100_TX: 196 case IFM_100_T4: 197 return (EINVAL); 198 default: 199 /* 200 * BMCR data is stored in the ifmedia entry. 201 */ 202 PHY_WRITE(sc, MII_ANAR, 203 mii_anar(ife->ifm_media)); 204 PHY_WRITE(sc, MII_BMCR, ife->ifm_data); 205 } 206 break; 207 208 case MII_TICK: 209 /* 210 * If we're not currently selected, just return. 211 */ 212 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 213 return (0); 214 if (mii_phy_tick(sc) == EJUSTRETURN) 215 return (0); 216 break; 217 } 218 219 /* Update the media status. */ 220 ukphy_status(sc); 221 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) 222 mii->mii_media_active = IFM_ETHER|IFM_HPNA_1; 223 224 /* Callback if something changed. */ 225 mii_phy_update(sc, cmd); 226 return (0); 227 } 228