2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: dl10019.c,v 1.11 2008/04/28 20:23:49 martin Exp $ */
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.11 2008/04/28 20:23:49 martin Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2001-02-13 04:43:02 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/mii_bitbang.h>
|
|
|
|
|
|
|
|
#include <dev/ic/dp8390reg.h>
|
|
|
|
#include <dev/ic/dp8390var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/ne2000reg.h>
|
|
|
|
#include <dev/ic/ne2000var.h>
|
|
|
|
|
|
|
|
#include <dev/ic/dl10019reg.h>
|
|
|
|
#include <dev/ic/dl10019var.h>
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
int dl10019_mii_readreg(device_t, int, int);
|
|
|
|
void dl10019_mii_writereg(device_t, int, int, int);
|
|
|
|
void dl10019_mii_statchg(device_t);
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MII bit-bang glue.
|
|
|
|
*/
|
2008-03-12 17:31:11 +03:00
|
|
|
u_int32_t dl10019_mii_bitbang_read(device_t);
|
|
|
|
void dl10019_mii_bitbang_write(device_t, u_int32_t);
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
const struct mii_bitbang_ops dl10019_mii_bitbang_ops = {
|
|
|
|
dl10019_mii_bitbang_read,
|
|
|
|
dl10019_mii_bitbang_write,
|
|
|
|
{
|
|
|
|
DL0_GPIO_MII_DATAOUT, /* MII_BIT_MDO */
|
|
|
|
DL0_GPIO_MII_DATAIN, /* MII_BIT_MDI */
|
|
|
|
DL0_GPIO_MII_CLK, /* MII_BIT_MDC */
|
|
|
|
DL0_19_GPIO_MII_DIROUT, /* MII_BIT_DIR_HOST_PHY */
|
|
|
|
0, /* MII_BIT_DIR_PHY_HOST */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct mii_bitbang_ops dl10022_mii_bitbang_ops = {
|
|
|
|
dl10019_mii_bitbang_read,
|
|
|
|
dl10019_mii_bitbang_write,
|
|
|
|
{
|
|
|
|
DL0_GPIO_MII_DATAOUT, /* MII_BIT_MDO */
|
|
|
|
DL0_GPIO_MII_DATAIN, /* MII_BIT_MDI */
|
|
|
|
DL0_GPIO_MII_CLK, /* MII_BIT_MDC */
|
|
|
|
DL0_22_GPIO_MII_DIROUT, /* MII_BIT_DIR_HOST_PHY */
|
|
|
|
0, /* MII_BIT_DIR_PHY_HOST */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
dl10019_mii_reset(struct dp8390_softc *sc)
|
|
|
|
{
|
|
|
|
struct ne2000_softc *nsc = (void *) sc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (nsc->sc_type != NE2000_TYPE_DL10022)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
|
|
|
|
0x08);
|
2001-06-03 08:39:52 +04:00
|
|
|
delay(1);
|
2001-02-13 04:43:02 +03:00
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
|
|
|
|
0x0c);
|
2001-06-03 08:39:52 +04:00
|
|
|
delay(1);
|
2001-02-13 04:43:02 +03:00
|
|
|
}
|
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dl10019_media_init(struct dp8390_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ec.ec_if;
|
|
|
|
|
|
|
|
sc->sc_mii.mii_ifp = ifp;
|
|
|
|
sc->sc_mii.mii_readreg = dl10019_mii_readreg;
|
|
|
|
sc->sc_mii.mii_writereg = dl10019_mii_writereg;
|
|
|
|
sc->sc_mii.mii_statchg = dl10019_mii_statchg;
|
2002-10-22 04:01:55 +04:00
|
|
|
ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, dp8390_mediachange,
|
2001-02-13 04:43:02 +03:00
|
|
|
dp8390_mediastatus);
|
|
|
|
|
|
|
|
dl10019_mii_reset(sc);
|
|
|
|
|
2008-03-12 17:31:11 +03:00
|
|
|
mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
|
2001-02-13 04:43:02 +03:00
|
|
|
MII_OFFSET_ANY, 0);
|
|
|
|
|
|
|
|
if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
|
|
|
|
ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
|
|
|
|
} else
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dl10019_media_fini(struct dp8390_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dl10019_mediachange(struct dp8390_softc *sc)
|
|
|
|
{
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
int rc;
|
2001-02-13 04:43:02 +03:00
|
|
|
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
if ((rc = mii_mediachg(&sc->sc_mii)) == ENXIO)
|
|
|
|
return 0;
|
|
|
|
return rc;
|
2001-02-13 04:43:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dl10019_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
|
|
|
|
{
|
|
|
|
|
|
|
|
mii_pollstat(&sc->sc_mii);
|
|
|
|
ifmr->ifm_status = sc->sc_mii.mii_media_status;
|
|
|
|
ifmr->ifm_active = sc->sc_mii.mii_media_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dl10019_init_card(struct dp8390_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
dl10019_mii_reset(sc);
|
|
|
|
mii_mediachg(&sc->sc_mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dl10019_stop_card(struct dp8390_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
mii_down(&sc->sc_mii);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
2008-03-12 17:31:11 +03:00
|
|
|
dl10019_mii_bitbang_read(device_t self)
|
2001-02-13 04:43:02 +03:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct dp8390_softc *sc = device_private(self);
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
/* We're already in Page 0. */
|
|
|
|
return (bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO) &
|
|
|
|
~DL0_GPIO_PRESERVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-12 17:31:11 +03:00
|
|
|
dl10019_mii_bitbang_write(device_t self, u_int32_t val)
|
2001-02-13 04:43:02 +03:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct dp8390_softc *sc = device_private(self);
|
2001-02-13 04:43:02 +03:00
|
|
|
u_int8_t gpio;
|
|
|
|
|
|
|
|
/* We're already in Page 0. */
|
|
|
|
gpio = bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO);
|
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
|
|
|
|
(val & ~DL0_GPIO_PRESERVE) | (gpio & DL0_GPIO_PRESERVE));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-12 17:31:11 +03:00
|
|
|
dl10019_mii_readreg(device_t self, int phy, int reg)
|
2001-02-13 04:43:02 +03:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct ne2000_softc *nsc = device_private(self);
|
2001-06-03 08:39:52 +04:00
|
|
|
const struct mii_bitbang_ops *ops;
|
2001-02-13 04:43:02 +03:00
|
|
|
int val;
|
|
|
|
|
2001-06-03 08:39:52 +04:00
|
|
|
ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
|
|
|
|
&dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
|
|
|
|
|
2001-07-05 09:36:02 +04:00
|
|
|
val = mii_bitbang_readreg(self, ops, phy, reg);
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-12 17:31:11 +03:00
|
|
|
dl10019_mii_writereg(device_t self, int phy, int reg, int val)
|
2001-02-13 04:43:02 +03:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct ne2000_softc *nsc = device_private(self);
|
2001-06-03 08:39:52 +04:00
|
|
|
const struct mii_bitbang_ops *ops;
|
|
|
|
|
|
|
|
ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
|
|
|
|
&dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
|
2001-02-13 04:43:02 +03:00
|
|
|
|
2001-07-05 09:36:02 +04:00
|
|
|
mii_bitbang_writereg(self, ops, phy, reg, val);
|
2001-02-13 04:43:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-12 17:31:11 +03:00
|
|
|
dl10019_mii_statchg(device_t self)
|
2001-02-13 04:43:02 +03:00
|
|
|
{
|
2008-03-12 17:31:11 +03:00
|
|
|
struct dp8390_softc *sc = device_private(self);
|
|
|
|
struct ne2000_softc *nsc = device_private(self);
|
2001-02-13 04:43:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable collision detection on the DL10022 if
|
|
|
|
* we are on a full-duplex link.
|
|
|
|
*/
|
|
|
|
if (nsc->sc_type == NE2000_TYPE_DL10022) {
|
|
|
|
u_int8_t diag;
|
|
|
|
|
|
|
|
if (sc->sc_mii.mii_media_active & IFM_FDX)
|
|
|
|
diag = DL0_DIAG_NOCOLLDETECT;
|
|
|
|
else
|
|
|
|
diag = 0;
|
|
|
|
bus_space_write_1(sc->sc_regt, sc->sc_regh,
|
|
|
|
NEDL_DL0_DIAG, diag);
|
|
|
|
}
|
|
|
|
}
|