2013-06-09 13:15:51 +04:00
|
|
|
/* $NetBSD: be.c,v 1.80 2013/06/09 09:23:35 msaitoh Exp $ */
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 Theo de Raadt and Jason L. Wright.
|
|
|
|
* 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. The name of the authors may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2013-06-09 13:15:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: be.c,v 1.80 2013/06/09 09:23:35 msaitoh Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1999-01-16 15:43:09 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
1999-01-18 16:29:01 +03:00
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
1999-01-16 15:43:09 +03:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
|
|
|
|
#include <dev/sbus/sbusvar.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
|
|
|
|
#include <dev/sbus/qecreg.h>
|
|
|
|
#include <dev/sbus/qecvar.h>
|
|
|
|
#include <dev/sbus/bereg.h>
|
|
|
|
|
|
|
|
struct be_softc {
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t sc_dev;
|
2003-05-03 22:10:37 +04:00
|
|
|
bus_space_tag_t sc_bustag; /* bus & DMA tags */
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_dma_tag_t sc_dmatag;
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dmamap_t sc_dmamap;
|
1999-01-16 15:43:09 +03:00
|
|
|
struct ethercom sc_ethercom;
|
|
|
|
/*struct ifmedia sc_ifmedia; -* interface media */
|
|
|
|
struct mii_data sc_mii; /* MII media control */
|
|
|
|
#define sc_media sc_mii.mii_media/* shorthand */
|
1999-12-22 00:07:42 +03:00
|
|
|
int sc_phys[2]; /* MII instance -> phy */
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout sc_tick_ch;
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/*
|
|
|
|
* Some `mii_softc' items we need to emulate MII operation
|
|
|
|
* for our internal transceiver.
|
|
|
|
*/
|
|
|
|
int sc_mii_inst; /* instance of internal phy */
|
|
|
|
int sc_mii_active; /* currently active medium */
|
|
|
|
int sc_mii_ticks; /* tick counter */
|
1999-12-23 19:39:56 +03:00
|
|
|
int sc_mii_flags; /* phy status flags */
|
|
|
|
#define MIIF_HAVELINK 0x04000000
|
|
|
|
int sc_intphy_curspeed; /* Established link speed */
|
1999-12-22 19:05:12 +03:00
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
struct qec_softc *sc_qec; /* QEC parent */
|
|
|
|
|
|
|
|
bus_space_handle_t sc_qr; /* QEC registers */
|
|
|
|
bus_space_handle_t sc_br; /* BE registers */
|
|
|
|
bus_space_handle_t sc_cr; /* channel registers */
|
|
|
|
bus_space_handle_t sc_tr; /* transceiver registers */
|
|
|
|
|
|
|
|
u_int sc_rev;
|
|
|
|
|
|
|
|
int sc_channel; /* channel number */
|
|
|
|
int sc_burst;
|
1999-01-17 23:47:50 +03:00
|
|
|
|
|
|
|
struct qec_ring sc_rb; /* Packet Ring Buffer */
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* MAC address */
|
2009-09-18 18:35:11 +04:00
|
|
|
uint8_t sc_enaddr[ETHER_ADDR_LEN];
|
2004-05-04 19:34:37 +04:00
|
|
|
#ifdef BEDEBUG
|
|
|
|
int sc_debug;
|
|
|
|
#endif
|
1999-01-16 15:43:09 +03:00
|
|
|
};
|
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static int bematch(device_t, cfdata_t, void *);
|
|
|
|
static void beattach(device_t, device_t, void *);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static int beinit(struct ifnet *);
|
|
|
|
static void bestart(struct ifnet *);
|
|
|
|
static void bestop(struct ifnet *, int);
|
|
|
|
static void bewatchdog(struct ifnet *);
|
|
|
|
static int beioctl(struct ifnet *, u_long, void *);
|
|
|
|
static void bereset(struct be_softc *);
|
|
|
|
static void behwreset(struct be_softc *);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static int beintr(void *);
|
|
|
|
static int berint(struct be_softc *);
|
|
|
|
static int betint(struct be_softc *);
|
2009-09-18 18:35:11 +04:00
|
|
|
static int beqint(struct be_softc *, uint32_t);
|
|
|
|
static int beeint(struct be_softc *, uint32_t);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static void be_read(struct be_softc *, int, int);
|
|
|
|
static int be_put(struct be_softc *, int, struct mbuf *);
|
|
|
|
static struct mbuf *be_get(struct be_softc *, int, int);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static void be_pal_gate(struct be_softc *, int);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* ifmedia callbacks */
|
2009-09-18 18:14:06 +04:00
|
|
|
static void be_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
|
|
|
static int be_ifmedia_upd(struct ifnet *);
|
1999-01-17 23:47:50 +03:00
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static void be_mcreset(struct be_softc *);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* MII methods & callbacks */
|
2009-05-12 18:38:26 +04:00
|
|
|
static int be_mii_readreg(device_t, int, int);
|
|
|
|
static void be_mii_writereg(device_t, int, int, int);
|
2012-07-22 18:32:49 +04:00
|
|
|
static void be_mii_statchg(struct ifnet *);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* MII helpers */
|
2005-02-04 05:10:35 +03:00
|
|
|
static void be_mii_sync(struct be_softc *);
|
2009-09-18 18:35:11 +04:00
|
|
|
static void be_mii_sendbits(struct be_softc *, int, uint32_t, int);
|
2005-02-04 05:10:35 +03:00
|
|
|
static int be_mii_reset(struct be_softc *, int);
|
|
|
|
static int be_tcvr_read_bit(struct be_softc *, int);
|
|
|
|
static void be_tcvr_write_bit(struct be_softc *, int, int);
|
|
|
|
|
2009-09-18 18:14:06 +04:00
|
|
|
static void be_tick(void *);
|
|
|
|
#if 0
|
|
|
|
static void be_intphy_auto(struct be_softc *);
|
|
|
|
#endif
|
|
|
|
static void be_intphy_status(struct be_softc *);
|
|
|
|
static int be_intphy_service(struct be_softc *, struct mii_data *, int);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
|
2009-09-18 17:48:54 +04:00
|
|
|
CFATTACH_DECL_NEW(be, sizeof(struct be_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
bematch, beattach, NULL, NULL);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
int
|
2009-05-12 18:38:26 +04:00
|
|
|
bematch(device_t parent, cfdata_t cf, void *aux)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return strcmp(cf->cf_name, sa->sa_name) == 0;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-12 18:38:26 +04:00
|
|
|
beattach(device_t parent, device_t self, void *aux)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
2009-09-18 16:23:16 +04:00
|
|
|
struct qec_softc *qec = device_private(parent);
|
|
|
|
struct be_softc *sc = device_private(self);
|
1999-01-16 15:43:09 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mii_data *mii = &sc->sc_mii;
|
1999-12-22 00:07:42 +03:00
|
|
|
struct mii_softc *child;
|
1999-01-16 15:43:09 +03:00
|
|
|
int node = sa->sa_node;
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dma_tag_t dmatag = sa->sa_dmatag;
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
bus_size_t size;
|
2000-05-10 02:42:08 +04:00
|
|
|
int instance;
|
1999-01-16 15:43:09 +03:00
|
|
|
int rseg, error;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t v;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 17:48:54 +04:00
|
|
|
sc->sc_dev = self;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
if (sa->sa_nreg < 3) {
|
2009-09-18 18:00:44 +04:00
|
|
|
printf(": only %d register sets\n", sa->sa_nreg);
|
1999-01-16 15:43:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (bus_space_map(sa->sa_bustag,
|
2009-09-18 18:35:11 +04:00
|
|
|
(bus_addr_t)BUS_ADDR(sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base),
|
|
|
|
(bus_size_t)sa->sa_reg[0].oa_size,
|
|
|
|
0, &sc->sc_cr) != 0) {
|
2009-09-18 18:00:44 +04:00
|
|
|
printf(": cannot map registers\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (bus_space_map(sa->sa_bustag,
|
2009-09-18 18:35:11 +04:00
|
|
|
(bus_addr_t)BUS_ADDR(sa->sa_reg[1].oa_space, sa->sa_reg[1].oa_base),
|
|
|
|
(bus_size_t)sa->sa_reg[1].oa_size,
|
|
|
|
0, &sc->sc_br) != 0) {
|
2009-09-18 18:00:44 +04:00
|
|
|
printf(": cannot map registers\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (bus_space_map(sa->sa_bustag,
|
2009-09-18 18:35:11 +04:00
|
|
|
(bus_addr_t)BUS_ADDR(sa->sa_reg[2].oa_space, sa->sa_reg[2].oa_base),
|
|
|
|
(bus_size_t)sa->sa_reg[2].oa_size,
|
|
|
|
0, &sc->sc_tr) != 0) {
|
2009-09-18 18:00:44 +04:00
|
|
|
printf(": cannot map registers\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-12 23:35:35 +04:00
|
|
|
sc->sc_bustag = sa->sa_bustag;
|
1999-01-16 15:43:09 +03:00
|
|
|
sc->sc_qec = qec;
|
|
|
|
sc->sc_qr = qec->sc_regs;
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
sc->sc_rev = prom_getpropint(node, "board-version", -1);
|
2009-09-18 18:00:44 +04:00
|
|
|
printf(": rev %x,", sc->sc_rev);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2008-12-26 21:51:19 +03:00
|
|
|
callout_init(&sc->sc_tick_ch, 0);
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
sc->sc_channel = prom_getpropint(node, "channel#", -1);
|
1999-01-16 15:43:09 +03:00
|
|
|
if (sc->sc_channel == -1)
|
|
|
|
sc->sc_channel = 0;
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
sc->sc_burst = prom_getpropint(node, "burst-sizes", -1);
|
1999-01-16 15:43:09 +03:00
|
|
|
if (sc->sc_burst == -1)
|
|
|
|
sc->sc_burst = qec->sc_burst;
|
|
|
|
|
|
|
|
/* Clamp at parent's burst sizes */
|
|
|
|
sc->sc_burst &= qec->sc_burst;
|
|
|
|
|
1999-11-21 18:01:50 +03:00
|
|
|
/* Establish interrupt handler */
|
|
|
|
if (sa->sa_nintr)
|
2000-07-10 00:57:41 +04:00
|
|
|
(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_NET,
|
2009-09-18 18:35:11 +04:00
|
|
|
beintr, sc);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2004-03-16 02:51:11 +03:00
|
|
|
prom_getether(node, sc->sc_enaddr);
|
1999-01-16 15:43:09 +03:00
|
|
|
printf(" address %s\n", ether_sprintf(sc->sc_enaddr));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate descriptor ring and buffers.
|
|
|
|
*/
|
1999-01-17 23:47:50 +03:00
|
|
|
|
|
|
|
/* for now, allocate as many bufs as there are ring descriptors */
|
|
|
|
sc->sc_rb.rb_ntbuf = QEC_XD_RING_MAXSIZE;
|
|
|
|
sc->sc_rb.rb_nrbuf = QEC_XD_RING_MAXSIZE;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
size =
|
|
|
|
QEC_XD_RING_MAXSIZE * sizeof(struct qec_xd) +
|
|
|
|
QEC_XD_RING_MAXSIZE * sizeof(struct qec_xd) +
|
|
|
|
sc->sc_rb.rb_ntbuf * BE_PKT_BUF_SZ +
|
|
|
|
sc->sc_rb.rb_nrbuf * BE_PKT_BUF_SZ;
|
2000-05-10 02:42:08 +04:00
|
|
|
|
2000-05-10 18:16:11 +04:00
|
|
|
/* Get a DMA handle */
|
|
|
|
if ((error = bus_dmamap_create(dmatag, size, 1, size, 0,
|
2009-09-18 18:35:11 +04:00
|
|
|
BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "DMA map create error %d\n", error);
|
2000-05-10 02:42:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate DMA buffer */
|
2000-05-10 18:25:43 +04:00
|
|
|
if ((error = bus_dmamem_alloc(sa->sa_dmatag, size, 0, 0,
|
2009-09-18 18:35:11 +04:00
|
|
|
&seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
|
|
|
|
aprint_error_dev(self, "DMA buffer alloc error %d\n", error);
|
1999-01-16 15:43:09 +03:00
|
|
|
return;
|
|
|
|
}
|
2000-05-10 02:42:08 +04:00
|
|
|
|
|
|
|
/* Map DMA memory in CPU addressable space */
|
1999-01-16 15:43:09 +03:00
|
|
|
if ((error = bus_dmamem_map(sa->sa_dmatag, &seg, rseg, size,
|
2009-09-18 18:35:11 +04:00
|
|
|
&sc->sc_rb.rb_membase, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
|
|
|
aprint_error_dev(self, "DMA buffer map error %d\n", error);
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_dmamem_free(sa->sa_dmatag, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-08 05:20:39 +03:00
|
|
|
/* Load the buffer */
|
|
|
|
if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap,
|
2009-09-18 18:35:11 +04:00
|
|
|
sc->sc_rb.rb_membase, size, NULL, BUS_DMA_NOWAIT)) != 0) {
|
|
|
|
aprint_error_dev(self, "DMA buffer map load error %d\n", error);
|
2001-03-08 05:20:39 +03:00
|
|
|
bus_dmamem_unmap(dmatag, sc->sc_rb.rb_membase, size);
|
|
|
|
bus_dmamem_free(dmatag, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
2001-03-20 18:39:20 +03:00
|
|
|
sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr;
|
2001-03-08 05:20:39 +03:00
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* Initialize our media structures and MII info.
|
|
|
|
*/
|
|
|
|
mii->mii_ifp = ifp;
|
|
|
|
mii->mii_readreg = be_mii_readreg;
|
|
|
|
mii->mii_writereg = be_mii_writereg;
|
1999-12-21 01:23:39 +03:00
|
|
|
mii->mii_statchg = be_mii_statchg;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
ifmedia_init(&mii->mii_media, 0, be_ifmedia_upd, be_ifmedia_sts);
|
|
|
|
|
1999-12-22 00:07:42 +03:00
|
|
|
/*
|
|
|
|
* Initialize transceiver and determine which PHY connection to use.
|
|
|
|
*/
|
|
|
|
be_mii_sync(sc);
|
|
|
|
v = bus_space_read_4(sc->sc_bustag, sc->sc_tr, BE_TRI_MGMTPAL);
|
|
|
|
|
|
|
|
instance = 0;
|
|
|
|
|
|
|
|
if ((v & MGMT_PAL_EXT_MDIO) != 0) {
|
1999-12-21 01:23:39 +03:00
|
|
|
|
2009-09-18 16:23:16 +04:00
|
|
|
mii_attach(self, mii, 0xffffffff, BE_PHY_EXTERNAL,
|
2000-02-02 20:46:42 +03:00
|
|
|
MII_OFFSET_ANY, 0);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 00:07:42 +03:00
|
|
|
child = LIST_FIRST(&mii->mii_phys);
|
|
|
|
if (child == NULL) {
|
1999-01-16 15:43:09 +03:00
|
|
|
/* No PHY attached */
|
1999-12-22 00:07:42 +03:00
|
|
|
ifmedia_add(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, instance),
|
|
|
|
0, NULL);
|
1999-12-22 00:07:42 +03:00
|
|
|
ifmedia_set(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, instance));
|
1999-01-16 15:43:09 +03:00
|
|
|
} else {
|
1999-12-22 00:07:42 +03:00
|
|
|
/*
|
|
|
|
* Note: we support just one PHY on the external
|
|
|
|
* MII connector.
|
|
|
|
*/
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (LIST_NEXT(child, mii_list) != NULL) {
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"spurious MII device %s attached\n",
|
|
|
|
device_xname(child->mii_dev));
|
1999-12-22 00:07:42 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (child->mii_phy != BE_PHY_EXTERNAL ||
|
|
|
|
child->mii_inst > 0) {
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"cannot accommodate MII device %s"
|
|
|
|
" at phy %d, instance %d\n",
|
2008-05-04 21:14:41 +04:00
|
|
|
device_xname(child->mii_dev),
|
1999-12-22 00:07:42 +03:00
|
|
|
child->mii_phy, child->mii_inst);
|
|
|
|
} else {
|
|
|
|
sc->sc_phys[instance] = child->mii_phy;
|
|
|
|
}
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* XXX - we can really do the following ONLY if the
|
|
|
|
* phy indeed has the auto negotiation capability!!
|
|
|
|
*/
|
1999-12-22 00:07:42 +03:00
|
|
|
ifmedia_set(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, instance));
|
1999-12-22 00:07:42 +03:00
|
|
|
|
|
|
|
/* Mark our current media setting */
|
|
|
|
be_pal_gate(sc, BE_PHY_EXTERNAL);
|
|
|
|
instance++;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
1999-12-22 00:07:42 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((v & MGMT_PAL_INT_MDIO) != 0) {
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* The be internal phy looks vaguely like MII hardware,
|
|
|
|
* but not enough to be able to use the MII device
|
|
|
|
* layer. Hence, we have to take care of media selection
|
|
|
|
* ourselves.
|
|
|
|
*/
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
sc->sc_mii_inst = instance;
|
1999-12-22 00:07:42 +03:00
|
|
|
sc->sc_phys[instance] = BE_PHY_INTERNAL;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/* Use `ifm_data' to store BMCR bits */
|
|
|
|
ifmedia_add(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, instance),
|
|
|
|
0, NULL);
|
1999-01-16 15:43:09 +03:00
|
|
|
ifmedia_add(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, instance),
|
|
|
|
BMCR_S100, NULL);
|
1999-01-16 15:43:09 +03:00
|
|
|
ifmedia_add(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, instance),
|
|
|
|
0, NULL);
|
1999-12-22 00:07:42 +03:00
|
|
|
|
1999-12-23 19:39:56 +03:00
|
|
|
printf("on-board transceiver at %s: 10baseT, 100baseTX, auto\n",
|
2009-09-18 18:35:11 +04:00
|
|
|
device_xname(self));
|
1999-12-23 19:39:56 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
be_mii_reset(sc, BE_PHY_INTERNAL);
|
1999-12-22 00:07:42 +03:00
|
|
|
/* Only set default medium here if there's no external PHY */
|
|
|
|
if (instance == 0) {
|
|
|
|
be_pal_gate(sc, BE_PHY_INTERNAL);
|
|
|
|
ifmedia_set(&sc->sc_media,
|
2009-09-18 18:35:11 +04:00
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, instance));
|
1999-12-22 19:05:12 +03:00
|
|
|
} else
|
2009-09-18 16:23:16 +04:00
|
|
|
be_mii_writereg(self,
|
2009-09-18 18:35:11 +04:00
|
|
|
BE_PHY_INTERNAL, MII_BMCR, BMCR_ISO);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
2009-09-18 16:23:16 +04:00
|
|
|
memcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = bestart;
|
|
|
|
ifp->if_ioctl = beioctl;
|
|
|
|
ifp->if_watchdog = bewatchdog;
|
2009-09-18 17:45:20 +04:00
|
|
|
ifp->if_init = beinit;
|
|
|
|
ifp->if_stop = bestop;
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags =
|
2009-09-18 18:35:11 +04:00
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2003-10-16 11:20:54 +04:00
|
|
|
/* claim 802.1q capability */
|
|
|
|
sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to copy from mbuf chain to transmit buffer in
|
|
|
|
* network buffer memory.
|
|
|
|
*/
|
2005-12-25 02:41:33 +03:00
|
|
|
static inline int
|
2009-03-14 18:35:58 +03:00
|
|
|
be_put(struct be_softc *sc, int idx, struct mbuf *m)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct mbuf *n;
|
|
|
|
int len, tlen = 0, boff = 0;
|
2009-09-22 17:13:46 +04:00
|
|
|
uint8_t *bp;
|
1999-01-17 23:47:50 +03:00
|
|
|
|
2009-09-18 18:09:42 +04:00
|
|
|
bp = sc->sc_rb.rb_txbuf + (idx % sc->sc_rb.rb_ntbuf) * BE_PKT_BUF_SZ;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
for (; m; m = n) {
|
|
|
|
len = m->m_len;
|
|
|
|
if (len == 0) {
|
|
|
|
MFREE(m, n);
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-22 17:13:46 +04:00
|
|
|
memcpy(bp + boff, mtod(m, void *), len);
|
1999-01-16 15:43:09 +03:00
|
|
|
boff += len;
|
|
|
|
tlen += len;
|
|
|
|
MFREE(m, n);
|
|
|
|
}
|
2009-09-18 18:35:11 +04:00
|
|
|
return tlen;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull data off an interface.
|
|
|
|
* Len is the length of data, with local net header stripped.
|
|
|
|
* We copy the data into mbufs. When full cluster sized units are present,
|
|
|
|
* we copy into clusters.
|
|
|
|
*/
|
2005-12-25 02:41:33 +03:00
|
|
|
static inline struct mbuf *
|
2009-03-15 00:04:01 +03:00
|
|
|
be_get(struct be_softc *sc, int idx, int totlen)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct mbuf *top, **mp;
|
|
|
|
int len, pad, boff = 0;
|
2009-09-22 17:13:46 +04:00
|
|
|
uint8_t *bp;
|
1999-01-17 23:47:50 +03:00
|
|
|
|
2009-09-18 18:09:42 +04:00
|
|
|
bp = sc->sc_rb.rb_rxbuf + (idx % sc->sc_rb.rb_nrbuf) * BE_PKT_BUF_SZ;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return (NULL);
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
|
|
|
|
pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
|
|
|
|
m->m_data += pad;
|
|
|
|
len = MHLEN - pad;
|
|
|
|
top = NULL;
|
|
|
|
mp = ⊤
|
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
m_freem(top);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
len = MLEN;
|
|
|
|
}
|
|
|
|
if (top && totlen >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
len = MCLBYTES;
|
|
|
|
}
|
|
|
|
m->m_len = len = min(totlen, len);
|
2009-09-22 17:13:46 +04:00
|
|
|
memcpy(mtod(m, void *), bp + boff, len);
|
1999-01-16 15:43:09 +03:00
|
|
|
boff += len;
|
|
|
|
totlen -= len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return top;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet to the higher levels.
|
|
|
|
*/
|
2005-12-25 02:41:33 +03:00
|
|
|
static inline void
|
2009-03-15 00:04:01 +03:00
|
|
|
be_read(struct be_softc *sc, int idx, int len)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
2004-05-04 19:34:37 +04:00
|
|
|
if (len <= sizeof(struct ether_header) ||
|
2005-11-05 19:01:52 +03:00
|
|
|
len > ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN) {
|
2004-05-04 19:34:37 +04:00
|
|
|
#ifdef BEDEBUG
|
|
|
|
if (sc->sc_debug)
|
|
|
|
printf("%s: invalid packet size %d; dropping\n",
|
2009-09-18 18:35:11 +04:00
|
|
|
ifp->if_xname, len);
|
2004-05-04 19:34:37 +04:00
|
|
|
#endif
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull packet off interface.
|
|
|
|
*/
|
|
|
|
m = be_get(sc, idx, len);
|
|
|
|
if (m == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
|
|
|
* If so, hand off the raw packet to BPF.
|
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1999-05-19 03:52:51 +04:00
|
|
|
/* Pass the packet up. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface.
|
|
|
|
* We make two assumptions here:
|
|
|
|
* 1) that the current priority is set to splnet _before_ this code
|
|
|
|
* is called *and* is returned to the appropriate priority after
|
|
|
|
* return
|
|
|
|
* 2) that the IFF_OACTIVE flag is checked before this code is called
|
|
|
|
* (i.e. that the output part of the interface is idle)
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
bestart(struct ifnet *ifp)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct be_softc *sc = ifp->if_softc;
|
1999-01-17 23:47:50 +03:00
|
|
|
struct qec_xd *txd = sc->sc_rb.rb_txd;
|
1999-01-16 15:43:09 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
unsigned int bix, len;
|
1999-01-17 23:47:50 +03:00
|
|
|
unsigned int ntbuf = sc->sc_rb.rb_ntbuf;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
bix = sc->sc_rb.rb_tdhead;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
1999-01-16 15:43:09 +03:00
|
|
|
if (m == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If BPF is listening on this interface, let it see the
|
|
|
|
* packet before we commit it to the wire.
|
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer.
|
|
|
|
*/
|
|
|
|
len = be_put(sc, bix, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize transmit registers and start transmission
|
|
|
|
*/
|
|
|
|
txd[bix].xd_flags = QEC_XD_OWN | QEC_XD_SOP | QEC_XD_EOP |
|
2009-09-18 18:35:11 +04:00
|
|
|
(len & QEC_XD_LENGTH);
|
|
|
|
bus_space_write_4(sc->sc_bustag, sc->sc_cr,
|
|
|
|
BE_CRI_CTRL, BE_CR_CTRL_TWAKEUP);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
if (++sc->sc_rb.rb_td_nbusy == ntbuf) {
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
sc->sc_rb.rb_tdhead = bix;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-18 17:45:20 +04:00
|
|
|
bestop(struct ifnet *ifp, int disable)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:45:20 +04:00
|
|
|
struct be_softc *sc = ifp->if_softc;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_tick_ch);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/* Down the MII. */
|
|
|
|
mii_down(&sc->sc_mii);
|
|
|
|
(void)be_intphy_service(sc, &sc->sc_mii, MII_DOWN);
|
1999-11-12 21:14:17 +03:00
|
|
|
|
2009-09-18 17:45:20 +04:00
|
|
|
behwreset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
behwreset(struct be_softc *sc)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t br = sc->sc_br;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/* Stop the transmitter */
|
|
|
|
bus_space_write_4(t, br, BE_BRI_TXCFG, 0);
|
|
|
|
for (n = 32; n > 0; n--) {
|
|
|
|
if (bus_space_read_4(t, br, BE_BRI_TXCFG) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop the receiver */
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXCFG, 0);
|
|
|
|
for (n = 32; n > 0; n--) {
|
|
|
|
if (bus_space_read_4(t, br, BE_BRI_RXCFG) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset interface.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
bereset(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:45:20 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1999-01-16 15:43:09 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
2009-09-18 17:45:20 +04:00
|
|
|
behwreset(sc);
|
1999-12-23 19:39:56 +03:00
|
|
|
if ((sc->sc_ethercom.ec_if.if_flags & IFF_UP) != 0)
|
2009-09-18 17:45:20 +04:00
|
|
|
beinit(ifp);
|
1999-01-16 15:43:09 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
bewatchdog(struct ifnet *ifp)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct be_softc *sc = ifp->if_softc;
|
|
|
|
|
2009-09-18 17:48:54 +04:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
|
1999-01-16 15:43:09 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_oerrors;
|
|
|
|
|
|
|
|
bereset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-09-18 16:23:16 +04:00
|
|
|
beintr(void *arg)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct be_softc *sc = arg;
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t whyq, whyb, whyc;
|
1999-01-16 15:43:09 +03:00
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
/* Read QEC status, channel status and BE status */
|
|
|
|
whyq = bus_space_read_4(t, sc->sc_qr, QEC_QRI_STAT);
|
|
|
|
whyc = bus_space_read_4(t, sc->sc_cr, BE_CRI_STAT);
|
|
|
|
whyb = bus_space_read_4(t, sc->sc_br, BE_BRI_STAT);
|
|
|
|
|
|
|
|
if (whyq & QEC_STAT_BM)
|
|
|
|
r |= beeint(sc, whyb);
|
|
|
|
|
|
|
|
if (whyq & QEC_STAT_ER)
|
|
|
|
r |= beqint(sc, whyc);
|
|
|
|
|
|
|
|
if (whyq & QEC_STAT_TX && whyc & BE_CR_STAT_TXIRQ)
|
|
|
|
r |= betint(sc);
|
|
|
|
|
|
|
|
if (whyq & QEC_STAT_RX && whyc & BE_CR_STAT_RXIRQ)
|
|
|
|
r |= berint(sc);
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return r;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* QEC Interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-09-18 18:35:11 +04:00
|
|
|
beqint(struct be_softc *sc, uint32_t why)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t self = sc->sc_dev;
|
1999-01-16 15:43:09 +03:00
|
|
|
int r = 0, rst = 0;
|
|
|
|
|
|
|
|
if (why & BE_CR_STAT_TXIRQ)
|
|
|
|
r |= 1;
|
|
|
|
if (why & BE_CR_STAT_RXIRQ)
|
|
|
|
r |= 1;
|
|
|
|
|
|
|
|
if (why & BE_CR_STAT_BERROR) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "bigmac error\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (why & BE_CR_STAT_TXDERR) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "bogus tx descriptor\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (why & (BE_CR_STAT_TXLERR | BE_CR_STAT_TXPERR | BE_CR_STAT_TXSERR)) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "tx DMA error ( ");
|
1999-01-16 15:43:09 +03:00
|
|
|
if (why & BE_CR_STAT_TXLERR)
|
|
|
|
printf("Late ");
|
|
|
|
if (why & BE_CR_STAT_TXPERR)
|
|
|
|
printf("Parity ");
|
|
|
|
if (why & BE_CR_STAT_TXSERR)
|
|
|
|
printf("Generic ");
|
|
|
|
printf(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & BE_CR_STAT_RXDROP) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "out of rx descriptors\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (why & BE_CR_STAT_RXSMALL) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "rx descriptor too small\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (why & (BE_CR_STAT_RXLERR | BE_CR_STAT_RXPERR | BE_CR_STAT_RXSERR)) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "rx DMA error ( ");
|
1999-01-16 15:43:09 +03:00
|
|
|
if (why & BE_CR_STAT_RXLERR)
|
|
|
|
printf("Late ");
|
|
|
|
if (why & BE_CR_STAT_RXPERR)
|
|
|
|
printf("Parity ");
|
|
|
|
if (why & BE_CR_STAT_RXSERR)
|
|
|
|
printf("Generic ");
|
|
|
|
printf(")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "unexpected error interrupt %08x\n",
|
2009-09-18 18:35:11 +04:00
|
|
|
why);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rst) {
|
2009-09-18 16:23:16 +04:00
|
|
|
printf("%s: resetting\n", device_xname(self));
|
1999-01-16 15:43:09 +03:00
|
|
|
bereset(sc);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return r;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-09-18 18:35:11 +04:00
|
|
|
beeint(struct be_softc *sc, uint32_t why)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t self = sc->sc_dev;
|
1999-01-16 15:43:09 +03:00
|
|
|
int r = 0, rst = 0;
|
|
|
|
|
|
|
|
if (why & BE_BR_STAT_RFIFOVF) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "receive fifo overrun\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
if (why & BE_BR_STAT_TFIFO_UND) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "transmit fifo underrun\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
if (why & BE_BR_STAT_MAXPKTERR) {
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "max packet size error\n");
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
rst = 1;
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "unexpected error interrupt %08x\n",
|
2009-09-18 18:35:11 +04:00
|
|
|
why);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rst) {
|
2009-09-18 16:23:16 +04:00
|
|
|
printf("%s: resetting\n", device_xname(self));
|
1999-01-16 15:43:09 +03:00
|
|
|
bereset(sc);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return r;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
betint(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t br = sc->sc_br;
|
|
|
|
unsigned int bix, txflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unload collision counters
|
|
|
|
*/
|
|
|
|
ifp->if_collisions +=
|
2009-09-18 18:35:11 +04:00
|
|
|
bus_space_read_4(t, br, BE_BRI_NCCNT) +
|
|
|
|
bus_space_read_4(t, br, BE_BRI_FCCNT) +
|
|
|
|
bus_space_read_4(t, br, BE_BRI_EXCNT) +
|
|
|
|
bus_space_read_4(t, br, BE_BRI_LTCNT);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the clear the hardware counters
|
|
|
|
*/
|
|
|
|
bus_space_write_4(t, br, BE_BRI_NCCNT, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_FCCNT, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_EXCNT, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_LTCNT, 0);
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
bix = sc->sc_rb.rb_tdtail;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
for (;;) {
|
1999-01-17 23:47:50 +03:00
|
|
|
if (sc->sc_rb.rb_td_nbusy <= 0)
|
1999-01-16 15:43:09 +03:00
|
|
|
break;
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
txflags = sc->sc_rb.rb_txd[bix].xd_flags;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
if (txflags & QEC_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
--sc->sc_rb.rb_td_nbusy;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
sc->sc_rb.rb_tdtail = bix;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
bestart(ifp);
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
if (sc->sc_rb.rb_td_nbusy == 0)
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return 1;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
berint(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
1999-01-17 23:47:50 +03:00
|
|
|
struct qec_xd *xd = sc->sc_rb.rb_rxd;
|
1999-01-16 15:43:09 +03:00
|
|
|
unsigned int bix, len;
|
1999-01-17 23:47:50 +03:00
|
|
|
unsigned int nrbuf = sc->sc_rb.rb_nrbuf;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
bix = sc->sc_rb.rb_rdtail;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all buffers with valid data.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
len = xd[bix].xd_flags;
|
|
|
|
if (len & QEC_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
len &= QEC_XD_LENGTH;
|
|
|
|
be_read(sc, bix, len);
|
|
|
|
|
|
|
|
/* ... */
|
|
|
|
xd[(bix+nrbuf) % QEC_XD_RING_MAXSIZE].xd_flags =
|
2009-09-18 18:35:11 +04:00
|
|
|
QEC_XD_OWN | (BE_PKT_BUF_SZ & QEC_XD_LENGTH);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
}
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
sc->sc_rb.rb_rdtail = bix;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return 1;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
beioctl(struct ifnet *ifp, u_long cmd, void *data)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
struct be_softc *sc = ifp->if_softc;
|
2009-09-18 16:23:16 +04:00
|
|
|
struct ifaddr *ifa = data;
|
|
|
|
struct ifreq *ifr = data;
|
1999-01-16 15:43:09 +03:00
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
switch (cmd) {
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
case SIOCINITIFADDR:
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags |= IFF_UP;
|
2009-09-18 17:45:20 +04:00
|
|
|
beinit(ifp);
|
1999-01-16 15:43:09 +03:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if ((error = ifioctl_common(ifp, cmd, data)) != 0)
|
|
|
|
break;
|
|
|
|
/* XXX re-use ether_ioctl() */
|
|
|
|
switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
|
|
|
|
case IFF_RUNNING:
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
2009-09-18 17:45:20 +04:00
|
|
|
bestop(ifp, 0);
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
case IFF_UP:
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
2009-09-18 17:45:20 +04:00
|
|
|
beinit(ifp);
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
default:
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect hardware registers.
|
|
|
|
*/
|
2009-09-18 17:45:20 +04:00
|
|
|
bestop(ifp, 0);
|
|
|
|
beinit(ifp);
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
#ifdef BEDEBUG
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
1999-01-17 23:47:50 +03:00
|
|
|
sc->sc_debug = 1;
|
1999-01-16 15:43:09 +03:00
|
|
|
else
|
|
|
|
sc->sc_debug = 0;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2009-09-18 17:45:20 +04:00
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
|
|
|
|
break;
|
|
|
|
default:
|
2007-09-01 11:32:22 +04:00
|
|
|
if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2004-10-30 22:08:34 +04:00
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
2009-09-18 17:45:20 +04:00
|
|
|
error = beinit(ifp);
|
|
|
|
else
|
|
|
|
error = 0;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
2009-09-18 18:35:11 +04:00
|
|
|
return error;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-18 17:45:20 +04:00
|
|
|
int
|
|
|
|
beinit(struct ifnet *ifp)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:45:20 +04:00
|
|
|
struct be_softc *sc = ifp->if_softc;
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t br = sc->sc_br;
|
|
|
|
bus_space_handle_t cr = sc->sc_cr;
|
|
|
|
struct qec_softc *qec = sc->sc_qec;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t v;
|
|
|
|
uint32_t qecaddr;
|
|
|
|
uint8_t *ea;
|
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, s;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2001-01-14 20:37:41 +03:00
|
|
|
s = splnet();
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
qec_meminit(&sc->sc_rb, BE_PKT_BUF_SZ);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 17:45:20 +04:00
|
|
|
bestop(ifp, 1);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
ea = sc->sc_enaddr;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_MACADDR0, (ea[0] << 8) | ea[1]);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_MACADDR1, (ea[2] << 8) | ea[3]);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_MACADDR2, (ea[4] << 8) | ea[5]);
|
|
|
|
|
2000-02-14 20:06:45 +03:00
|
|
|
/* Clear hash table */
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB0, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB1, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB2, 0);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB3, 0);
|
|
|
|
|
2000-02-14 20:06:45 +03:00
|
|
|
/* Re-initialize RX configuration */
|
|
|
|
v = BE_BR_RXCFG_FIFO;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXCFG, v);
|
|
|
|
|
1999-03-23 03:27:09 +03:00
|
|
|
be_mcreset(sc);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RANDSEED, 0xbd);
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
bus_space_write_4(t, br,
|
|
|
|
BE_BRI_XIFCFG, BE_BR_XCFG_ODENABLE | BE_BR_XCFG_RESV);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
bus_space_write_4(t, br, BE_BRI_JSIZE, 4);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off counter expiration interrupts as well as
|
|
|
|
* 'gotframe' and 'sentframe'
|
|
|
|
*/
|
|
|
|
bus_space_write_4(t, br, BE_BRI_IMASK,
|
2009-09-18 18:35:11 +04:00
|
|
|
BE_BR_IMASK_GOTFRAME |
|
|
|
|
BE_BR_IMASK_RCNTEXP |
|
|
|
|
BE_BR_IMASK_ACNTEXP |
|
|
|
|
BE_BR_IMASK_CCNTEXP |
|
|
|
|
BE_BR_IMASK_LCNTEXP |
|
|
|
|
BE_BR_IMASK_CVCNTEXP |
|
|
|
|
BE_BR_IMASK_SENTFRAME |
|
|
|
|
BE_BR_IMASK_NCNTEXP |
|
|
|
|
BE_BR_IMASK_ECNTEXP |
|
|
|
|
BE_BR_IMASK_LCCNTEXP |
|
|
|
|
BE_BR_IMASK_FCNTEXP |
|
|
|
|
BE_BR_IMASK_DTIMEXP);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* Channel registers: */
|
2009-09-18 18:35:11 +04:00
|
|
|
bus_space_write_4(t, cr, BE_CRI_RXDS, (uint32_t)sc->sc_rb.rb_rxddma);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_TXDS, (uint32_t)sc->sc_rb.rb_txddma);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
qecaddr = sc->sc_channel * qec->sc_msize;
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_RXWBUF, qecaddr);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_RXRBUF, qecaddr);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_TXWBUF, qecaddr + qec->sc_rsize);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_TXRBUF, qecaddr + qec->sc_rsize);
|
|
|
|
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_RIMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_TIMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_QMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_BMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, BE_CRI_CCNT, 0);
|
|
|
|
|
2003-10-16 11:20:54 +04:00
|
|
|
/* Set max packet length */
|
|
|
|
v = ETHER_MAX_LEN;
|
|
|
|
if (sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU)
|
|
|
|
v += ETHER_VLAN_ENCAP_LEN;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXMAX, v);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_TXMAX, v);
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/* Enable transmitter */
|
2009-09-18 18:35:11 +04:00
|
|
|
bus_space_write_4(t, br,
|
|
|
|
BE_BRI_TXCFG, BE_BR_TXCFG_FIFO | BE_BR_TXCFG_ENABLE);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
/* Enable receiver */
|
2000-02-14 20:06:45 +03:00
|
|
|
v = bus_space_read_4(t, br, BE_BRI_RXCFG);
|
|
|
|
v |= BE_BR_RXCFG_FIFO | BE_BR_RXCFG_ENABLE;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXCFG, v);
|
1999-01-16 15:43:09 +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 = be_ifmedia_upd(ifp)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_tick_ch, hz, be_tick, sc);
|
2009-09-18 17:45:20 +04:00
|
|
|
|
|
|
|
return 0;
|
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
|
|
|
out:
|
1999-01-16 15:43:09 +03:00
|
|
|
splx(s);
|
2009-09-18 17:45:20 +04:00
|
|
|
return rc;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_mcreset(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
1999-01-17 23:47:50 +03:00
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
1999-01-16 15:43:09 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t br = sc->sc_br;
|
2009-09-18 18:40:49 +04:00
|
|
|
uint32_t v;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t crc;
|
|
|
|
uint16_t hash[4];
|
1999-01-16 15:43:09 +03:00
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
|
1999-03-23 03:27:09 +03:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
v = bus_space_read_4(t, br, BE_BRI_RXCFG);
|
|
|
|
v |= BE_BR_RXCFG_PMISC;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXCFG, v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
if (ifp->if_flags & IFF_ALLMULTI) {
|
2000-02-14 20:06:45 +03:00
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0xffff;
|
|
|
|
goto chipit;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0;
|
|
|
|
|
1999-01-17 23:47:50 +03:00
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
1999-01-16 15:43:09 +03:00
|
|
|
while (enm != NULL) {
|
2002-05-22 20:03:14 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast
|
|
|
|
* addresses. For now, just accept all
|
|
|
|
* multicasts, rather than trying to set only
|
|
|
|
* those filter bits needed to match the range.
|
|
|
|
* (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for
|
|
|
|
* which the range is big enough to require
|
|
|
|
* all bits set.)
|
|
|
|
*/
|
2000-02-14 20:06:45 +03:00
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0xffff;
|
1999-01-16 15:43:09 +03:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
2000-02-14 20:06:45 +03:00
|
|
|
goto chipit;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
2009-09-18 18:40:49 +04:00
|
|
|
crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
|
|
|
|
/* Just want the 6 most significant bits. */
|
1999-01-16 15:43:09 +03:00
|
|
|
crc >>= 26;
|
2009-09-18 18:40:49 +04:00
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
hash[crc >> 4] |= 1 << (crc & 0xf);
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
|
2000-02-14 20:06:45 +03:00
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
|
|
|
|
chipit:
|
|
|
|
/* Enable the hash filter */
|
1999-01-16 15:43:09 +03:00
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB0, hash[0]);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB1, hash[1]);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB2, hash[2]);
|
|
|
|
bus_space_write_4(t, br, BE_BRI_HASHTAB3, hash[3]);
|
2000-02-14 20:06:45 +03:00
|
|
|
|
|
|
|
v = bus_space_read_4(t, br, BE_BRI_RXCFG);
|
|
|
|
v &= ~BE_BR_RXCFG_PMISC;
|
|
|
|
v |= BE_BR_RXCFG_HENABLE;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_RXCFG, v);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the tcvr to an idle state
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_mii_sync(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t tr = sc->sc_tr;
|
1999-12-21 01:23:39 +03:00
|
|
|
int n = 32;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
while (n--) {
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL,
|
2009-09-18 18:35:11 +04:00
|
|
|
MGMT_PAL_INT_MDIO | MGMT_PAL_EXT_MDIO | MGMT_PAL_OENAB);
|
1999-01-16 15:43:09 +03:00
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL,
|
2009-09-18 18:35:11 +04:00
|
|
|
MGMT_PAL_INT_MDIO | MGMT_PAL_EXT_MDIO |
|
|
|
|
MGMT_PAL_OENAB | MGMT_PAL_DCLOCK);
|
1999-01-16 15:43:09 +03:00
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-22 00:07:42 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_pal_gate(struct be_softc *sc, int phy)
|
1999-12-22 00:07:42 +03:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t tr = sc->sc_tr;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t v;
|
1999-12-22 00:07:42 +03:00
|
|
|
|
|
|
|
be_mii_sync(sc);
|
|
|
|
|
|
|
|
v = ~(TCVR_PAL_EXTLBACK | TCVR_PAL_MSENSE | TCVR_PAL_LTENABLE);
|
|
|
|
if (phy == BE_PHY_INTERNAL)
|
|
|
|
v &= ~TCVR_PAL_SERIAL;
|
|
|
|
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_TCVRPAL, v);
|
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_TCVRPAL);
|
|
|
|
}
|
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
be_tcvr_read_bit(struct be_softc *sc, int phy)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t tr = sc->sc_tr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (phy == BE_PHY_INTERNAL) {
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL, MGMT_PAL_EXT_MDIO);
|
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
2009-09-18 18:35:11 +04:00
|
|
|
bus_space_write_4(t, tr,
|
|
|
|
BE_TRI_MGMTPAL, MGMT_PAL_EXT_MDIO | MGMT_PAL_DCLOCK);
|
1999-01-16 15:43:09 +03:00
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
ret = (bus_space_read_4(t, tr, BE_TRI_MGMTPAL) &
|
2009-09-18 18:35:11 +04:00
|
|
|
MGMT_PAL_INT_MDIO) >> MGMT_PAL_INT_MDIO_SHIFT;
|
1999-01-16 15:43:09 +03:00
|
|
|
} else {
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL, MGMT_PAL_INT_MDIO);
|
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
ret = (bus_space_read_4(t, tr, BE_TRI_MGMTPAL) &
|
2009-09-18 18:35:11 +04:00
|
|
|
MGMT_PAL_EXT_MDIO) >> MGMT_PAL_EXT_MDIO_SHIFT;
|
|
|
|
bus_space_write_4(t, tr,
|
|
|
|
BE_TRI_MGMTPAL, MGMT_PAL_INT_MDIO | MGMT_PAL_DCLOCK);
|
1999-01-16 15:43:09 +03:00
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return ret;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
static void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_tcvr_write_bit(struct be_softc *sc, int phy, int bit)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t tr = sc->sc_tr;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint32_t v;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
if (phy == BE_PHY_INTERNAL) {
|
1999-12-21 01:23:39 +03:00
|
|
|
v = ((bit & 1) << MGMT_PAL_INT_MDIO_SHIFT) |
|
2009-09-18 18:35:11 +04:00
|
|
|
MGMT_PAL_OENAB | MGMT_PAL_EXT_MDIO;
|
1999-01-16 15:43:09 +03:00
|
|
|
} else {
|
2009-09-18 18:35:11 +04:00
|
|
|
v = ((bit & 1) << MGMT_PAL_EXT_MDIO_SHIFT) |
|
|
|
|
MGMT_PAL_OENAB | MGMT_PAL_INT_MDIO;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
1999-12-22 19:05:12 +03:00
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL, v);
|
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
|
|
|
bus_space_write_4(t, tr, BE_TRI_MGMTPAL, v | MGMT_PAL_DCLOCK);
|
|
|
|
(void)bus_space_read_4(t, tr, BE_TRI_MGMTPAL);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
static void
|
2009-09-18 18:35:11 +04:00
|
|
|
be_mii_sendbits(struct be_softc *sc, int phy, uint32_t data, int nbits)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1 << (nbits - 1); i != 0; i >>= 1) {
|
|
|
|
be_tcvr_write_bit(sc, phy, (data & i) != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-19 17:57:00 +03:00
|
|
|
static int
|
2009-05-12 18:38:26 +04:00
|
|
|
be_mii_readreg(device_t self, int phy, int reg)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct be_softc *sc = device_private(self);
|
1999-01-16 15:43:09 +03:00
|
|
|
int val = 0, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the PHY register by manually driving the MII control lines.
|
|
|
|
*/
|
|
|
|
be_mii_sync(sc);
|
|
|
|
be_mii_sendbits(sc, phy, MII_COMMAND_START, 2);
|
|
|
|
be_mii_sendbits(sc, phy, MII_COMMAND_READ, 2);
|
|
|
|
be_mii_sendbits(sc, phy, phy, 5);
|
|
|
|
be_mii_sendbits(sc, phy, reg, 5);
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
(void)be_tcvr_read_bit(sc, phy);
|
|
|
|
(void)be_tcvr_read_bit(sc, phy);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
for (i = 15; i >= 0; i--)
|
|
|
|
val |= (be_tcvr_read_bit(sc, phy) << i);
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
(void)be_tcvr_read_bit(sc, phy);
|
|
|
|
(void)be_tcvr_read_bit(sc, phy);
|
|
|
|
(void)be_tcvr_read_bit(sc, phy);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return val;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-12 18:38:26 +04:00
|
|
|
be_mii_writereg(device_t self, int phy, int reg, int val)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct be_softc *sc = device_private(self);
|
1999-01-16 15:43:09 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the PHY register by manually driving the MII control lines.
|
|
|
|
*/
|
|
|
|
be_mii_sync(sc);
|
|
|
|
be_mii_sendbits(sc, phy, MII_COMMAND_START, 2);
|
|
|
|
be_mii_sendbits(sc, phy, MII_COMMAND_WRITE, 2);
|
|
|
|
be_mii_sendbits(sc, phy, phy, 5);
|
|
|
|
be_mii_sendbits(sc, phy, reg, 5);
|
|
|
|
|
|
|
|
be_tcvr_write_bit(sc, phy, 1);
|
|
|
|
be_tcvr_write_bit(sc, phy, 0);
|
|
|
|
|
|
|
|
for (i = 15; i >= 0; i--)
|
|
|
|
be_tcvr_write_bit(sc, phy, (val >> i) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
be_mii_reset(struct be_softc *sc, int phy)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t self = sc->sc_dev;
|
1999-01-16 15:43:09 +03:00
|
|
|
int n;
|
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
be_mii_writereg(self, phy, MII_BMCR, BMCR_LOOP | BMCR_PDOWN | BMCR_ISO);
|
2009-09-18 16:23:16 +04:00
|
|
|
be_mii_writereg(self, phy, MII_BMCR, BMCR_RESET);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
for (n = 16; n >= 0; n--) {
|
2009-09-18 16:23:16 +04:00
|
|
|
int bmcr = be_mii_readreg(self, phy, MII_BMCR);
|
1999-01-16 15:43:09 +03:00
|
|
|
if ((bmcr & BMCR_RESET) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
if (n == 0) {
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "bmcr reset failed\n");
|
2009-09-18 18:35:11 +04:00
|
|
|
return EIO;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
1999-12-23 19:39:56 +03:00
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_tick(void *arg)
|
1999-12-22 19:05:12 +03:00
|
|
|
{
|
|
|
|
struct be_softc *sc = arg;
|
|
|
|
int s = splnet();
|
|
|
|
|
|
|
|
mii_tick(&sc->sc_mii);
|
|
|
|
(void)be_intphy_service(sc, &sc->sc_mii, MII_TICK);
|
|
|
|
|
|
|
|
splx(s);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_tick_ch, hz, be_tick, sc);
|
1999-12-22 19:05:12 +03:00
|
|
|
}
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
void
|
2012-07-22 18:32:49 +04:00
|
|
|
be_mii_statchg(struct ifnet *ifp)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
2012-07-22 18:32:49 +04:00
|
|
|
struct be_softc *sc = ifp->if_softc;
|
1999-12-21 01:23:39 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t br = sc->sc_br;
|
2009-09-18 18:35:11 +04:00
|
|
|
uint instance;
|
|
|
|
uint32_t v;
|
1999-12-21 01:23:39 +03:00
|
|
|
|
1999-12-22 00:07:42 +03:00
|
|
|
instance = IFM_INST(sc->sc_mii.mii_media.ifm_cur->ifm_media);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (instance > 1)
|
|
|
|
panic("be_mii_statchg: instance %d out of range", instance);
|
|
|
|
#endif
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
/* Update duplex mode in TX configuration */
|
|
|
|
v = bus_space_read_4(t, br, BE_BRI_TXCFG);
|
|
|
|
if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0)
|
|
|
|
v |= BE_BR_TXCFG_FULLDPLX;
|
|
|
|
else
|
|
|
|
v &= ~BE_BR_TXCFG_FULLDPLX;
|
|
|
|
bus_space_write_4(t, br, BE_BRI_TXCFG, v);
|
1999-12-22 00:07:42 +03:00
|
|
|
|
|
|
|
/* Change to appropriate gate in transceiver PAL */
|
|
|
|
be_pal_gate(sc, sc->sc_phys[instance]);
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/*
|
|
|
|
* Get current media settings.
|
|
|
|
*/
|
1999-01-16 15:43:09 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
1999-12-22 19:05:12 +03:00
|
|
|
struct be_softc *sc = ifp->if_softc;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
mii_pollstat(&sc->sc_mii);
|
|
|
|
(void)be_intphy_service(sc, &sc->sc_mii, MII_POLLSTAT);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
ifmr->ifm_status = sc->sc_mii.mii_media_status;
|
|
|
|
ifmr->ifm_active = sc->sc_mii.mii_media_active;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
be_ifmedia_upd(struct ifnet *ifp)
|
1999-12-22 19:05:12 +03:00
|
|
|
{
|
|
|
|
struct be_softc *sc = ifp->if_softc;
|
|
|
|
int error;
|
|
|
|
|
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 ((error = mii_mediachg(&sc->sc_mii)) == ENXIO)
|
|
|
|
error = 0;
|
|
|
|
else if (error != 0)
|
|
|
|
return error;
|
1999-12-22 19:05:12 +03:00
|
|
|
|
2009-09-18 18:35:11 +04:00
|
|
|
return be_intphy_service(sc, &sc->sc_mii, MII_MEDIACHG);
|
1999-12-22 19:05:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Service routine for our pseudo-MII internal transceiver.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
be_intphy_service(struct be_softc *sc, struct mii_data *mii, int cmd)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
1999-12-22 19:05:12 +03:00
|
|
|
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t self = sc->sc_dev;
|
1999-01-16 15:43:09 +03:00
|
|
|
int bmcr, bmsr;
|
1999-12-23 19:39:56 +03:00
|
|
|
int error;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case MII_POLLSTAT:
|
|
|
|
/*
|
|
|
|
* If we're not polling our PHY instance, just return.
|
|
|
|
*/
|
|
|
|
if (IFM_INST(ife->ifm_media) != sc->sc_mii_inst)
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
break;
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
case MII_MEDIACHG:
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/*
|
|
|
|
* If the media indicates a different PHY instance,
|
|
|
|
* isolate ourselves.
|
|
|
|
*/
|
|
|
|
if (IFM_INST(ife->ifm_media) != sc->sc_mii_inst) {
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
|
|
|
be_mii_writereg(self,
|
|
|
|
BE_PHY_INTERNAL, MII_BMCR, bmcr | BMCR_ISO);
|
1999-12-23 19:39:56 +03:00
|
|
|
sc->sc_mii_flags &= ~MIIF_HAVELINK;
|
|
|
|
sc->sc_intphy_curspeed = 0;
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-12-22 19:05:12 +03:00
|
|
|
}
|
1999-01-16 15:43:09 +03:00
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
|
1999-12-23 19:39:56 +03:00
|
|
|
if ((error = be_mii_reset(sc, BE_PHY_INTERNAL)) != 0)
|
2009-09-18 18:35:11 +04:00
|
|
|
return error;
|
1999-12-23 19:39:56 +03:00
|
|
|
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
1999-12-23 19:39:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select the new mode and take out of isolation
|
|
|
|
*/
|
1999-12-22 19:05:12 +03:00
|
|
|
if (IFM_SUBTYPE(ife->ifm_media) == IFM_100_TX)
|
|
|
|
bmcr |= BMCR_S100;
|
|
|
|
else if (IFM_SUBTYPE(ife->ifm_media) == IFM_10_T)
|
|
|
|
bmcr &= ~BMCR_S100;
|
1999-12-23 19:39:56 +03:00
|
|
|
else if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
|
|
|
|
if ((sc->sc_mii_flags & MIIF_HAVELINK) != 0) {
|
|
|
|
bmcr &= ~BMCR_S100;
|
|
|
|
bmcr |= sc->sc_intphy_curspeed;
|
|
|
|
} else {
|
|
|
|
/* Keep isolated until link is up */
|
|
|
|
bmcr |= BMCR_ISO;
|
|
|
|
sc->sc_mii_flags |= MIIF_DOINGAUTO;
|
|
|
|
}
|
|
|
|
}
|
1999-12-21 01:23:39 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
if ((IFM_OPTIONS(ife->ifm_media) & IFM_FDX) != 0)
|
|
|
|
bmcr |= BMCR_FDX;
|
|
|
|
else
|
|
|
|
bmcr &= ~BMCR_FDX;
|
|
|
|
|
2009-09-18 16:23:16 +04:00
|
|
|
be_mii_writereg(self, BE_PHY_INTERNAL, MII_BMCR, bmcr);
|
1999-12-22 19:05:12 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MII_TICK:
|
|
|
|
/*
|
|
|
|
* If we're not currently selected, just return.
|
|
|
|
*/
|
|
|
|
if (IFM_INST(ife->ifm_media) != sc->sc_mii_inst)
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-12-22 19:05:12 +03:00
|
|
|
|
|
|
|
/* Is the interface even up? */
|
|
|
|
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-12-22 19:05:12 +03:00
|
|
|
|
2013-06-09 13:15:51 +04:00
|
|
|
/* Only used for automatic media selection */
|
|
|
|
if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
|
|
|
|
break;
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/*
|
|
|
|
* Check link status; if we don't have a link, try another
|
|
|
|
* speed. We can't detect duplex mode, so half-duplex is
|
|
|
|
* what we have to settle for.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Read twice in case the register is latched */
|
2009-09-18 18:35:11 +04:00
|
|
|
bmsr =
|
|
|
|
be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMSR) |
|
|
|
|
be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMSR);
|
1999-12-22 19:05:12 +03:00
|
|
|
|
|
|
|
if ((bmsr & BMSR_LINK) != 0) {
|
|
|
|
/* We have a carrier */
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
1999-12-23 19:39:56 +03:00
|
|
|
|
|
|
|
if ((sc->sc_mii_flags & MIIF_DOINGAUTO) != 0) {
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self,
|
|
|
|
BE_PHY_INTERNAL, MII_BMCR);
|
1999-12-23 19:39:56 +03:00
|
|
|
|
|
|
|
sc->sc_mii_flags |= MIIF_HAVELINK;
|
|
|
|
sc->sc_intphy_curspeed = (bmcr & BMCR_S100);
|
|
|
|
sc->sc_mii_flags &= ~MIIF_DOINGAUTO;
|
|
|
|
|
|
|
|
bmcr &= ~BMCR_ISO;
|
2009-09-18 16:23:16 +04:00
|
|
|
be_mii_writereg(self,
|
|
|
|
BE_PHY_INTERNAL, MII_BMCR, bmcr);
|
1999-12-23 19:39:56 +03:00
|
|
|
|
|
|
|
printf("%s: link up at %s Mbps\n",
|
2009-09-18 16:23:16 +04:00
|
|
|
device_xname(self),
|
|
|
|
(bmcr & BMCR_S100) ? "100" : "10");
|
1999-12-23 19:39:56 +03:00
|
|
|
}
|
2013-06-09 13:15:51 +04:00
|
|
|
break;
|
1999-12-22 19:05:12 +03:00
|
|
|
}
|
|
|
|
|
1999-12-23 19:39:56 +03:00
|
|
|
if ((sc->sc_mii_flags & MIIF_DOINGAUTO) == 0) {
|
|
|
|
sc->sc_mii_flags |= MIIF_DOINGAUTO;
|
|
|
|
sc->sc_mii_flags &= ~MIIF_HAVELINK;
|
|
|
|
sc->sc_intphy_curspeed = 0;
|
2009-09-18 16:23:16 +04:00
|
|
|
printf("%s: link down\n", device_xname(self));
|
1999-12-23 19:39:56 +03:00
|
|
|
}
|
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
/* Only retry autonegotiation every 5 seconds. */
|
1999-12-23 19:39:56 +03:00
|
|
|
if (++sc->sc_mii_ticks < 5)
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-12-22 19:05:12 +03:00
|
|
|
|
|
|
|
sc->sc_mii_ticks = 0;
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
1999-12-22 19:05:12 +03:00
|
|
|
/* Just flip the fast speed bit */
|
|
|
|
bmcr ^= BMCR_S100;
|
2009-09-18 16:23:16 +04:00
|
|
|
be_mii_writereg(self, BE_PHY_INTERNAL, MII_BMCR, bmcr);
|
1999-12-22 19:05:12 +03:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MII_DOWN:
|
1999-12-23 19:39:56 +03:00
|
|
|
/* Isolate this phy */
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
|
|
|
be_mii_writereg(self,
|
|
|
|
BE_PHY_INTERNAL, MII_BMCR, bmcr | BMCR_ISO);
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-12-22 19:05:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the media status. */
|
|
|
|
be_intphy_status(sc);
|
|
|
|
|
|
|
|
/* Callback if something changed. */
|
|
|
|
if (sc->sc_mii_active != mii->mii_media_active || cmd == MII_MEDIACHG) {
|
2012-07-22 18:32:49 +04:00
|
|
|
(*mii->mii_statchg)(mii->mii_ifp);
|
1999-12-22 19:05:12 +03:00
|
|
|
sc->sc_mii_active = mii->mii_media_active;
|
|
|
|
}
|
2009-09-18 18:35:11 +04:00
|
|
|
return 0;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-12-22 19:05:12 +03:00
|
|
|
* Determine status of internal transceiver
|
1999-01-16 15:43:09 +03:00
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
be_intphy_status(struct be_softc *sc)
|
1999-01-16 15:43:09 +03:00
|
|
|
{
|
1999-12-22 19:05:12 +03:00
|
|
|
struct mii_data *mii = &sc->sc_mii;
|
2009-09-18 17:48:54 +04:00
|
|
|
device_t self = sc->sc_dev;
|
1999-12-21 01:23:39 +03:00
|
|
|
int media_active, media_status;
|
1999-01-16 15:43:09 +03:00
|
|
|
int bmcr, bmsr;
|
|
|
|
|
1999-12-21 01:23:39 +03:00
|
|
|
media_status = IFM_AVALID;
|
|
|
|
media_active = 0;
|
|
|
|
|
1999-01-16 15:43:09 +03:00
|
|
|
/*
|
|
|
|
* Internal transceiver; do the work here.
|
|
|
|
*/
|
2009-09-18 16:23:16 +04:00
|
|
|
bmcr = be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMCR);
|
1999-01-16 15:43:09 +03:00
|
|
|
|
|
|
|
switch (bmcr & (BMCR_S100 | BMCR_FDX)) {
|
|
|
|
case (BMCR_S100 | BMCR_FDX):
|
1999-12-21 01:23:39 +03:00
|
|
|
media_active = IFM_ETHER | IFM_100_TX | IFM_FDX;
|
1999-01-16 15:43:09 +03:00
|
|
|
break;
|
|
|
|
case BMCR_S100:
|
1999-12-21 01:23:39 +03:00
|
|
|
media_active = IFM_ETHER | IFM_100_TX | IFM_HDX;
|
1999-01-16 15:43:09 +03:00
|
|
|
break;
|
|
|
|
case BMCR_FDX:
|
1999-12-21 01:23:39 +03:00
|
|
|
media_active = IFM_ETHER | IFM_10_T | IFM_FDX;
|
1999-01-16 15:43:09 +03:00
|
|
|
break;
|
|
|
|
case 0:
|
1999-12-21 01:23:39 +03:00
|
|
|
media_active = IFM_ETHER | IFM_10_T | IFM_HDX;
|
1999-01-16 15:43:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read twice in case the register is latched */
|
2009-09-18 18:35:11 +04:00
|
|
|
bmsr =
|
|
|
|
be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMSR) |
|
|
|
|
be_mii_readreg(self, BE_PHY_INTERNAL, MII_BMSR);
|
1999-01-16 15:43:09 +03:00
|
|
|
if (bmsr & BMSR_LINK)
|
1999-12-22 00:07:42 +03:00
|
|
|
media_status |= IFM_ACTIVE;
|
1999-12-21 01:23:39 +03:00
|
|
|
|
1999-12-22 19:05:12 +03:00
|
|
|
mii->mii_media_status = media_status;
|
|
|
|
mii->mii_media_active = media_active;
|
1999-01-16 15:43:09 +03:00
|
|
|
}
|