ukphy_subr.c revision 119418
133965Sjdp/* $NetBSD: ukphy_subr.c,v 1.2 1998/11/05 04:08:02 thorpej Exp $ */ 2218822Sdim 3218822Sdim/*- 433965Sjdp * Copyright (c) 1998 The NetBSD Foundation, Inc. 533965Sjdp * All rights reserved. 6130561Sobrien * 733965Sjdp * This code is derived from software contributed to The NetBSD Foundation 8130561Sobrien * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9130561Sobrien * NASA Ames Research Center, and by Frank van der Linden. 10130561Sobrien * 11130561Sobrien * Redistribution and use in source and binary forms, with or without 1233965Sjdp * modification, are permitted provided that the following conditions 13130561Sobrien * are met: 14130561Sobrien * 1. Redistributions of source code must retain the above copyright 15130561Sobrien * notice, this list of conditions and the following disclaimer. 16130561Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1733965Sjdp * notice, this list of conditions and the following disclaimer in the 18130561Sobrien * documentation and/or other materials provided with the distribution. 19130561Sobrien * 3. All advertising materials mentioning features or use of this software 20218822Sdim * must display the following acknowledgement: 2133965Sjdp * This product includes software developed by the NetBSD 2233965Sjdp * Foundation, Inc. and its contributors. 2333965Sjdp * 4. Neither the name of The NetBSD Foundation nor the names of its 2433965Sjdp * contributors may be used to endorse or promote products derived 2533965Sjdp * from this software without specific prior written permission. 2633965Sjdp * 2777298Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2833965Sjdp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2933965Sjdp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3033965Sjdp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3133965Sjdp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3233965Sjdp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3333965Sjdp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3433965Sjdp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3533965Sjdp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3633965Sjdp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3733965Sjdp * POSSIBILITY OF SUCH DAMAGE. 3833965Sjdp */ 3933965Sjdp 4033965Sjdp#include <sys/cdefs.h> 41218822Sdim__FBSDID("$FreeBSD: head/sys/dev/mii/ukphy_subr.c 119418 2003-08-24 17:55:58Z obrien $"); 42218822Sdim 4333965Sjdp/* 4433965Sjdp * Subroutines shared by the ukphy driver and other PHY drivers. 45218822Sdim */ 4633965Sjdp 4733965Sjdp#include <sys/cdefs.h> 4833965Sjdp__FBSDID("$FreeBSD: head/sys/dev/mii/ukphy_subr.c 119418 2003-08-24 17:55:58Z obrien $"); 4933965Sjdp 5033965Sjdp#include <sys/param.h> 5133965Sjdp#include <sys/systm.h> 5233965Sjdp#include <sys/socket.h> 5333965Sjdp#include <sys/module.h> 5433965Sjdp#include <sys/bus.h> 5533965Sjdp 5633965Sjdp#include <net/if.h> 57130561Sobrien#include <net/if_media.h> 5833965Sjdp 5933965Sjdp#include <dev/mii/mii.h> 6033965Sjdp#include <dev/mii/miivar.h> 6133965Sjdp 6233965Sjdp#include "miibus_if.h" 6333965Sjdp 6433965Sjdp/* 6533965Sjdp * Media status subroutine. If a PHY driver does media detection simply 6633965Sjdp * by decoding the NWay autonegotiation, use this routine. 6733965Sjdp */ 6833965Sjdpvoid 6933965Sjdpukphy_status(struct mii_softc *phy) 7033965Sjdp{ 7133965Sjdp struct mii_data *mii = phy->mii_pdata; 72130561Sobrien struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 7377298Sobrien int bmsr, bmcr, anlpar; 7433965Sjdp 7533965Sjdp mii->mii_media_status = IFM_AVALID; 7633965Sjdp mii->mii_media_active = IFM_ETHER; 7733965Sjdp 7833965Sjdp bmsr = PHY_READ(phy, MII_BMSR) | PHY_READ(phy, MII_BMSR); 7933965Sjdp if (bmsr & BMSR_LINK) 8033965Sjdp mii->mii_media_status |= IFM_ACTIVE; 8133965Sjdp 8233965Sjdp bmcr = PHY_READ(phy, MII_BMCR); 8333965Sjdp if (bmcr & BMCR_ISO) { 8433965Sjdp mii->mii_media_active |= IFM_NONE; 8533965Sjdp mii->mii_media_status = 0; 8633965Sjdp return; 8733965Sjdp } 8833965Sjdp 8933965Sjdp if (bmcr & BMCR_LOOP) 90130561Sobrien mii->mii_media_active |= IFM_LOOP; 91130561Sobrien 9233965Sjdp if (bmcr & BMCR_AUTOEN) { 9333965Sjdp /* 9433965Sjdp * NWay autonegotiation takes the highest-order common 9533965Sjdp * bit of the ANAR and ANLPAR (i.e. best media advertised 9633965Sjdp * both by us and our link partner). 9733965Sjdp */ 9833965Sjdp if ((bmsr & BMSR_ACOMP) == 0) { 9933965Sjdp /* Erg, still trying, I guess... */ 10033965Sjdp mii->mii_media_active |= IFM_NONE; 101130561Sobrien return; 102130561Sobrien } 10333965Sjdp 10433965Sjdp anlpar = PHY_READ(phy, MII_ANAR) & PHY_READ(phy, MII_ANLPAR); 105130561Sobrien if (anlpar & ANLPAR_T4) 10633965Sjdp mii->mii_media_active |= IFM_100_T4; 10733965Sjdp else if (anlpar & ANLPAR_TX_FD) 10833965Sjdp mii->mii_media_active |= IFM_100_TX|IFM_FDX; 10933965Sjdp else if (anlpar & ANLPAR_TX) 11033965Sjdp mii->mii_media_active |= IFM_100_TX; 11133965Sjdp else if (anlpar & ANLPAR_10_FD) 11233965Sjdp mii->mii_media_active |= IFM_10_T|IFM_FDX; 11377298Sobrien else if (anlpar & ANLPAR_10) 11433965Sjdp mii->mii_media_active |= IFM_10_T; 11533965Sjdp else 116130561Sobrien mii->mii_media_active |= IFM_NONE; 117130561Sobrien } else 11833965Sjdp mii->mii_media_active = ife->ifm_media; 11960484Sobrien} 120130561Sobrien