1999-08-21 17:40:53 +00:00
|
|
|
/* $NetBSD: exphy.c,v 1.16 1999/04/23 04:24:32 thorpej Exp $ */
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 1999 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.
|
|
|
|
*/
|
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1999-08-21 17:40:53 +00:00
|
|
|
* Copyright (c) 1997 Manuel Bouyer. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Manuel Bouyer.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2004-05-29 18:09:10 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-08-21 17:40:53 +00:00
|
|
|
/*
|
|
|
|
* driver for 3Com internal PHYs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.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>
|
2003-01-19 02:59:34 +00:00
|
|
|
#include "miidevs.h"
|
1999-08-21 17:40:53 +00:00
|
|
|
|
|
|
|
#include "miibus_if.h"
|
|
|
|
|
2002-10-14 22:31:52 +00:00
|
|
|
static int exphy_probe(device_t);
|
|
|
|
static int exphy_attach(device_t);
|
1999-08-21 17:40:53 +00:00
|
|
|
|
|
|
|
static device_method_t exphy_methods[] = {
|
|
|
|
/* device interface */
|
|
|
|
DEVMETHOD(device_probe, exphy_probe),
|
|
|
|
DEVMETHOD(device_attach, exphy_attach),
|
2002-04-29 13:07:38 +00:00
|
|
|
DEVMETHOD(device_detach, mii_phy_detach),
|
1999-08-21 17:40:53 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t exphy_devclass;
|
|
|
|
|
|
|
|
static driver_t exphy_driver = {
|
|
|
|
"xlphy",
|
|
|
|
exphy_methods,
|
|
|
|
sizeof(struct mii_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(xlphy, miibus, exphy_driver, exphy_devclass, 0, 0);
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int exphy_service(struct mii_softc *, struct mii_data *, int);
|
|
|
|
static void exphy_reset(struct mii_softc *);
|
1999-08-21 17:40:53 +00:00
|
|
|
|
2007-01-12 23:17:43 +00:00
|
|
|
/*
|
|
|
|
* Some 3Com internal PHYs report zero for OUI and model, others use
|
|
|
|
* actual values.
|
|
|
|
* Note that the 3Com internal PHYs having OUI 0x105a and model 0 are
|
|
|
|
* handled fine by ukphy(4); they can be isolated and don't require
|
|
|
|
* special treatment after reset.
|
|
|
|
*/
|
|
|
|
static const struct mii_phydesc exphys[] = {
|
|
|
|
{ 0, 0, "3Com internal media interface" },
|
|
|
|
MII_PHY_DESC(BROADCOM, 3C905C),
|
|
|
|
MII_PHY_END
|
|
|
|
};
|
|
|
|
|
2002-10-14 22:31:52 +00:00
|
|
|
static int
|
2005-09-30 19:39:27 +00:00
|
|
|
exphy_probe(device_t dev)
|
1999-08-21 17:40:53 +00:00
|
|
|
{
|
|
|
|
|
2007-01-12 23:17:43 +00:00
|
|
|
if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
|
|
|
|
"xl") == 0)
|
|
|
|
return (mii_phy_dev_probe(dev, exphys, BUS_PROBE_DEFAULT));
|
|
|
|
return (ENXIO);
|
1999-08-21 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
2002-10-14 22:31:52 +00:00
|
|
|
static int
|
2005-09-30 19:39:27 +00:00
|
|
|
exphy_attach(device_t dev)
|
1999-08-21 17:40:53 +00:00
|
|
|
{
|
|
|
|
struct mii_softc *sc;
|
|
|
|
struct mii_attach_args *ma;
|
|
|
|
struct mii_data *mii;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
ma = device_get_ivars(dev);
|
|
|
|
sc->mii_dev = device_get_parent(dev);
|
|
|
|
mii = device_get_softc(sc->mii_dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 3Com PHY can never be isolated, so never allow non-zero
|
|
|
|
* instances!
|
|
|
|
*/
|
|
|
|
if (mii->mii_instance != 0) {
|
|
|
|
device_printf(dev, "ignoring this PHY, non-zero instance\n");
|
2007-01-12 23:17:43 +00:00
|
|
|
return (ENXIO);
|
1999-08-21 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
1999-09-01 17:07:27 +00:00
|
|
|
LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
|
|
|
|
|
|
|
|
sc->mii_inst = mii->mii_instance;
|
|
|
|
sc->mii_phy = ma->mii_phyno;
|
|
|
|
sc->mii_service = exphy_service;
|
|
|
|
sc->mii_pdata = mii;
|
1999-08-21 17:40:53 +00:00
|
|
|
mii->mii_instance++;
|
|
|
|
|
|
|
|
sc->mii_flags |= MIIF_NOISOLATE;
|
|
|
|
|
|
|
|
#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
|
|
|
|
|
|
|
|
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
|
2007-01-12 22:27:46 +00:00
|
|
|
MII_MEDIA_100_TX);
|
1999-08-21 17:40:53 +00:00
|
|
|
|
|
|
|
exphy_reset(sc);
|
|
|
|
|
|
|
|
sc->mii_capabilities =
|
|
|
|
PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
|
|
|
|
device_printf(dev, " ");
|
2002-04-29 13:35:31 +00:00
|
|
|
mii_phy_add_media(sc);
|
1999-08-21 17:40:53 +00:00
|
|
|
printf("\n");
|
|
|
|
#undef ADD
|
|
|
|
MIIBUS_MEDIAINIT(sc->mii_dev);
|
2007-01-12 23:17:43 +00:00
|
|
|
return (0);
|
1999-08-21 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
2001-09-29 19:18:52 +00:00
|
|
|
static int
|
2005-09-30 19:39:27 +00:00
|
|
|
exphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
|
1999-08-21 17:40:53 +00:00
|
|
|
{
|
|
|
|
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't isolate the 3Com PHY, so it has to be the only one!
|
|
|
|
*/
|
|
|
|
if (IFM_INST(ife->ifm_media) != sc->mii_inst)
|
|
|
|
panic("exphy_service: can't isolate 3Com PHY");
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MII_POLLSTAT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MII_MEDIACHG:
|
|
|
|
/*
|
|
|
|
* If the interface is not up, don't do anything.
|
|
|
|
*/
|
|
|
|
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
|
|
|
|
break;
|
|
|
|
|
2002-04-29 13:35:31 +00:00
|
|
|
mii_phy_setmedia(sc);
|
1999-08-21 17:40:53 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MII_TICK:
|
|
|
|
/*
|
2001-09-29 19:18:52 +00:00
|
|
|
* Is the interface even up?
|
1999-08-21 17:40:53 +00:00
|
|
|
*/
|
2001-09-29 19:18:52 +00:00
|
|
|
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
|
1999-08-21 17:40:53 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 3Com PHY's autonegotiation doesn't need to be
|
|
|
|
* kicked; it continues in the background.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the media status. */
|
|
|
|
ukphy_status(sc);
|
|
|
|
|
|
|
|
/* Callback if something changed. */
|
2001-09-29 19:18:52 +00:00
|
|
|
mii_phy_update(sc, cmd);
|
1999-08-21 17:40:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-09-29 19:18:52 +00:00
|
|
|
static void
|
2002-04-29 13:35:31 +00:00
|
|
|
exphy_reset(struct mii_softc *sc)
|
1999-08-21 17:40:53 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
mii_phy_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX 3Com PHY doesn't set the BMCR properly after
|
|
|
|
* XXX reset, which breaks autonegotiation.
|
|
|
|
*/
|
|
|
|
PHY_WRITE(sc, MII_BMCR, BMCR_S100|BMCR_AUTOEN|BMCR_FDX);
|
|
|
|
}
|