smcphy.c (227908) | smcphy.c (232015) |
---|---|
1/*- 2 * Copyright (c) 2006 Benno Rice. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Benno Rice. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> |
26__FBSDID("$FreeBSD: head/sys/dev/mii/smcphy.c 227908 2011-11-23 20:27:26Z marius $"); | 26__FBSDID("$FreeBSD: head/sys/dev/mii/smcphy.c 232015 2012-02-23 01:20:21Z yongari $"); |
27 28/* 29 * Driver for the internal PHY on the SMSC LAN91C111. 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> --- 15 unchanged lines hidden (view full) --- 50#include "miibus_if.h" 51 52static int smcphy_probe(device_t); 53static int smcphy_attach(device_t); 54 55static int smcphy_service(struct mii_softc *, struct mii_data *, int); 56static void smcphy_reset(struct mii_softc *); 57static void smcphy_auto(struct mii_softc *, int); | 27 28/* 29 * Driver for the internal PHY on the SMSC LAN91C111. 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> --- 15 unchanged lines hidden (view full) --- 50#include "miibus_if.h" 51 52static int smcphy_probe(device_t); 53static int smcphy_attach(device_t); 54 55static int smcphy_service(struct mii_softc *, struct mii_data *, int); 56static void smcphy_reset(struct mii_softc *); 57static void smcphy_auto(struct mii_softc *, int); |
58static void smcphy_status(struct mii_softc *); |
|
58 59static device_method_t smcphy_methods[] = { 60 /* device interface */ 61 DEVMETHOD(device_probe, smcphy_probe), 62 DEVMETHOD(device_attach, smcphy_attach), 63 DEVMETHOD(device_detach, mii_phy_detach), 64 DEVMETHOD(device_shutdown, bus_generic_shutdown), 65 DEVMETHOD_END --- 5 unchanged lines hidden (view full) --- 71 "smcphy", 72 smcphy_methods, 73 sizeof(struct mii_softc) 74}; 75 76DRIVER_MODULE(smcphy, miibus, smcphy_driver, smcphy_devclass, 0, 0); 77 78static const struct mii_phydesc smcphys[] = { | 59 60static device_method_t smcphy_methods[] = { 61 /* device interface */ 62 DEVMETHOD(device_probe, smcphy_probe), 63 DEVMETHOD(device_attach, smcphy_attach), 64 DEVMETHOD(device_detach, mii_phy_detach), 65 DEVMETHOD(device_shutdown, bus_generic_shutdown), 66 DEVMETHOD_END --- 5 unchanged lines hidden (view full) --- 72 "smcphy", 73 smcphy_methods, 74 sizeof(struct mii_softc) 75}; 76 77DRIVER_MODULE(smcphy, miibus, smcphy_driver, smcphy_devclass, 0, 0); 78 79static const struct mii_phydesc smcphys[] = { |
80 MII_PHY_DESC(SEEQ, 80220), |
|
79 MII_PHY_DESC(SEEQ, 84220), 80 MII_PHY_END 81}; 82 | 81 MII_PHY_DESC(SEEQ, 84220), 82 MII_PHY_END 83}; 84 |
85static const struct mii_phy_funcs smcphy80220_funcs = { 86 smcphy_service, 87 smcphy_status, 88 mii_phy_reset 89}; 90 |
|
83static const struct mii_phy_funcs smcphy_funcs = { 84 smcphy_service, | 91static const struct mii_phy_funcs smcphy_funcs = { 92 smcphy_service, |
85 ukphy_status, | 93 smcphy_status, |
86 smcphy_reset 87}; 88 89static int 90smcphy_probe(device_t dev) 91{ 92 93 return (mii_phy_dev_probe(dev, smcphys, BUS_PROBE_DEFAULT)); 94} 95 96static int 97smcphy_attach(device_t dev) 98{ 99 struct mii_softc *sc; | 94 smcphy_reset 95}; 96 97static int 98smcphy_probe(device_t dev) 99{ 100 101 return (mii_phy_dev_probe(dev, smcphys, BUS_PROBE_DEFAULT)); 102} 103 104static int 105smcphy_attach(device_t dev) 106{ 107 struct mii_softc *sc; |
108 struct mii_attach_args *ma; 109 const struct mii_phy_funcs *mpf; |
|
100 101 sc = device_get_softc(dev); | 110 111 sc = device_get_softc(dev); |
102 103 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE, 104 &smcphy_funcs, 1); | 112 ma = device_get_ivars(dev); 113 if (MII_MODEL(ma->mii_id2) == MII_MODEL_SEEQ_80220) 114 mpf = &smcphy80220_funcs; 115 else 116 mpf = &smcphy_funcs; 117 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE, mpf, 1); |
105 mii_phy_setmedia(sc); 106 107 return (0); 108} 109 110static int 111smcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 112{ --- 96 unchanged lines hidden (view full) --- 209 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA; 210 if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) 211 anar |= ANAR_FC; 212 PHY_WRITE(sc, MII_ANAR, anar); 213 /* Apparently this helps. */ 214 anar = PHY_READ(sc, MII_ANAR); 215 PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); 216} | 118 mii_phy_setmedia(sc); 119 120 return (0); 121} 122 123static int 124smcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 125{ --- 96 unchanged lines hidden (view full) --- 222 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA; 223 if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) 224 anar |= ANAR_FC; 225 PHY_WRITE(sc, MII_ANAR, anar); 226 /* Apparently this helps. */ 227 anar = PHY_READ(sc, MII_ANAR); 228 PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); 229} |
230 231static void 232smcphy_status(struct mii_softc *sc) 233{ 234 struct mii_data *mii; 235 uint32_t bmcr, bmsr, status; 236 237 mii = sc->mii_pdata; 238 mii->mii_media_status = IFM_AVALID; 239 mii->mii_media_active = IFM_ETHER; 240 241 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); 242 if ((bmsr & BMSR_LINK) != 0) 243 mii->mii_media_status |= IFM_ACTIVE; 244 245 bmcr = PHY_READ(sc, MII_BMCR); 246 if ((bmcr & BMCR_ISO) != 0) { 247 mii->mii_media_active |= IFM_NONE; 248 mii->mii_media_status = 0; 249 return; 250 } 251 252 if ((bmcr & BMCR_LOOP) != 0) 253 mii->mii_media_active |= IFM_LOOP; 254 255 if ((bmcr & BMCR_AUTOEN) != 0) { 256 if ((bmsr & BMSR_ACOMP) == 0) { 257 /* Erg, still trying, I guess... */ 258 mii->mii_media_active |= IFM_NONE; 259 return; 260 } 261 } 262 263 status = PHY_READ(sc, 0x12); 264 if (status & 0x0080) 265 mii->mii_media_active |= IFM_100_TX; 266 else 267 mii->mii_media_active |= IFM_10_T; 268 if (status & 0x0040) 269 mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc); 270 else 271 mii->mii_media_active |= IFM_HDX; 272} |
|