2015-04-13 19:33:23 +03:00
|
|
|
/* $NetBSD: qe.c,v 1.63 2015/04/13 16:33:25 riastradh Exp $ */
|
1999-01-17 23:44:18 +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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for the SBus qec+qe QuadEthernet board.
|
|
|
|
*
|
|
|
|
* This driver was written using the AMD MACE Am79C940 documentation, some
|
|
|
|
* ideas gleaned from the S/Linux driver for this card, Solaris header files,
|
|
|
|
* and a loan of a card from Paul Southworth of the Internet Engineering
|
|
|
|
* Group (www.ieng.com).
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-04-13 19:33:23 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: qe.c,v 1.63 2015/04/13 16:33:25 riastradh Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
1999-06-24 23:59:14 +04:00
|
|
|
#define QEDEBUG
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#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 <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-17 23:44:18 +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>
|
2000-07-10 00:57:41 +04:00
|
|
|
#include <machine/autoconf.h>
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-02-03 09:03:37 +03:00
|
|
|
#include <dev/sbus/sbusvar.h>
|
1999-01-17 23:44:18 +03:00
|
|
|
#include <dev/sbus/qecreg.h>
|
|
|
|
#include <dev/sbus/qecvar.h>
|
|
|
|
#include <dev/sbus/qereg.h>
|
|
|
|
|
|
|
|
struct qe_softc {
|
2011-07-18 04:58:51 +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-17 23:44:18 +03:00
|
|
|
bus_dma_tag_t sc_dmatag;
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dmamap_t sc_dmamap;
|
1999-01-17 23:44:18 +03:00
|
|
|
struct ethercom sc_ethercom;
|
|
|
|
struct ifmedia sc_ifmedia; /* interface media */
|
|
|
|
|
|
|
|
struct qec_softc *sc_qec; /* QEC parent */
|
|
|
|
|
|
|
|
bus_space_handle_t sc_qr; /* QEC registers */
|
|
|
|
bus_space_handle_t sc_mr; /* MACE registers */
|
|
|
|
bus_space_handle_t sc_cr; /* channel registers */
|
|
|
|
|
|
|
|
int sc_channel; /* channel number */
|
|
|
|
u_int sc_rev; /* board revision */
|
|
|
|
|
|
|
|
int sc_burst;
|
|
|
|
|
|
|
|
struct qec_ring sc_rb; /* Packet Ring Buffer */
|
|
|
|
|
|
|
|
/* MAC address */
|
2009-09-19 15:53:42 +04:00
|
|
|
uint8_t sc_enaddr[6];
|
1999-06-24 23:59:14 +04:00
|
|
|
|
|
|
|
#ifdef QEDEBUG
|
|
|
|
int sc_debug;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
};
|
|
|
|
|
2009-05-12 18:38:26 +04:00
|
|
|
int qematch(device_t, cfdata_t, void *);
|
|
|
|
void qeattach(device_t, device_t, void *);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
void qeinit(struct qe_softc *);
|
|
|
|
void qestart(struct ifnet *);
|
|
|
|
void qestop(struct qe_softc *);
|
|
|
|
void qewatchdog(struct ifnet *);
|
2007-03-04 08:59:00 +03:00
|
|
|
int qeioctl(struct ifnet *, u_long, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
void qereset(struct qe_softc *);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int qeintr(void *);
|
2009-09-19 15:53:42 +04:00
|
|
|
int qe_eint(struct qe_softc *, uint32_t);
|
2005-02-04 05:10:35 +03:00
|
|
|
int qe_rint(struct qe_softc *);
|
|
|
|
int qe_tint(struct qe_softc *);
|
|
|
|
void qe_mcreset(struct qe_softc *);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static int qe_put(struct qe_softc *, int, struct mbuf *);
|
|
|
|
static void qe_read(struct qe_softc *, int, int);
|
|
|
|
static struct mbuf *qe_get(struct qe_softc *, int, int);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/* ifmedia callbacks */
|
2005-02-04 05:10:35 +03:00
|
|
|
void qe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
|
|
|
int qe_ifmedia_upd(struct ifnet *);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
2011-07-18 04:58:51 +04:00
|
|
|
CFATTACH_DECL_NEW(qe, sizeof(struct qe_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
qematch, qeattach, NULL, NULL);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
int
|
2009-05-12 18:38:26 +04:00
|
|
|
qematch(device_t parent, cfdata_t cf, void *aux)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
return (strcmp(cf->cf_name, sa->sa_name) == 0);
|
1999-01-17 23:44:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-12 18:38:26 +04:00
|
|
|
qeattach(device_t parent, device_t self, void *aux)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct sbus_attach_args *sa = aux;
|
2009-09-18 16:23:16 +04:00
|
|
|
struct qec_softc *qec = device_private(parent);
|
|
|
|
struct qe_softc *sc = device_private(self);
|
1999-01-17 23:44:18 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
int node = sa->sa_node;
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dma_tag_t dmatag = sa->sa_dmatag;
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
bus_size_t size;
|
|
|
|
int rseg, error;
|
|
|
|
|
2011-07-18 04:58:51 +04:00
|
|
|
sc->sc_dev = self;
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
if (sa->sa_nreg < 2) {
|
|
|
|
printf("%s: only %d register sets\n",
|
2008-04-05 22:35:31 +04:00
|
|
|
device_xname(self), sa->sa_nreg);
|
1999-01-17 23:44:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (bus_space_map(sa->sa_bustag,
|
|
|
|
(bus_addr_t)BUS_ADDR(
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[0].oa_space,
|
|
|
|
sa->sa_reg[0].oa_base),
|
|
|
|
(bus_size_t)sa->sa_reg[0].oa_size,
|
2002-03-20 20:57:33 +03:00
|
|
|
0, &sc->sc_cr) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map registers\n");
|
1999-01-17 23:44:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-11 19:00:55 +03:00
|
|
|
if (bus_space_map(sa->sa_bustag,
|
|
|
|
(bus_addr_t)BUS_ADDR(
|
2002-08-23 06:53:10 +04:00
|
|
|
sa->sa_reg[1].oa_space,
|
|
|
|
sa->sa_reg[1].oa_base),
|
|
|
|
(bus_size_t)sa->sa_reg[1].oa_size,
|
2002-03-20 20:57:33 +03:00
|
|
|
0, &sc->sc_mr) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "cannot map registers\n");
|
1999-01-17 23:44:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
sc->sc_rev = prom_getpropint(node, "mace-version", -1);
|
1999-01-17 23:44:18 +03:00
|
|
|
printf(" rev %x", sc->sc_rev);
|
|
|
|
|
2001-09-13 00:09:53 +04:00
|
|
|
sc->sc_bustag = sa->sa_bustag;
|
|
|
|
sc->sc_dmatag = sa->sa_dmatag;
|
1999-01-17 23:44:18 +03:00
|
|
|
sc->sc_qec = qec;
|
|
|
|
sc->sc_qr = qec->sc_regs;
|
|
|
|
|
2004-03-17 20:04:58 +03:00
|
|
|
sc->sc_channel = prom_getpropint(node, "channel#", -1);
|
1999-01-17 23:44:18 +03:00
|
|
|
sc->sc_burst = qec->sc_burst;
|
|
|
|
|
|
|
|
qestop(sc);
|
|
|
|
|
|
|
|
/* Note: no interrupt level passed */
|
2002-12-10 16:44:47 +03:00
|
|
|
(void)bus_intr_establish(sa->sa_bustag, 0, IPL_NET, qeintr, sc);
|
2004-03-16 02:51:11 +03:00
|
|
|
prom_getether(node, sc->sc_enaddr);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate descriptor ring and buffers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
size = QEC_XD_RING_MAXSIZE * sizeof(struct qec_xd) +
|
|
|
|
QEC_XD_RING_MAXSIZE * sizeof(struct qec_xd) +
|
|
|
|
sc->sc_rb.rb_ntbuf * QE_PKT_BUF_SZ +
|
|
|
|
sc->sc_rb.rb_nrbuf * QE_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,
|
2000-05-10 02:42:08 +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(dmatag, size, 0, 0,
|
1999-01-17 23:44:18 +03:00
|
|
|
&seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "DMA buffer alloc error %d\n",
|
|
|
|
error);
|
1999-01-17 23:44:18 +03:00
|
|
|
return;
|
|
|
|
}
|
2000-05-10 02:42:08 +04:00
|
|
|
|
|
|
|
/* Map DMA buffer in CPU addressable space */
|
|
|
|
if ((error = bus_dmamem_map(dmatag, &seg, rseg, size,
|
1999-01-17 23:44:18 +03:00
|
|
|
&sc->sc_rb.rb_membase,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
aprint_error_dev(self, "DMA buffer map error %d\n",
|
|
|
|
error);
|
2001-03-08 05:20:39 +03:00
|
|
|
bus_dmamem_free(dmatag, &seg, rseg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the buffer */
|
|
|
|
if ((error = bus_dmamap_load(dmatag, sc->sc_dmamap,
|
|
|
|
sc->sc_rb.rb_membase, size, NULL,
|
|
|
|
BUS_DMA_NOWAIT)) != 0) {
|
2008-04-05 22:35:31 +04:00
|
|
|
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);
|
2000-05-10 02:42:08 +04:00
|
|
|
bus_dmamem_free(dmatag, &seg, rseg);
|
1999-01-17 23:44:18 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-03-06 22:10:58 +03:00
|
|
|
sc->sc_rb.rb_dmabase = sc->sc_dmamap->dm_segs[0].ds_addr;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/* Initialize media properties */
|
|
|
|
ifmedia_init(&sc->sc_ifmedia, 0, qe_ifmedia_upd, qe_ifmedia_sts);
|
|
|
|
ifmedia_add(&sc->sc_ifmedia,
|
|
|
|
IFM_MAKEWORD(IFM_ETHER,IFM_10_T,0,0),
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&sc->sc_ifmedia,
|
|
|
|
IFM_MAKEWORD(IFM_ETHER,IFM_10_5,0,0),
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_add(&sc->sc_ifmedia,
|
|
|
|
IFM_MAKEWORD(IFM_ETHER,IFM_AUTO,0,0),
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_ifmedia, IFM_ETHER|IFM_AUTO);
|
|
|
|
|
2009-09-18 16:23:16 +04:00
|
|
|
memcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = qestart;
|
|
|
|
ifp->if_ioctl = qeioctl;
|
|
|
|
ifp->if_watchdog = qewatchdog;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS |
|
|
|
|
IFF_MULTICAST;
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
|
|
|
|
printf(" address %s\n", ether_sprintf(sc->sc_enaddr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
qe_get(struct qe_softc *sc, int idx, int totlen)
|
1999-01-17 23:44:18 +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:44:18 +03:00
|
|
|
|
2009-09-18 18:09:42 +04:00
|
|
|
bp = sc->sc_rb.rb_rxbuf + (idx % sc->sc_rb.rb_nrbuf) * QE_PKT_BUF_SZ;
|
1999-01-17 23:44:18 +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-17 23:44:18 +03:00
|
|
|
boff += len;
|
|
|
|
totlen -= len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (top);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to copy from mbuf chain to transmit buffer in
|
|
|
|
* network buffer memory.
|
|
|
|
*/
|
2005-12-25 02:41:33 +03:00
|
|
|
inline int
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_put(struct qe_softc *sc, int idx, struct mbuf *m)
|
1999-01-17 23:44:18 +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:44:18 +03:00
|
|
|
|
2009-09-18 18:09:42 +04:00
|
|
|
bp = sc->sc_rb.rb_txbuf + (idx % sc->sc_rb.rb_ntbuf) * QE_PKT_BUF_SZ;
|
1999-01-17 23:44:18 +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-17 23:44:18 +03:00
|
|
|
boff += len;
|
|
|
|
tlen += len;
|
|
|
|
MFREE(m, n);
|
|
|
|
}
|
|
|
|
return (tlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet to the higher levels.
|
|
|
|
*/
|
2005-12-25 02:41:33 +03:00
|
|
|
inline void
|
2009-03-15 00:04:01 +03:00
|
|
|
qe_read(struct qe_softc *sc, int idx, int len)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ETHERMTU + sizeof(struct ether_header)) {
|
|
|
|
|
|
|
|
printf("%s: invalid packet size %d; dropping\n",
|
|
|
|
ifp->if_xname, len);
|
|
|
|
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull packet off interface.
|
|
|
|
*/
|
|
|
|
m = qe_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-17 23:44:18 +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
|
|
|
qestart(struct ifnet *ifp)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
1999-01-17 23:44:18 +03:00
|
|
|
struct qec_xd *txd = sc->sc_rb.rb_txd;
|
|
|
|
struct mbuf *m;
|
|
|
|
unsigned int bix, len;
|
|
|
|
unsigned int ntbuf = sc->sc_rb.rb_ntbuf;
|
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bix = sc->sc_rb.rb_tdhead;
|
|
|
|
|
|
|
|
for (;;) {
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
1999-01-17 23:44:18 +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-17 23:44:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer.
|
|
|
|
*/
|
|
|
|
len = qe_put(sc, bix, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize transmit registers and start transmission
|
|
|
|
*/
|
|
|
|
txd[bix].xd_flags = QEC_XD_OWN | QEC_XD_SOP | QEC_XD_EOP |
|
|
|
|
(len & QEC_XD_LENGTH);
|
|
|
|
bus_space_write_4(sc->sc_bustag, sc->sc_cr, QE_CRI_CTRL,
|
|
|
|
QE_CR_CTRL_TWAKEUP);
|
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
|
|
|
|
if (++sc->sc_rb.rb_td_nbusy == ntbuf) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_rb.rb_tdhead = bix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qestop(struct qe_softc *sc)
|
2005-02-27 03:26:58 +03:00
|
|
|
{
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
|
|
|
bus_space_handle_t cr = sc->sc_cr;
|
|
|
|
int n;
|
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
/* Stop the schwurst */
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_BIUCC, QE_MR_BIUCC_SWRST);
|
|
|
|
for (n = 200; n > 0; n--) {
|
|
|
|
if ((bus_space_read_1(t, mr, QE_MRI_BIUCC) &
|
|
|
|
QE_MR_BIUCC_SWRST) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then reset */
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_CTRL, QE_CR_CTRL_RESET);
|
|
|
|
for (n = 200; n > 0; n--) {
|
|
|
|
if ((bus_space_read_4(t, cr, QE_CRI_CTRL) &
|
|
|
|
QE_CR_CTRL_RESET) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset interface.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qereset(struct qe_softc *sc)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
qestop(sc);
|
|
|
|
qeinit(sc);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qewatchdog(struct ifnet *ifp)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
|
|
|
|
2011-07-18 04:58:51 +04:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
|
1999-06-24 23:59:14 +04:00
|
|
|
ifp->if_oerrors++;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
qereset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt dispatch.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
qeintr(void *arg)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
2009-09-18 16:23:16 +04:00
|
|
|
struct qe_softc *sc = arg;
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
2009-09-19 15:53:42 +04:00
|
|
|
uint32_t qecstat, qestat;
|
1999-01-17 23:44:18 +03:00
|
|
|
int r = 0;
|
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
/* Read QEC status and channel status */
|
|
|
|
qecstat = bus_space_read_4(t, sc->sc_qr, QEC_QRI_STAT);
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
|
|
|
if (sc->sc_debug) {
|
|
|
|
printf("qe%d: intr: qecstat=%x\n", sc->sc_channel, qecstat);
|
|
|
|
}
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/* Filter out status for this channel */
|
|
|
|
qecstat = qecstat >> (4 * sc->sc_channel);
|
|
|
|
if ((qecstat & 0xf) == 0)
|
|
|
|
return (r);
|
|
|
|
|
|
|
|
qestat = bus_space_read_4(t, sc->sc_cr, QE_CRI_STAT);
|
|
|
|
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
|
|
|
if (sc->sc_debug) {
|
|
|
|
char bits[64]; int i;
|
2005-05-31 02:17:47 +04:00
|
|
|
bus_space_tag_t t1 = sc->sc_bustag;
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(bits, sizeof(bits), QE_CR_STAT_BITS, qestat);
|
|
|
|
printf("qe%d: intr: qestat=%s\n", sc->sc_channel, bits);
|
1999-06-24 23:59:14 +04:00
|
|
|
|
|
|
|
printf("MACE registers:\n");
|
|
|
|
for (i = 0 ; i < 32; i++) {
|
2005-05-31 02:17:47 +04:00
|
|
|
printf(" m[%d]=%x,", i, bus_space_read_1(t1, mr, i));
|
1999-06-24 23:59:14 +04:00
|
|
|
if (((i+1) & 7) == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
if (qestat & QE_CR_STAT_ALLERRORS) {
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
2001-03-30 21:30:18 +04:00
|
|
|
if (sc->sc_debug) {
|
|
|
|
char bits[64];
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(bits, sizeof(bits), QE_CR_STAT_BITS, qestat);
|
|
|
|
printf("qe%d: eint: qestat=%s\n", sc->sc_channel, bits);
|
2001-03-30 21:30:18 +04:00
|
|
|
}
|
1999-06-24 23:59:14 +04:00
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
r |= qe_eint(sc, qestat);
|
|
|
|
if (r == -1)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qestat & QE_CR_STAT_TXIRQ)
|
|
|
|
r |= qe_tint(sc);
|
|
|
|
|
|
|
|
if (qestat & QE_CR_STAT_RXIRQ)
|
|
|
|
r |= qe_rint(sc);
|
|
|
|
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_tint(struct qe_softc *sc)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
unsigned int bix, txflags;
|
|
|
|
|
|
|
|
bix = sc->sc_rb.rb_tdtail;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (sc->sc_rb.rb_td_nbusy <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
txflags = sc->sc_rb.rb_txd[bix].xd_flags;
|
|
|
|
|
|
|
|
if (txflags & QEC_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
|
|
|
|
--sc->sc_rb.rb_td_nbusy;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_rb.rb_tdtail = bix;
|
|
|
|
|
|
|
|
qestart(ifp);
|
|
|
|
|
|
|
|
if (sc->sc_rb.rb_td_nbusy == 0)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_rint(struct qe_softc *sc)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct qec_xd *xd = sc->sc_rb.rb_rxd;
|
|
|
|
unsigned int bix, len;
|
|
|
|
unsigned int nrbuf = sc->sc_rb.rb_nrbuf;
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
|
|
|
int npackets = 0;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
bix = sc->sc_rb.rb_rdtail;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process all buffers with valid data.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
len = xd[bix].xd_flags;
|
|
|
|
if (len & QEC_XD_OWN)
|
|
|
|
break;
|
|
|
|
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
|
|
|
npackets++;
|
|
|
|
#endif
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
len &= QEC_XD_LENGTH;
|
|
|
|
len -= 4;
|
|
|
|
qe_read(sc, bix, len);
|
|
|
|
|
|
|
|
/* ... */
|
|
|
|
xd[(bix+nrbuf) % QEC_XD_RING_MAXSIZE].xd_flags =
|
|
|
|
QEC_XD_OWN | (QE_PKT_BUF_SZ & QEC_XD_LENGTH);
|
|
|
|
|
|
|
|
if (++bix == QEC_XD_RING_MAXSIZE)
|
|
|
|
bix = 0;
|
|
|
|
}
|
1999-06-24 23:59:14 +04:00
|
|
|
#ifdef QEDEBUG
|
2001-03-30 21:30:18 +04:00
|
|
|
if (npackets == 0 && sc->sc_debug)
|
1999-06-24 23:59:14 +04:00
|
|
|
printf("%s: rint: no packets; rb index %d; status 0x%x\n",
|
2011-07-18 04:58:51 +04:00
|
|
|
device_xname(sc->sc_dev), bix, len);
|
1999-06-24 23:59:14 +04:00
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
sc->sc_rb.rb_rdtail = bix;
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2009-09-19 15:53:42 +04:00
|
|
|
qe_eint(struct qe_softc *sc, uint32_t why)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
2011-07-18 04:58:51 +04:00
|
|
|
device_t self = sc->sc_dev;
|
|
|
|
const char *xname = device_xname(self);
|
1999-01-17 23:44:18 +03:00
|
|
|
int r = 0, rst = 0;
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_EDEFER) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: excessive tx defers.\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
r |= 1;
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_CLOSS) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: no carrier, link down?\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_ERETRIES) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: excessive tx retries\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_LCOLL) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: late tx transmission\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_FUFLOW) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: tx fifo underflow\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_JERROR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: jabber seen\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_BERROR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: babble seen\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_TCCOFLOW) {
|
|
|
|
ifp->if_collisions += 256;
|
|
|
|
ifp->if_oerrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_TXDERROR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: tx descriptor is bad\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
rst = 1;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_TXLERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: tx late error\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
rst = 1;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_TXPERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: tx DMA parity error\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
rst = 1;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_TXSERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: tx DMA sbus error ack\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
rst = 1;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RCCOFLOW) {
|
|
|
|
ifp->if_collisions += 256;
|
|
|
|
ifp->if_ierrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RUOFLOW) {
|
|
|
|
ifp->if_ierrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_MCOFLOW) {
|
|
|
|
ifp->if_ierrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXFOFLOW) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx fifo overflow\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RLCOLL) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx late collision\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
ifp->if_collisions++;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_FCOFLOW) {
|
|
|
|
ifp->if_ierrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_CECOFLOW) {
|
|
|
|
ifp->if_ierrors += 256;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXDROP) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx packet dropped\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXSMALL) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx buffer too small\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXLERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx late error\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXPERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx DMA parity error\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (why & QE_CR_STAT_RXSERR) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: rx DMA sbus error ack\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
r |= 1;
|
|
|
|
rst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r == 0)
|
2009-09-18 16:23:16 +04:00
|
|
|
aprint_error_dev(self, "unexpected interrupt error: %08x\n",
|
2008-04-05 22:35:31 +04:00
|
|
|
why);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
if (rst) {
|
2011-07-18 04:58:51 +04:00
|
|
|
printf("%s: resetting...\n", xname);
|
1999-01-17 23:44:18 +03:00
|
|
|
qereset(sc);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
qeioctl(struct ifnet *ifp, u_long cmd, void *data)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
2009-09-18 16:23:16 +04:00
|
|
|
struct ifaddr *ifa = data;
|
|
|
|
struct ifreq *ifr = data;
|
1999-01-17 23:44:18 +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-17 23:44:18 +03:00
|
|
|
ifp->if_flags |= IFF_UP;
|
*** 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
|
|
|
qeinit(sc);
|
1999-01-17 23:44:18 +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-17 23:44:18 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
|
|
|
qestop(sc);
|
|
|
|
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-17 23:44:18 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
qeinit(sc);
|
*** 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-17 23:44:18 +03:00
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect hardware registers.
|
|
|
|
*/
|
|
|
|
qestop(sc);
|
|
|
|
qeinit(sc);
|
*** 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-17 23:44:18 +03:00
|
|
|
}
|
|
|
|
#ifdef QEDEBUG
|
1999-06-24 23:59:14 +04:00
|
|
|
sc->sc_debug = (ifp->if_flags & IFF_DEBUG) != 0 ? 1 : 0;
|
1999-01-17 23:44:18 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2007-09-01 11:32:22 +04:00
|
|
|
if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
|
1999-01-17 23:44:18 +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)
|
|
|
|
qe_mcreset(sc);
|
1999-01-17 23:44:18 +03:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-06-22 15:03:57 +04:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1999-01-17 23:44:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qeinit(struct qe_softc *sc)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t cr = sc->sc_cr;
|
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
|
|
|
struct qec_softc *qec = sc->sc_qec;
|
2009-09-19 15:53:42 +04:00
|
|
|
uint32_t qecaddr;
|
|
|
|
uint8_t *ea;
|
1999-06-24 23:59:14 +04:00
|
|
|
int s;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
2001-01-14 20:37:41 +03:00
|
|
|
s = splnet();
|
1999-06-24 23:59:14 +04:00
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
qestop(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate descriptor ring and buffers
|
|
|
|
*/
|
|
|
|
qec_meminit(&sc->sc_rb, QE_PKT_BUF_SZ);
|
|
|
|
|
|
|
|
/* Channel registers: */
|
2009-09-19 15:53:42 +04:00
|
|
|
bus_space_write_4(t, cr, QE_CRI_RXDS, (uint32_t)sc->sc_rb.rb_rxddma);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_TXDS, (uint32_t)sc->sc_rb.rb_txddma);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_RIMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_TIMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_QMASK, 0);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_MMASK, QE_CR_MMASK_RXCOLL);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_CCNT, 0);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_PIPG, 0);
|
|
|
|
|
|
|
|
qecaddr = sc->sc_channel * qec->sc_msize;
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_RXWBUF, qecaddr);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_RXRBUF, qecaddr);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_TXWBUF, qecaddr + qec->sc_rsize);
|
|
|
|
bus_space_write_4(t, cr, QE_CRI_TXRBUF, qecaddr + qec->sc_rsize);
|
|
|
|
|
|
|
|
/* MACE registers: */
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_PHYCC, QE_MR_PHYCC_ASEL);
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_XMTFC, QE_MR_XMTFC_APADXMT);
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_RCVFC, 0);
|
1999-06-24 23:59:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask MACE's receive interrupt, since we're being notified
|
|
|
|
* by the QEC after DMA completes.
|
|
|
|
*/
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IMR,
|
|
|
|
QE_MR_IMR_CERRM | QE_MR_IMR_RCVINTM);
|
1999-06-24 23:59:14 +04:00
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_BIUCC,
|
|
|
|
QE_MR_BIUCC_BSWAP | QE_MR_BIUCC_64TS);
|
|
|
|
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_FIFOFC,
|
|
|
|
QE_MR_FIFOCC_TXF16 | QE_MR_FIFOCC_RXF32 |
|
|
|
|
QE_MR_FIFOCC_RFWU | QE_MR_FIFOCC_TFWU);
|
|
|
|
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_PLSCC, QE_MR_PLSCC_TP);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Station address
|
|
|
|
*/
|
|
|
|
ea = sc->sc_enaddr;
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC,
|
|
|
|
QE_MR_IAC_ADDRCHG | QE_MR_IAC_PHYADDR);
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_write_multi_1(t, mr, QE_MRI_PADR, ea, 6);
|
1999-01-17 23:44:18 +03:00
|
|
|
|
|
|
|
/* Apply media settings */
|
|
|
|
qe_ifmedia_upd(ifp);
|
|
|
|
|
|
|
|
/*
|
1999-06-24 23:59:14 +04:00
|
|
|
* Clear Logical address filter
|
1999-01-17 23:44:18 +03:00
|
|
|
*/
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC,
|
|
|
|
QE_MR_IAC_ADDRCHG | QE_MR_IAC_LOGADDR);
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_set_multi_1(t, mr, QE_MRI_LADRF, 0, 8);
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC, 0);
|
|
|
|
|
|
|
|
/* Clear missed packet count (register cleared on read) */
|
|
|
|
(void)bus_space_read_1(t, mr, QE_MRI_MPC);
|
|
|
|
|
1999-06-24 23:59:14 +04:00
|
|
|
#if 0
|
|
|
|
/* test register: */
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_UTR, 0);
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-03-23 03:27:09 +03:00
|
|
|
/* Reset multicast filter */
|
|
|
|
qe_mcreset(sc);
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset multicast filter.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_mcreset(struct qe_softc *sc)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
2009-09-19 15:53:42 +04:00
|
|
|
uint32_t crc;
|
|
|
|
uint16_t hash[4];
|
|
|
|
uint8_t octet, maccc, *ladrp = (uint8_t *)&hash[0];
|
2012-06-23 21:21:12 +04:00
|
|
|
int i;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
1999-03-23 03:27:09 +03:00
|
|
|
|
1999-06-24 23:59:14 +04:00
|
|
|
/* We also enable transmitter & receiver here */
|
1999-03-23 03:27:09 +03:00
|
|
|
maccc = QE_MR_MACCC_ENXMT | QE_MR_MACCC_ENRCV;
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
maccc |= QE_MR_MACCC_PROM;
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_MACCC, maccc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-01-17 23:44:18 +03:00
|
|
|
if (ifp->if_flags & IFF_ALLMULTI) {
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC,
|
|
|
|
QE_MR_IAC_ADDRCHG | QE_MR_IAC_LOGADDR);
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_set_multi_1(t, mr, QE_MRI_LADRF, 0xff, 8);
|
1999-01-17 23:44:18 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC, 0);
|
1999-03-23 03:27:09 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_MACCC, maccc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hash[3] = hash[2] = hash[1] = hash[0] = 0;
|
|
|
|
|
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
|
|
|
while (enm != NULL) {
|
2002-05-22 20:03:14 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
|
1999-03-23 03:27:09 +03:00
|
|
|
ETHER_ADDR_LEN) != 0) {
|
|
|
|
/*
|
|
|
|
* 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.)
|
|
|
|
*/
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC,
|
|
|
|
QE_MR_IAC_ADDRCHG | QE_MR_IAC_LOGADDR);
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_set_multi_1(t, mr, QE_MRI_LADRF, 0xff, 8);
|
1999-03-23 03:27:09 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC, 0);
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
break;
|
|
|
|
}
|
1999-01-17 23:44:18 +03:00
|
|
|
|
2012-06-23 21:21:12 +04:00
|
|
|
crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
|
1999-03-23 03:27:09 +03:00
|
|
|
crc >>= 26;
|
|
|
|
hash[crc >> 4] |= 1 << (crc & 0xf);
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
1999-01-17 23:44:18 +03:00
|
|
|
}
|
|
|
|
|
2012-06-23 21:21:12 +04:00
|
|
|
/* We need to byte-swap the hash before writing to the chip. */
|
|
|
|
for (i = 0; i < 7; i += 2) {
|
|
|
|
octet = ladrp[i];
|
|
|
|
ladrp[i] = ladrp[i + 1];
|
|
|
|
ladrp[i + 1] = octet;
|
|
|
|
}
|
1999-03-23 03:27:09 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC,
|
|
|
|
QE_MR_IAC_ADDRCHG | QE_MR_IAC_LOGADDR);
|
1999-06-24 23:59:14 +04:00
|
|
|
bus_space_write_multi_1(t, mr, QE_MRI_LADRF, ladrp, 8);
|
1999-03-23 03:27:09 +03:00
|
|
|
bus_space_write_1(t, mr, QE_MRI_IAC, 0);
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_MACCC, maccc);
|
1999-01-17 23:44:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get current media settings.
|
|
|
|
*/
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
2009-09-19 15:53:42 +04:00
|
|
|
uint8_t v;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
v = bus_space_read_1(t, mr, QE_MRI_PLSCC);
|
|
|
|
|
|
|
|
switch (bus_space_read_1(t, mr, QE_MRI_PLSCC) & QE_MR_PLSCC_PORTMASK) {
|
|
|
|
case QE_MR_PLSCC_TP:
|
|
|
|
ifmr->ifm_active = IFM_ETHER | IFM_10_T;
|
|
|
|
break;
|
|
|
|
case QE_MR_PLSCC_AUI:
|
|
|
|
ifmr->ifm_active = IFM_ETHER | IFM_10_5;
|
|
|
|
break;
|
|
|
|
case QE_MR_PLSCC_GPSI:
|
|
|
|
case QE_MR_PLSCC_DAI:
|
|
|
|
/* ... */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = bus_space_read_1(t, mr, QE_MRI_PHYCC);
|
|
|
|
ifmr->ifm_status |= IFM_AVALID;
|
|
|
|
if ((v & QE_MR_PHYCC_LNKFL) != 0)
|
|
|
|
ifmr->ifm_status &= ~IFM_ACTIVE;
|
|
|
|
else
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
qe_ifmedia_upd(struct ifnet *ifp)
|
1999-01-17 23:44:18 +03:00
|
|
|
{
|
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &sc->sc_ifmedia;
|
|
|
|
bus_space_tag_t t = sc->sc_bustag;
|
|
|
|
bus_space_handle_t mr = sc->sc_mr;
|
|
|
|
int newmedia = ifm->ifm_media;
|
2009-09-19 15:53:42 +04:00
|
|
|
uint8_t plscc, phycc;
|
1999-01-17 23:44:18 +03:00
|
|
|
|
1999-03-09 03:42:20 +03:00
|
|
|
#if defined(SUN4U) || defined(__GNUC__)
|
|
|
|
(void)&t;
|
|
|
|
#endif
|
1999-01-17 23:44:18 +03:00
|
|
|
if (IFM_TYPE(newmedia) != IFM_ETHER)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
plscc = bus_space_read_1(t, mr, QE_MRI_PLSCC) & ~QE_MR_PLSCC_PORTMASK;
|
|
|
|
phycc = bus_space_read_1(t, mr, QE_MRI_PHYCC) & ~QE_MR_PHYCC_ASEL;
|
|
|
|
|
|
|
|
if (IFM_SUBTYPE(newmedia) == IFM_AUTO)
|
|
|
|
phycc |= QE_MR_PHYCC_ASEL;
|
|
|
|
else if (IFM_SUBTYPE(newmedia) == IFM_10_T)
|
|
|
|
plscc |= QE_MR_PLSCC_TP;
|
|
|
|
else if (IFM_SUBTYPE(newmedia) == IFM_10_5)
|
|
|
|
plscc |= QE_MR_PLSCC_AUI;
|
|
|
|
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_PLSCC, plscc);
|
|
|
|
bus_space_write_1(t, mr, QE_MRI_PHYCC, phycc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|