2010-11-13 16:51:57 +03:00
|
|
|
/* $NetBSD: sgec.c,v 1.39 2010/11/13 13:52:02 uebayasi Exp $ */
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 Ludd, University of Lule}, Sweden. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
2005-02-27 03:26:58 +03:00
|
|
|
* This product includes software developed at Ludd, University of
|
1999-08-08 15:41:28 +04:00
|
|
|
* Lule}, Sweden and its contributors.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for the SGEC (Second Generation Ethernet Controller), sitting
|
2005-02-27 03:26:58 +03:00
|
|
|
* on for example the VAX 4000/300 (KA670).
|
1999-08-08 15:41:28 +04:00
|
|
|
*
|
|
|
|
* The SGEC looks like a mixture of the DEQNA and the TULIP. Fun toy.
|
|
|
|
*
|
|
|
|
* Even though the chip is capable to use virtual addresses (read the
|
|
|
|
* System Page Table directly) this driver doesn't do so, and there
|
|
|
|
* is no benefit in doing it either in NetBSD of today.
|
|
|
|
*
|
|
|
|
* Things that is still to do:
|
|
|
|
* Collect statistics.
|
|
|
|
* Use imperfect filtering when many multicast addresses.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-11-13 16:51:57 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sgec.c,v 1.39 2010/11/13 13:52:02 uebayasi Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
#include <dev/ic/sgecreg.h>
|
|
|
|
#include <dev/ic/sgecvar.h>
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static void zeinit(struct ze_softc *);
|
|
|
|
static void zestart(struct ifnet *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int zeioctl(struct ifnet *, u_long, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
static int ze_add_rxbuf(struct ze_softc *, int);
|
|
|
|
static void ze_setup(struct ze_softc *);
|
|
|
|
static void zetimeout(struct ifnet *);
|
2008-03-11 08:34:01 +03:00
|
|
|
static bool zereset(struct ze_softc *);
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
#define ZE_WCSR(csr, val) \
|
|
|
|
bus_space_write_4(sc->sc_iot, sc->sc_ioh, csr, val)
|
|
|
|
#define ZE_RCSR(csr) \
|
|
|
|
bus_space_read_4(sc->sc_iot, sc->sc_ioh, csr)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets.
|
|
|
|
*/
|
|
|
|
void
|
2008-03-11 08:34:01 +03:00
|
|
|
sgec_attach(struct ze_softc *sc)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
2008-03-11 08:34:01 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct ze_tdes *tp;
|
|
|
|
struct ze_rdes *rp;
|
1999-08-08 15:41:28 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
int i, rseg, error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate DMA safe memory for descriptors and setup memory.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
error = bus_dmamem_alloc(sc->sc_dmat, sizeof(struct ze_cdata),
|
|
|
|
PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
aprint_error(": unable to allocate control data, error = %d\n",
|
1999-08-08 15:41:28 +04:00
|
|
|
error);
|
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, sizeof(struct ze_cdata),
|
|
|
|
(void **)&sc->sc_zedata, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
|
|
|
|
if (error) {
|
|
|
|
aprint_error(
|
|
|
|
": unable to map control data, error = %d\n", error);
|
1999-08-08 15:41:28 +04:00
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
error = bus_dmamap_create(sc->sc_dmat, sizeof(struct ze_cdata), 1,
|
|
|
|
sizeof(struct ze_cdata), 0, BUS_DMA_NOWAIT, &sc->sc_cmap);
|
|
|
|
if (error) {
|
|
|
|
aprint_error(
|
|
|
|
": unable to create control data DMA map, error = %d\n",
|
1999-08-08 15:41:28 +04:00
|
|
|
error);
|
|
|
|
goto fail_2;
|
|
|
|
}
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
error = bus_dmamap_load(sc->sc_dmat, sc->sc_cmap, sc->sc_zedata,
|
|
|
|
sizeof(struct ze_cdata), NULL, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
aprint_error(
|
|
|
|
": unable to load control data DMA map, error = %d\n",
|
1999-08-08 15:41:28 +04:00
|
|
|
error);
|
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero the newly allocated memory.
|
|
|
|
*/
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(sc->sc_zedata, 0, sizeof(struct ze_cdata));
|
2008-03-11 08:34:01 +03:00
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Create the transmit descriptor DMA maps.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
for (i = 0; error == 0 && i < TXDESCS; i++) {
|
|
|
|
error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
|
2007-04-13 08:16:45 +04:00
|
|
|
TXDESCS - 1, MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_xmtmap[i]);
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
aprint_error(": unable to create tx DMA map %d, error = %d\n",
|
|
|
|
i, error);
|
|
|
|
goto fail_4;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create receive buffer DMA maps.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
for (i = 0; error == 0 && i < RXDESCS; i++) {
|
|
|
|
error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
|
|
|
|
MCLBYTES, 0, BUS_DMA_NOWAIT, &sc->sc_rcvmap[i]);
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
aprint_error(": unable to create rx DMA map %d, error = %d\n",
|
|
|
|
i, error);
|
|
|
|
goto fail_5;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
2008-03-11 08:34:01 +03:00
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Pre-allocate the receive buffers.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
for (i = 0; error == 0 && i < RXDESCS; i++) {
|
|
|
|
error = ze_add_rxbuf(sc, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
aprint_error(
|
|
|
|
": unable to allocate or map rx buffer %d, error = %d\n",
|
|
|
|
i, error);
|
|
|
|
goto fail_6;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
|
2000-06-04 06:14:12 +04:00
|
|
|
/* For vmstat -i
|
|
|
|
*/
|
2000-06-05 06:28:19 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
|
2008-03-11 08:34:01 +03:00
|
|
|
device_xname(sc->sc_dev), "intr");
|
2007-04-27 03:08:22 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_rxintrcnt, EVCNT_TYPE_INTR,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_intrcnt, device_xname(sc->sc_dev), "rx intr");
|
2007-04-27 03:08:22 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_txintrcnt, EVCNT_TYPE_INTR,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_intrcnt, device_xname(sc->sc_dev), "tx intr");
|
2007-04-27 03:08:22 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_txdraincnt, EVCNT_TYPE_INTR,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_intrcnt, device_xname(sc->sc_dev), "tx drain");
|
2007-04-27 03:08:22 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_nobufintrcnt, EVCNT_TYPE_INTR,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_intrcnt, device_xname(sc->sc_dev), "nobuf intr");
|
2007-04-27 03:08:22 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_nointrcnt, EVCNT_TYPE_INTR,
|
2008-03-11 08:34:01 +03:00
|
|
|
&sc->sc_intrcnt, device_xname(sc->sc_dev), "no intr");
|
2000-06-04 06:14:12 +04:00
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Create ring loops of the buffer chains.
|
|
|
|
* This is only done once.
|
|
|
|
*/
|
|
|
|
sc->sc_pzedata = (struct ze_cdata *)sc->sc_cmap->dm_segs[0].ds_addr;
|
|
|
|
|
|
|
|
rp = sc->sc_zedata->zc_recv;
|
|
|
|
rp[RXDESCS].ze_framelen = ZE_FRAMELEN_OW;
|
|
|
|
rp[RXDESCS].ze_rdes1 = ZE_RDES1_CA;
|
|
|
|
rp[RXDESCS].ze_bufaddr = (char *)sc->sc_pzedata->zc_recv;
|
|
|
|
|
|
|
|
tp = sc->sc_zedata->zc_xmit;
|
|
|
|
tp[TXDESCS].ze_tdr = ZE_TDR_OW;
|
|
|
|
tp[TXDESCS].ze_tdes1 = ZE_TDES1_CA;
|
|
|
|
tp[TXDESCS].ze_bufaddr = (char *)sc->sc_pzedata->zc_xmit;
|
|
|
|
|
|
|
|
if (zereset(sc))
|
|
|
|
return;
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
strcpy(ifp->if_xname, device_xname(sc->sc_dev));
|
1999-08-08 15:41:28 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_start = zestart;
|
|
|
|
ifp->if_ioctl = zeioctl;
|
|
|
|
ifp->if_watchdog = zetimeout;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_normal("\n");
|
|
|
|
aprint_normal_dev(sc->sc_dev, "hardware address %s\n",
|
1999-08-08 15:41:28 +04:00
|
|
|
ether_sprintf(sc->sc_enaddr));
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free any resources we've allocated during the failed attach
|
|
|
|
* attempt. Do this in reverse order and fall through.
|
|
|
|
*/
|
|
|
|
fail_6:
|
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
|
|
|
if (sc->sc_rxmbuf[i] != NULL) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_xmtmap[i]);
|
|
|
|
m_freem(sc->sc_rxmbuf[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail_5:
|
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
|
|
|
if (sc->sc_xmtmap[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_xmtmap[i]);
|
|
|
|
}
|
|
|
|
fail_4:
|
|
|
|
for (i = 0; i < TXDESCS; i++) {
|
|
|
|
if (sc->sc_rcvmap[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_rcvmap[i]);
|
|
|
|
}
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_cmap);
|
|
|
|
fail_3:
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmap);
|
|
|
|
fail_2:
|
2007-03-04 08:59:00 +03:00
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_zedata,
|
1999-08-08 15:41:28 +04:00
|
|
|
sizeof(struct ze_cdata));
|
|
|
|
fail_1:
|
|
|
|
bus_dmamem_free(sc->sc_dmat, &seg, rseg);
|
|
|
|
fail_0:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface.
|
|
|
|
*/
|
|
|
|
void
|
2008-03-11 08:34:01 +03:00
|
|
|
zeinit(struct ze_softc *sc)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
2008-03-11 08:34:01 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
1999-08-08 15:41:28 +04:00
|
|
|
struct ze_cdata *zc = sc->sc_zedata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the interface.
|
|
|
|
*/
|
|
|
|
if (zereset(sc))
|
|
|
|
return;
|
|
|
|
|
2007-04-27 03:08:22 +04:00
|
|
|
sc->sc_nexttx = sc->sc_inq = sc->sc_lastack = sc->sc_txcnt = 0;
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Release and init transmit descriptors.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < TXDESCS; i++) {
|
2007-04-13 08:16:45 +04:00
|
|
|
if (sc->sc_xmtmap[i]->dm_nsegs > 0)
|
1999-08-08 15:41:28 +04:00
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_xmtmap[i]);
|
2007-04-13 08:16:45 +04:00
|
|
|
if (sc->sc_txmbuf[i]) {
|
1999-08-08 15:41:28 +04:00
|
|
|
m_freem(sc->sc_txmbuf[i]);
|
|
|
|
sc->sc_txmbuf[i] = 0;
|
|
|
|
}
|
|
|
|
zc->zc_xmit[i].ze_tdr = 0; /* Clear valid bit */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init receive descriptors.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < RXDESCS; i++)
|
|
|
|
zc->zc_recv[i].ze_framelen = ZE_FRAMELEN_OW;
|
|
|
|
sc->sc_nextrx = 0;
|
|
|
|
|
|
|
|
ZE_WCSR(ZE_CSR6, ZE_NICSR6_IE|ZE_NICSR6_BL_8|ZE_NICSR6_ST|
|
|
|
|
ZE_NICSR6_SR|ZE_NICSR6_DC);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a setup frame.
|
|
|
|
* This will start the transmit machinery as well.
|
|
|
|
*/
|
|
|
|
ze_setup(sc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface.
|
|
|
|
*/
|
|
|
|
void
|
2008-03-11 08:34:01 +03:00
|
|
|
zestart(struct ifnet *ifp)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct ze_softc *sc = ifp->if_softc;
|
|
|
|
struct ze_cdata *zc = sc->sc_zedata;
|
|
|
|
paddr_t buffer;
|
2007-04-13 08:16:45 +04:00
|
|
|
struct mbuf *m;
|
2007-04-27 03:08:22 +04:00
|
|
|
int nexttx, starttx;
|
|
|
|
int len, i, totlen, error;
|
2000-05-27 08:26:32 +04:00
|
|
|
int old_inq = sc->sc_inq;
|
2007-04-27 03:08:22 +04:00
|
|
|
uint16_t orword, tdr;
|
2007-04-13 08:16:45 +04:00
|
|
|
bus_dmamap_t map;
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
while (sc->sc_inq < (TXDESCS - 1)) {
|
|
|
|
|
|
|
|
if (sc->sc_setup) {
|
|
|
|
ze_setup(sc);
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-13 08:16:45 +04:00
|
|
|
nexttx = sc->sc_nexttx;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_POLL(&sc->sc_if.if_snd, m);
|
1999-08-08 15:41:28 +04:00
|
|
|
if (m == 0)
|
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* Count number of mbufs in chain.
|
|
|
|
* Always do DMA directly from mbufs, therefore the transmit
|
|
|
|
* ring is really big.
|
|
|
|
*/
|
2007-04-13 08:16:45 +04:00
|
|
|
map = sc->sc_xmtmap[nexttx];
|
|
|
|
error = bus_dmamap_load_mbuf(sc->sc_dmat, map, m,
|
|
|
|
BUS_DMA_WRITE);
|
|
|
|
if (error) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"zestart: load_mbuf failed: %d", error);
|
2007-04-13 08:16:45 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map->dm_nsegs >= TXDESCS)
|
1999-08-08 15:41:28 +04:00
|
|
|
panic("zestart"); /* XXX */
|
|
|
|
|
2007-04-13 08:16:45 +04:00
|
|
|
if ((map->dm_nsegs + sc->sc_inq) >= (TXDESCS - 1)) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, map);
|
1999-08-08 15:41:28 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* m now points to a mbuf chain that can be loaded.
|
|
|
|
* Loop around and set it.
|
|
|
|
*/
|
|
|
|
totlen = 0;
|
2007-04-13 08:16:45 +04:00
|
|
|
orword = ZE_TDES1_FS;
|
2007-04-27 03:08:22 +04:00
|
|
|
starttx = nexttx;
|
2007-04-13 08:16:45 +04:00
|
|
|
for (i = 0; i < map->dm_nsegs; i++) {
|
|
|
|
buffer = map->dm_segs[i].ds_addr;
|
|
|
|
len = map->dm_segs[i].ds_len;
|
|
|
|
|
2007-04-27 03:08:22 +04:00
|
|
|
KASSERT(len > 0);
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
totlen += len;
|
|
|
|
/* Word alignment calc */
|
|
|
|
if (totlen == m->m_pkthdr.len) {
|
2007-04-27 03:08:22 +04:00
|
|
|
sc->sc_txcnt += map->dm_nsegs;
|
|
|
|
if (sc->sc_txcnt >= TXDESCS * 3 / 4) {
|
|
|
|
orword |= ZE_TDES1_IC;
|
|
|
|
sc->sc_txcnt = 0;
|
|
|
|
}
|
|
|
|
orword |= ZE_TDES1_LS;
|
2007-04-13 08:16:45 +04:00
|
|
|
sc->sc_txmbuf[nexttx] = m;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
2007-04-13 08:16:45 +04:00
|
|
|
zc->zc_xmit[nexttx].ze_bufsize = len;
|
|
|
|
zc->zc_xmit[nexttx].ze_bufaddr = (char *)buffer;
|
|
|
|
zc->zc_xmit[nexttx].ze_tdes1 = orword;
|
2007-04-27 03:08:22 +04:00
|
|
|
zc->zc_xmit[nexttx].ze_tdr = tdr;
|
2007-04-13 08:16:45 +04:00
|
|
|
|
|
|
|
if (++nexttx == TXDESCS)
|
|
|
|
nexttx = 0;
|
|
|
|
orword = 0;
|
2007-04-27 03:08:22 +04:00
|
|
|
tdr = ZE_TDR_OW;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
2007-04-13 08:16:45 +04:00
|
|
|
|
|
|
|
sc->sc_inq += map->dm_nsegs;
|
|
|
|
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
1999-08-08 15:41:28 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (totlen != m->m_pkthdr.len)
|
|
|
|
panic("zestart: len fault");
|
|
|
|
#endif
|
2007-04-27 03:08:22 +04:00
|
|
|
/*
|
|
|
|
* Turn ownership of the packet over to the device.
|
|
|
|
*/
|
|
|
|
zc->zc_xmit[starttx].ze_tdr = ZE_TDR_OW;
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick off the transmit logic, if it is stopped.
|
|
|
|
*/
|
|
|
|
if ((ZE_RCSR(ZE_CSR5) & ZE_NICSR5_TS) != ZE_NICSR5_TS_RUN)
|
|
|
|
ZE_WCSR(ZE_CSR1, -1);
|
2007-04-13 08:16:45 +04:00
|
|
|
sc->sc_nexttx = nexttx;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
if (sc->sc_inq == (TXDESCS - 1))
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
2000-05-27 08:26:32 +04:00
|
|
|
out: if (old_inq < sc->sc_inq)
|
1999-08-08 15:41:28 +04:00
|
|
|
ifp->if_timer = 5; /* If transmit logic dies */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-11 08:34:01 +03:00
|
|
|
sgec_intr(struct ze_softc *sc)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct ze_cdata *zc = sc->sc_zedata;
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
int csr, len;
|
|
|
|
|
|
|
|
csr = ZE_RCSR(ZE_CSR5);
|
2007-04-27 03:08:22 +04:00
|
|
|
if ((csr & ZE_NICSR5_IS) == 0) { /* Wasn't we */
|
|
|
|
sc->sc_nointrcnt.ev_count++;
|
1999-08-08 15:41:28 +04:00
|
|
|
return 0;
|
2007-04-27 03:08:22 +04:00
|
|
|
}
|
1999-08-08 15:41:28 +04:00
|
|
|
ZE_WCSR(ZE_CSR5, csr);
|
|
|
|
|
2007-04-27 03:08:22 +04:00
|
|
|
if (csr & ZE_NICSR5_RU)
|
|
|
|
sc->sc_nobufintrcnt.ev_count++;
|
|
|
|
|
2005-01-31 06:02:27 +03:00
|
|
|
if (csr & ZE_NICSR5_RI) {
|
2007-04-27 03:08:22 +04:00
|
|
|
sc->sc_rxintrcnt.ev_count++;
|
1999-08-08 15:41:28 +04:00
|
|
|
while ((zc->zc_recv[sc->sc_nextrx].ze_framelen &
|
|
|
|
ZE_FRAMELEN_OW) == 0) {
|
|
|
|
|
2000-05-20 22:33:18 +04:00
|
|
|
ifp->if_ipackets++;
|
1999-08-08 15:41:28 +04:00
|
|
|
m = sc->sc_rxmbuf[sc->sc_nextrx];
|
|
|
|
len = zc->zc_recv[sc->sc_nextrx].ze_framelen;
|
|
|
|
ze_add_rxbuf(sc, sc->sc_nextrx);
|
|
|
|
if (++sc->sc_nextrx == RXDESCS)
|
|
|
|
sc->sc_nextrx = 0;
|
2005-01-31 06:02:27 +03:00
|
|
|
if (len < ETHER_MIN_LEN) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
m_freem(m);
|
|
|
|
} else {
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len =
|
|
|
|
len - ETHER_CRC_LEN;
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
2005-01-31 06:02:27 +03:00
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
}
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
2005-01-31 06:02:27 +03:00
|
|
|
}
|
1999-08-08 15:41:28 +04:00
|
|
|
|
2007-04-27 03:08:22 +04:00
|
|
|
if (csr & ZE_NICSR5_TI)
|
|
|
|
sc->sc_txintrcnt.ev_count++;
|
|
|
|
if (sc->sc_lastack != sc->sc_nexttx) {
|
|
|
|
int lastack;
|
|
|
|
for (lastack = sc->sc_lastack; lastack != sc->sc_nexttx; ) {
|
2007-04-13 08:16:45 +04:00
|
|
|
bus_dmamap_t map;
|
|
|
|
int nlastack;
|
1999-08-08 15:41:28 +04:00
|
|
|
|
2007-04-27 03:08:22 +04:00
|
|
|
if ((zc->zc_xmit[lastack].ze_tdr & ZE_TDR_OW) != 0)
|
1999-08-08 15:41:28 +04:00
|
|
|
break;
|
|
|
|
|
2007-04-13 08:16:45 +04:00
|
|
|
if ((zc->zc_xmit[lastack].ze_tdes1 & ZE_TDES1_DT) ==
|
|
|
|
ZE_TDES1_DT_SETUP) {
|
|
|
|
if (++lastack == TXDESCS)
|
|
|
|
lastack = 0;
|
|
|
|
sc->sc_inq--;
|
1999-08-08 15:41:28 +04:00
|
|
|
continue;
|
|
|
|
}
|
2007-04-13 08:16:45 +04:00
|
|
|
|
|
|
|
KASSERT(zc->zc_xmit[lastack].ze_tdes1 & ZE_TDES1_FS);
|
|
|
|
map = sc->sc_xmtmap[lastack];
|
|
|
|
KASSERT(map->dm_nsegs > 0);
|
|
|
|
nlastack = (lastack + map->dm_nsegs - 1) % TXDESCS;
|
|
|
|
if (zc->zc_xmit[nlastack].ze_tdr & ZE_TDR_OW)
|
|
|
|
break;
|
|
|
|
lastack = nlastack;
|
2007-04-27 03:08:22 +04:00
|
|
|
if (sc->sc_txcnt > map->dm_nsegs)
|
|
|
|
sc->sc_txcnt -= map->dm_nsegs;
|
|
|
|
else
|
|
|
|
sc->sc_txcnt = 0;
|
2007-04-13 08:16:45 +04:00
|
|
|
sc->sc_inq -= map->dm_nsegs;
|
|
|
|
KASSERT(zc->zc_xmit[lastack].ze_tdes1 & ZE_TDES1_LS);
|
|
|
|
ifp->if_opackets++;
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, map);
|
|
|
|
KASSERT(sc->sc_txmbuf[lastack]);
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, sc->sc_txmbuf[lastack]);
|
2007-04-13 08:16:45 +04:00
|
|
|
m_freem(sc->sc_txmbuf[lastack]);
|
|
|
|
sc->sc_txmbuf[lastack] = 0;
|
|
|
|
if (++lastack == TXDESCS)
|
|
|
|
lastack = 0;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
2007-04-27 03:08:22 +04:00
|
|
|
if (lastack != sc->sc_lastack) {
|
|
|
|
sc->sc_txdraincnt.ev_count++;
|
|
|
|
sc->sc_lastack = lastack;
|
|
|
|
if (sc->sc_inq == 0)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
zestart(ifp); /* Put in more in queue */
|
|
|
|
}
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
int
|
2008-03-11 08:34:01 +03:00
|
|
|
zeioctl(struct ifnet *ifp, u_long cmd, void *data)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct ze_softc *sc = ifp->if_softc;
|
2008-03-11 08:34:01 +03:00
|
|
|
struct ifaddr *ifa = data;
|
1999-08-08 15:41:28 +04:00
|
|
|
int s = splnet(), error = 0;
|
|
|
|
|
|
|
|
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-08-08 15:41:28 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
zeinit(sc);
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
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-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running,
|
|
|
|
* stop it. (by disabling receive mechanism).
|
|
|
|
*/
|
|
|
|
ZE_WCSR(ZE_CSR6, ZE_RCSR(ZE_CSR6) &
|
|
|
|
~(ZE_NICSR6_ST|ZE_NICSR6_SR));
|
|
|
|
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-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* If interface it marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
zeinit(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;
|
|
|
|
case IFF_UP|IFF_RUNNING:
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Send a new setup packet to match any new changes.
|
|
|
|
* (Like IFF_PROMISC etc)
|
|
|
|
*/
|
|
|
|
ze_setup(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;
|
|
|
|
case 0:
|
|
|
|
break;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
/*
|
|
|
|
* Update our multicast list.
|
|
|
|
*/
|
2007-09-01 11:32:22 +04:00
|
|
|
if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
2004-10-30 22:08:34 +04:00
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
|
|
|
ze_setup(sc);
|
1999-08-08 15:41:28 +04:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
*** 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
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a receive buffer to the indicated descriptor.
|
|
|
|
*/
|
|
|
|
int
|
2008-03-11 08:34:01 +03:00
|
|
|
ze_add_rxbuf(struct ze_softc *sc, int i)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ze_rdes *rp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
2003-02-26 09:31:08 +03:00
|
|
|
MCLAIM(m, &sc->sc_ec.ec_rx_mowner);
|
1999-08-08 15:41:28 +04:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_rxmbuf[i] != NULL)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
|
|
|
|
|
|
|
|
error = bus_dmamap_load(sc->sc_dmat, sc->sc_rcvmap[i],
|
2001-07-19 20:25:23 +04:00
|
|
|
m->m_ext.ext_buf, m->m_ext.ext_size, NULL,
|
|
|
|
BUS_DMA_READ|BUS_DMA_NOWAIT);
|
1999-08-08 15:41:28 +04:00
|
|
|
if (error)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("%s: can't load rx DMA map %d, error = %d",
|
2008-03-11 08:34:01 +03:00
|
|
|
device_xname(sc->sc_dev), i, error);
|
1999-08-08 15:41:28 +04:00
|
|
|
sc->sc_rxmbuf[i] = m;
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rcvmap[i], 0,
|
|
|
|
sc->sc_rcvmap[i]->dm_mapsize, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We know that the mbuf cluster is page aligned. Also, be sure
|
|
|
|
* that the IP header will be longword aligned.
|
|
|
|
*/
|
|
|
|
m->m_data += 2;
|
|
|
|
rp = &sc->sc_zedata->zc_recv[i];
|
|
|
|
rp->ze_bufsize = (m->m_ext.ext_size - 2);
|
|
|
|
rp->ze_bufaddr = (char *)sc->sc_rcvmap[i]->dm_segs[0].ds_addr + 2;
|
|
|
|
rp->ze_framelen = ZE_FRAMELEN_OW;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a setup packet and put in queue for sending.
|
|
|
|
*/
|
|
|
|
void
|
2008-03-11 08:34:01 +03:00
|
|
|
ze_setup(struct ze_softc *sc)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
struct ze_cdata *zc = sc->sc_zedata;
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
2007-08-27 18:48:54 +04:00
|
|
|
const u_int8_t *enaddr = CLLADDR(ifp->if_sadl);
|
2001-04-15 19:01:35 +04:00
|
|
|
int j, idx, reg;
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
if (sc->sc_inq == (TXDESCS - 1)) {
|
|
|
|
sc->sc_setup = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->sc_setup = 0;
|
|
|
|
/*
|
|
|
|
* Init the setup packet with valid info.
|
|
|
|
*/
|
|
|
|
memset(zc->zc_setup, 0xff, sizeof(zc->zc_setup)); /* Broadcast */
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(zc->zc_setup, enaddr, ETHER_ADDR_LEN);
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
/*
|
2005-02-27 03:26:58 +03:00
|
|
|
* Multicast handling. The SGEC can handle up to 16 direct
|
1999-08-08 15:41:28 +04:00
|
|
|
* ethernet addresses.
|
|
|
|
*/
|
|
|
|
j = 16;
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
|
|
|
|
while (enm != NULL) {
|
2001-07-07 09:35:39 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6)) {
|
1999-08-08 15:41:28 +04:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-07 19:53:13 +04:00
|
|
|
memcpy(&zc->zc_setup[j], enm->enm_addrlo, ETHER_ADDR_LEN);
|
1999-08-08 15:41:28 +04:00
|
|
|
j += 8;
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
if ((enm != NULL)&& (j == 128)) {
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-02 03:32:39 +04:00
|
|
|
/*
|
|
|
|
* ALLMULTI implies PROMISC in this driver.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
ifp->if_flags |= IFF_PROMISC;
|
|
|
|
else if (ifp->if_pcount == 0)
|
|
|
|
ifp->if_flags &= ~IFF_PROMISC;
|
|
|
|
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Fiddle with the receive logic.
|
|
|
|
*/
|
|
|
|
reg = ZE_RCSR(ZE_CSR6);
|
|
|
|
DELAY(10);
|
|
|
|
ZE_WCSR(ZE_CSR6, reg & ~ZE_NICSR6_SR); /* Stop rx */
|
|
|
|
reg &= ~ZE_NICSR6_AF;
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
reg |= ZE_NICSR6_AF_PROM;
|
|
|
|
else if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
reg |= ZE_NICSR6_AF_ALLM;
|
|
|
|
DELAY(10);
|
|
|
|
ZE_WCSR(ZE_CSR6, reg);
|
|
|
|
/*
|
|
|
|
* Only send a setup packet if needed.
|
|
|
|
*/
|
|
|
|
if ((ifp->if_flags & (IFF_PROMISC|IFF_ALLMULTI)) == 0) {
|
|
|
|
idx = sc->sc_nexttx;
|
|
|
|
zc->zc_xmit[idx].ze_tdes1 = ZE_TDES1_DT_SETUP;
|
|
|
|
zc->zc_xmit[idx].ze_bufsize = 128;
|
|
|
|
zc->zc_xmit[idx].ze_bufaddr = sc->sc_pzedata->zc_setup;
|
|
|
|
zc->zc_xmit[idx].ze_tdr = ZE_TDR_OW;
|
|
|
|
|
|
|
|
if ((ZE_RCSR(ZE_CSR5) & ZE_NICSR5_TS) != ZE_NICSR5_TS_RUN)
|
|
|
|
ZE_WCSR(ZE_CSR1, -1);
|
|
|
|
|
|
|
|
sc->sc_inq++;
|
|
|
|
if (++sc->sc_nexttx == TXDESCS)
|
|
|
|
sc->sc_nexttx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for dead transmit logic.
|
|
|
|
*/
|
|
|
|
void
|
2008-03-11 08:34:01 +03:00
|
|
|
zetimeout(struct ifnet *ifp)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
|
|
|
struct ze_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->sc_inq == 0)
|
|
|
|
return;
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error_dev(sc->sc_dev, "xmit logic died, resetting...\n");
|
1999-08-08 15:41:28 +04:00
|
|
|
/*
|
|
|
|
* Do a reset of interface, to get it going again.
|
|
|
|
* Will it work by just restart the transmit logic?
|
|
|
|
*/
|
|
|
|
zeinit(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset chip:
|
|
|
|
* Set/reset the reset flag.
|
|
|
|
* Write interrupt vector.
|
|
|
|
* Write ring buffer addresses.
|
|
|
|
* Write SBR.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
bool
|
|
|
|
zereset(struct ze_softc *sc)
|
1999-08-08 15:41:28 +04:00
|
|
|
{
|
2001-04-15 19:01:35 +04:00
|
|
|
int reg, i;
|
1999-08-08 15:41:28 +04:00
|
|
|
|
|
|
|
ZE_WCSR(ZE_CSR6, ZE_NICSR6_RE);
|
|
|
|
DELAY(50000);
|
|
|
|
if (ZE_RCSR(ZE_CSR6) & ZE_NICSR5_SF) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error_dev(sc->sc_dev, "selftest failed\n");
|
|
|
|
return true;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the vector that were set at match time, and remember it.
|
|
|
|
* WHICH VECTOR TO USE? Take one unused. XXX
|
|
|
|
* Funny way to set vector described in the programmers manual.
|
|
|
|
*/
|
|
|
|
reg = ZE_NICSR0_IPL14 | sc->sc_intvec | 0x1fff0003; /* SYNC/ASYNC??? */
|
|
|
|
i = 10;
|
|
|
|
do {
|
|
|
|
if (i-- == 0) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"failing SGEC CSR0 init\n");
|
|
|
|
return true;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|
|
|
|
ZE_WCSR(ZE_CSR0, reg);
|
|
|
|
} while (ZE_RCSR(ZE_CSR0) != reg);
|
|
|
|
|
|
|
|
ZE_WCSR(ZE_CSR3, (vaddr_t)sc->sc_pzedata->zc_recv);
|
|
|
|
ZE_WCSR(ZE_CSR4, (vaddr_t)sc->sc_pzedata->zc_xmit);
|
2008-03-11 08:34:01 +03:00
|
|
|
return false;
|
1999-08-08 15:41:28 +04:00
|
|
|
}
|