278d761d73
support in mii(4): - Merge generic flow control advertisement (which can be enabled by passing by MIIF_DOPAUSE to mii_attach(9)) and parsing support from NetBSD into mii_physubr.c and ukphy_subr.c. Unlike as in NetBSD, IFM_FLOW isn't implemented as a global option via the "don't care mask" but instead as a media specific option this. This has the following advantages: o allows flow control advertisement with autonegotiation to be turned on and off via ifconfig(8) with the default typically being off (though MIIF_FORCEPAUSE has been added causing flow control to be always advertised, allowing to easily MFC this changes for drivers that previously used home-grown support for flow control that behaved that way without breaking POLA) o allows to deal with PHY drivers where flow control advertisement with manual selection doesn't work or at least isn't implemented, like it's the case with brgphy(4), e1000phy(4) and ip1000phy(4), by setting MIIF_NOMANPAUSE o the available combinations of media options are readily available from the `ifconfig -m` output - Add IFM_FLOW to IFM_SHARED_OPTION_DESCRIPTIONS and IFM_ETH_RXPAUSE and IFM_ETH_TXPAUSE to IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS so these are understood by ifconfig(8). o Make the master/slave support in mii(4) actually usable: - Change IFM_ETH_MASTER from being implemented as a global option via the "don't care mask" to a media specific one as it actually is only applicable to IFM_1000_T to date. - Let mii_phy_setmedia() set GTCR_MAN_MS in IFM_1000_T slave mode to actually configure manually selected slave mode (like we also do in the PHY specific implementations). - Add IFM_ETH_MASTER to IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS so it is understood by ifconfig(8). o Switch bge(4), bce(4), msk(4), nfe(4) and stge(4) along with brgphy(4), e1000phy(4) and ip1000phy(4) to use the generic flow control support instead of home-grown solutions via IFM_FLAGs. This includes changing these PHY drivers and smcphy(4) to no longer unconditionally advertise support for flow control but only if the selected media has IFM_FLOW set (or MIIF_FORCEPAUSE is set) and implemented for these media variants, i.e. typically only for copper. o Switch brgphy(4), ciphy(4), e1000phy(4) and ip1000phy(4) to report and set IFM_1000_T master mode via IFM_ETH_MASTER instead of via IFF_LINK0 and some IFM_FLAGn. o Switch brgphy(4) to add at least the the supported copper media based on the contents of the BMSR via mii_phy_add_media() instead of hardcoding them. The latter approach seems to have developed historically, besides causing unnecessary code duplication it was also undesirable because brgphy_mii_phy_auto() already based the capability advertisement on the contents of the BMSR though. o Let brgphy(4) set IFM_1000_T master mode on all supported PHY and not just BCM5701. Apparently this was a misinterpretation of a workaround in the Linux tg3 driver; BCM5701 seem to require RGPHY_1000CTL_MSE and BRGPHY_1000CTL_MSC to be set when configuring autonegotiation but this doesn't mean we can't set these as well on other PHYs for manual media selection. o Let ukphy_status() report IFM_1000_T master mode via IFM_ETH_MASTER so IFM_1000_T master mode support now is generally available with all PHY drivers. o Don't let e1000phy(4) set master/slave bits for IFM_1000_SX as it's not applicable there. Reviewed by: yongari (plus additional testing) Obtained from: NetBSD (partially), OpenBSD (partially) MFC after: 2 weeks
130 lines
4.2 KiB
C
130 lines
4.2 KiB
C
/* $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.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
/*
|
|
* 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
|
|
ukphy_status(struct mii_softc *phy)
|
|
{
|
|
struct mii_data *mii = phy->mii_pdata;
|
|
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
|
int bmsr, bmcr, anlpar, gtcr, gtsr;
|
|
|
|
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);
|
|
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|IFM_HDX;
|
|
else if (anlpar & ANLPAR_TX_FD)
|
|
mii->mii_media_active |= IFM_100_TX|IFM_FDX;
|
|
else if (anlpar & ANLPAR_T4)
|
|
mii->mii_media_active |= IFM_100_T4|IFM_HDX;
|
|
else if (anlpar & ANLPAR_TX)
|
|
mii->mii_media_active |= IFM_100_TX|IFM_HDX;
|
|
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|IFM_HDX;
|
|
else
|
|
mii->mii_media_active |= IFM_NONE;
|
|
|
|
if ((mii->mii_media_active & IFM_1000_T) != 0 &&
|
|
(gtsr & GTSR_MS_RES) != 0)
|
|
mii->mii_media_active |= IFM_ETH_MASTER;
|
|
|
|
if ((mii->mii_media_active & IFM_FDX) != 0)
|
|
mii->mii_media_active |= mii_phy_flowstatus(phy);
|
|
} else
|
|
mii->mii_media_active = ife->ifm_media;
|
|
}
|