Driver for the 10BASE-T portion of the AMD 79c901 PHY.
This commit is contained in:
parent
222d7da881
commit
85a7cdc261
|
@ -0,0 +1,242 @@
|
|||
/* $NetBSD: amhphy.c,v 1.1 2001/08/25 04:06:26 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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 for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Driver for the 10BASE-T portion of the AMD Am79c901 PHY.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_media.h>
|
||||
|
||||
#include <dev/mii/mii.h>
|
||||
#include <dev/mii/miivar.h>
|
||||
#include <dev/mii/miidevs.h>
|
||||
|
||||
#include <dev/mii/amhphyreg.h>
|
||||
|
||||
int amhphymatch(struct device *, struct cfdata *, void *);
|
||||
void amhphyattach(struct device *, struct device *, void *);
|
||||
|
||||
struct cfattach amhphy_ca = {
|
||||
sizeof(struct mii_softc), amhphymatch, amhphyattach,
|
||||
mii_phy_detach, mii_phy_activate
|
||||
};
|
||||
|
||||
int amhphy_service(struct mii_softc *, struct mii_data *, int);
|
||||
void amhphy_status(struct mii_softc *);
|
||||
|
||||
const struct mii_phy_funcs amhphy_funcs = {
|
||||
amhphy_service, amhphy_status, mii_phy_reset,
|
||||
};
|
||||
|
||||
const struct mii_phydesc amhphys[] = {
|
||||
{ MII_OUI_yyAMD, MII_MODEL_yyAMD_79c901,
|
||||
MII_STR_yyAMD_79c901 },
|
||||
|
||||
{ 0, 0,
|
||||
NULL },
|
||||
};
|
||||
|
||||
int
|
||||
amhphymatch(parent, match, aux)
|
||||
struct device *parent;
|
||||
struct cfdata *match;
|
||||
void *aux;
|
||||
{
|
||||
struct mii_attach_args *ma = aux;
|
||||
|
||||
if (mii_phy_match(ma, amhphys) != NULL)
|
||||
return (10);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
amhphyattach(parent, self, aux)
|
||||
struct device *parent, *self;
|
||||
void *aux;
|
||||
{
|
||||
struct mii_softc *sc = (struct mii_softc *)self;
|
||||
struct mii_attach_args *ma = aux;
|
||||
struct mii_data *mii = ma->mii_data;
|
||||
const struct mii_phydesc *mpd;
|
||||
|
||||
mpd = mii_phy_match(ma, amhphys);
|
||||
printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
|
||||
|
||||
sc->mii_inst = mii->mii_instance;
|
||||
sc->mii_phy = ma->mii_phyno;
|
||||
sc->mii_funcs = &amhphy_funcs;
|
||||
sc->mii_pdata = mii;
|
||||
sc->mii_flags = mii->mii_flags;
|
||||
sc->mii_anegticks = 5;
|
||||
|
||||
PHY_RESET(sc);
|
||||
|
||||
sc->mii_capabilities =
|
||||
PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
|
||||
printf("%s: ", sc->mii_dev.dv_xname);
|
||||
if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0)
|
||||
printf("no media present");
|
||||
else
|
||||
mii_phy_add_media(sc);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int
|
||||
amhphy_service(sc, mii, cmd)
|
||||
struct mii_softc *sc;
|
||||
struct mii_data *mii;
|
||||
int cmd;
|
||||
{
|
||||
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
||||
int reg;
|
||||
|
||||
switch (cmd) {
|
||||
case MII_POLLSTAT:
|
||||
/*
|
||||
* If we're not polling our PHY instance, just return.
|
||||
*/
|
||||
if (IFM_INST(ife->ifm_media) != sc->mii_inst)
|
||||
return (0);
|
||||
break;
|
||||
|
||||
case MII_MEDIACHG:
|
||||
/*
|
||||
* If the media indicates a different PHY instance,
|
||||
* isolate ourselves.
|
||||
*/
|
||||
if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
|
||||
reg = PHY_READ(sc, MII_BMCR);
|
||||
PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the interface is not up, don't do anything.
|
||||
*/
|
||||
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
|
||||
break;
|
||||
|
||||
mii_phy_setmedia(sc);
|
||||
break;
|
||||
|
||||
case MII_TICK:
|
||||
/*
|
||||
* If we're not currently selected, just return.
|
||||
*/
|
||||
if (IFM_INST(ife->ifm_media) != sc->mii_inst)
|
||||
return (0);
|
||||
|
||||
if (mii_phy_tick(sc) == EJUSTRETURN)
|
||||
return (0);
|
||||
break;
|
||||
|
||||
case MII_DOWN:
|
||||
mii_phy_down(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Update the media status. */
|
||||
mii_phy_status(sc);
|
||||
|
||||
/* Callback if something changed. */
|
||||
mii_phy_update(sc, cmd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
amhphy_status(sc)
|
||||
struct mii_softc *sc;
|
||||
{
|
||||
struct mii_data *mii = sc->mii_pdata;
|
||||
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
||||
int bmsr, bmcr, ssr;
|
||||
|
||||
mii->mii_media_status = IFM_AVALID;
|
||||
mii->mii_media_active = IFM_ETHER;
|
||||
|
||||
bmsr = PHY_READ(sc, MII_BMSR);
|
||||
ssr = PHY_READ(sc, MII_AMHPHY_SSR);
|
||||
|
||||
if (ssr & SSR_LS)
|
||||
mii->mii_media_status |= IFM_ACTIVE;
|
||||
|
||||
bmcr = PHY_READ(sc, 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) {
|
||||
/*
|
||||
* The media status bits are only valid of autonegotiation
|
||||
* has completed (or it's disabled).
|
||||
*/
|
||||
if ((bmsr & BMSR_ACOMP) == 0) {
|
||||
/* Erg, still trying, I guess... */
|
||||
mii->mii_media_active |= IFM_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ssr & SSR_S) {
|
||||
/*
|
||||
* This should't really ever happen, since it's
|
||||
* a 10BASE-T only PHY. But the bit exists,
|
||||
* according to the documentation, so we pay
|
||||
* attention to it.
|
||||
*/
|
||||
mii->mii_media_active |= IFM_100_TX;
|
||||
} else
|
||||
mii->mii_media_active |= IFM_10_T;
|
||||
if (ssr & SSR_FD)
|
||||
mii->mii_media_active |= IFM_FDX;
|
||||
} else
|
||||
mii->mii_media_active = ife->ifm_media;
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/* $NetBSD: amhphyreg.h,v 1.1 2001/08/25 04:06:26 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
*
|
||||
* 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 for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _DEV_MII_AMHPHYREG_H_
|
||||
#define _DEV_MII_AMHPHYREG_H_
|
||||
|
||||
/*
|
||||
* Registers on the 10BASE-T portion of the Am79c901 PHY.
|
||||
*/
|
||||
|
||||
#define MII_AMHPHY_SER 0x10 /* status and enable register */
|
||||
#define SER_STE 0x2000 /* status test enable */
|
||||
#define SER_LSCE 0x1000 /* link status change enable */
|
||||
#define SER_DMCE 0x0800 /* duplex mode change enable */
|
||||
#define SER_ANCE 0x0400 /* auto-negotiation change enable */
|
||||
#define SER_SCE 0x0200 /* speed change enable */
|
||||
#define SER_GE 0x0100 /* global enable */
|
||||
#define SER_LSC 0x0010 /* link status change */
|
||||
#define SER_DMC 0x0008 /* duplex mode chane */
|
||||
#define SER_ANC 0x0004 /* auto-negotiation change */
|
||||
#define SER_SC 0x0002 /* speed change */
|
||||
#define SER_G 0x0001 /* global event pending */
|
||||
|
||||
|
||||
#define MII_AMHPHY_PCSR 0x11 /* PHY control/status register */
|
||||
#define PCSR_FLGE 0x2000 /* force link good enable */
|
||||
#define PCSR_DLP 0x1000 /* disable link pulse */
|
||||
#define PCSR_SQE_DIS 0x0800 /* SQE test disable */
|
||||
#define PCSR_JDD 0x0200 /* jabber detect disable */
|
||||
#define PCSR_RPR 0x0040 /* receive polarity reversed */
|
||||
#define PCSR_ARPCD 0x0020 /* auto receive polarity corr dis */
|
||||
#define PCSR_EDE 0x0010 /* extended distance enable */
|
||||
#define PCSR_TX_DISABLE 0x0008 /* Tx disable */
|
||||
#define PCSR_TX_CRS_EN 0x0004 /* CRS enable */
|
||||
#define PCSR_PHY_ISOLATED 0x0001 /* 10BASE-T PHY is isolated */
|
||||
|
||||
|
||||
#define MII_AMHPHY_MER 0x13 /* management extension register */
|
||||
#define MER_MFF 0x0020 /* management frame format error */
|
||||
#define MER_PHYADDR 0x001f /* PHY address */
|
||||
|
||||
|
||||
#define MII_AMHPHY_SSR 0x18 /* summary status register */
|
||||
#define SSR_LS 0x0008 /* link status */
|
||||
#define SSR_FD 0x0004 /* full-duplex */
|
||||
#define SSR_ANA 0x0002 /* autonegotiation alert */
|
||||
#define SSR_S 0x0001 /* speed (1 = 100Mb/s) */
|
||||
|
||||
|
||||
#endif /* _DEV_MII_AMHPHYREG_H_ */
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: files.mii,v 1.27 2001/08/25 03:21:38 thorpej Exp $
|
||||
# $NetBSD: files.mii,v 1.28 2001/08/25 04:06:26 thorpej Exp $
|
||||
|
||||
file dev/mii/mii.c mii
|
||||
|
||||
|
@ -14,6 +14,10 @@ device acphy: mii_phy
|
|||
attach acphy at mii
|
||||
file dev/mii/acphy.c acphy
|
||||
|
||||
device amhphy: mii_phy
|
||||
attach amhphy at mii
|
||||
file dev/mii/amhphy.c amhphy
|
||||
|
||||
device bmtphy: mii_phy
|
||||
attach bmtphy at mii
|
||||
file dev/mii/bmtphy.c bmtphy
|
||||
|
|
Loading…
Reference in New Issue