1999-08-21 17:40:53 +00:00
|
|
|
/* $NetBSD: ukphy_subr.c,v 1.2 1998/11/05 04:08:02 thorpej Exp $ */
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center, and by Frank van der Linden.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-08-21 17:40:53 +00:00
|
|
|
/*
|
|
|
|
* Subroutines shared by the ukphy driver and other PHY drivers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
#include "miibus_if.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Media status subroutine. If a PHY driver does media detection simply
|
|
|
|
* by decoding the NWay autonegotiation, use this routine.
|
|
|
|
*/
|
|
|
|
void
|
2002-04-29 13:35:31 +00:00
|
|
|
ukphy_status(struct mii_softc *phy)
|
1999-08-21 17:40:53 +00:00
|
|
|
{
|
|
|
|
struct mii_data *mii = phy->mii_pdata;
|
2002-04-29 13:35:31 +00:00
|
|
|
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
2006-05-19 03:51:42 +00:00
|
|
|
int bmsr, bmcr, anlpar, gtcr, gtsr;
|
1999-08-21 17:40:53 +00:00
|
|
|
|
|
|
|
mii->mii_media_status = IFM_AVALID;
|
|
|
|
mii->mii_media_active = IFM_ETHER;
|
|
|
|
|
|
|
|
bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR);
|
|
|
|
if (bmsr & BMSR_LINK)
|
|
|
|
mii->mii_media_status |= IFM_ACTIVE;
|
|
|
|
|
|
|
|
bmcr = PHY_READ(phy, MII_BMCR);
|
|
|
|
if (bmcr & BMCR_ISO) {
|
|
|
|
mii->mii_media_active |= IFM_NONE;
|
|
|
|
mii->mii_media_status = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bmcr & BMCR_LOOP)
|
|
|
|
mii->mii_media_active |= IFM_LOOP;
|
|
|
|
|
|
|
|
if (bmcr & BMCR_AUTOEN) {
|
|
|
|
/*
|
|
|
|
* NWay autonegotiation takes the highest-order common
|
|
|
|
* bit of the ANAR and ANLPAR (i.e. best media advertised
|
|
|
|
* both by us and our link partner).
|
|
|
|
*/
|
|
|
|
if ((bmsr & BMSR_ACOMP) == 0) {
|
|
|
|
/* Erg, still trying, I guess... */
|
|
|
|
mii->mii_media_active |= IFM_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
anlpar = PHY_READ(phy, MII_ANAR) & PHY_READ(phy, MII_ANLPAR);
|
2006-05-19 03:51:42 +00:00
|
|
|
if ((phy->mii_flags & MIIF_HAVE_GTCR) != 0 &&
|
|
|
|
(phy->mii_extcapabilities &
|
|
|
|
(EXTSR_1000THDX | EXTSR_1000TFDX)) != 0) {
|
|
|
|
gtcr = PHY_READ(phy, MII_100T2CR);
|
|
|
|
gtsr = PHY_READ(phy, MII_100T2SR);
|
|
|
|
} else
|
|
|
|
gtcr = gtsr = 0;
|
|
|
|
|
|
|
|
if ((gtcr & GTCR_ADV_1000TFDX) && (gtsr & GTSR_LP_1000TFDX))
|
|
|
|
mii->mii_media_active |= IFM_1000_T|IFM_FDX;
|
|
|
|
else if ((gtcr & GTCR_ADV_1000THDX) &&
|
|
|
|
(gtsr & GTSR_LP_1000THDX))
|
|
|
|
mii->mii_media_active |= IFM_1000_T;
|
|
|
|
else if (anlpar & ANLPAR_T4)
|
1999-08-21 17:40:53 +00:00
|
|
|
mii->mii_media_active |= IFM_100_T4;
|
|
|
|
else if (anlpar & ANLPAR_TX_FD)
|
|
|
|
mii->mii_media_active |= IFM_100_TX|IFM_FDX;
|
|
|
|
else if (anlpar & ANLPAR_TX)
|
|
|
|
mii->mii_media_active |= IFM_100_TX;
|
|
|
|
else if (anlpar & ANLPAR_10_FD)
|
|
|
|
mii->mii_media_active |= IFM_10_T|IFM_FDX;
|
|
|
|
else if (anlpar & ANLPAR_10)
|
|
|
|
mii->mii_media_active |= IFM_10_T;
|
|
|
|
else
|
|
|
|
mii->mii_media_active |= IFM_NONE;
|
|
|
|
} else
|
2002-04-29 13:35:31 +00:00
|
|
|
mii->mii_media_active = ife->ifm_media;
|
1999-08-21 17:40:53 +00:00
|
|
|
}
|