2009-02-16 11:00:42 +03:00
|
|
|
/* $NetBSD: ukphy_subr.c,v 1.11 2009/02/16 08:00:42 cegger Exp $ */
|
1998-11-05 02:59:51 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Subroutines shared by the ukphy driver and other PHY drivers.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:38:28 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-02-16 11:00:42 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ukphy_subr.c,v 1.11 2009/02/16 08:00:42 cegger Exp $");
|
2001-11-13 10:38:28 +03:00
|
|
|
|
1998-11-05 02:59:51 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Media status subroutine. If a PHY driver does media detection simply
|
|
|
|
* by decoding the NWay autonegotiation, use this routine.
|
|
|
|
*/
|
|
|
|
void
|
2001-08-25 22:04:01 +04:00
|
|
|
ukphy_status(struct mii_softc *phy)
|
1998-11-05 02:59:51 +03:00
|
|
|
{
|
|
|
|
struct mii_data *mii = phy->mii_pdata;
|
1999-11-04 01:30:32 +03:00
|
|
|
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
2004-05-17 04:17:28 +04:00
|
|
|
int bmsr, bmcr, anlpar, gtcr, gtsr;
|
1998-11-05 02:59:51 +03: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);
|
2004-05-17 04:17:28 +04: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;
|
1998-11-05 02:59:51 +03:00
|
|
|
else if (anlpar & ANLPAR_TX_FD)
|
|
|
|
mii->mii_media_active |= IFM_100_TX|IFM_FDX;
|
2009-02-16 11:00:42 +03:00
|
|
|
else if (anlpar & ANLPAR_T4)
|
|
|
|
mii->mii_media_active |= IFM_100_T4;
|
1998-11-05 02:59:51 +03:00
|
|
|
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;
|
2004-05-17 03:55:58 +04:00
|
|
|
|
2004-05-17 04:17:28 +04:00
|
|
|
if ((mii->mii_media_active & IFM_1000_T) &&
|
|
|
|
(gtsr & GTSR_MS_RES))
|
|
|
|
mii->mii_media_active |= IFM_ETH_MASTER;
|
|
|
|
|
2004-05-17 03:55:58 +04:00
|
|
|
if (mii->mii_media_active & IFM_FDX)
|
|
|
|
mii->mii_media_active |= mii_phy_flowstatus(phy);
|
1998-11-05 07:08:01 +03:00
|
|
|
} else
|
1999-11-04 01:30:32 +03:00
|
|
|
mii->mii_media_active = ife->ifm_media;
|
1998-11-05 02:59:51 +03:00
|
|
|
}
|