2016-02-09 11:32:07 +03:00
|
|
|
/* $NetBSD: if_qe.c,v 1.74 2016/02/09 08:32:11 ozaki-r Exp $ */
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Copyright (c) 1999 Ludd, University of Lule}, Sweden. All rights reserved.
|
1999-06-06 23:26:44 +04:00
|
|
|
*
|
|
|
|
* 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-26 15:45:06 +03:00
|
|
|
* This product includes software developed at Ludd, University of
|
1999-06-20 04:04:47 +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
|
1999-06-06 23:26:44 +04:00
|
|
|
*
|
1999-06-20 04:04:47 +04:00
|
|
|
* 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.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Driver for DEQNA/DELQA ethernet cards.
|
|
|
|
* Things that is still to do:
|
|
|
|
* Handle ubaresets. Does not work at all right now.
|
|
|
|
* Fix ALLMULTI reception. But someone must tell me how...
|
|
|
|
* Collect statistics.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 10:11:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2016-02-09 11:32:07 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_qe.c,v 1.74 2016/02/09 08:32:11 ozaki-r Exp $");
|
2001-11-13 10:11:12 +03:00
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
#include "opt_inet.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
1999-06-20 04:04:47 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/sockio.h>
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
#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-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
#include <dev/qbus/ubavar.h>
|
|
|
|
#include <dev/qbus/if_qereg.h>
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
#include "ioconf.h"
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
#define RXDESCS 30 /* # of receive descriptors */
|
|
|
|
#define TXDESCS 60 /* # transmit descs */
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Structure containing the elements that must be in DMA-safe memory.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
struct qe_cdata {
|
|
|
|
struct qe_ring qc_recv[RXDESCS+1]; /* Receive descriptors */
|
|
|
|
struct qe_ring qc_xmit[TXDESCS+1]; /* Transmit descriptors */
|
|
|
|
u_int8_t qc_setup[128]; /* Setup packet layout */
|
|
|
|
};
|
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
struct qe_softc {
|
2008-03-11 08:34:01 +03:00
|
|
|
device_t sc_dev; /* Configuration common part */
|
|
|
|
struct uba_softc *sc_uh; /* our parent */
|
2000-06-04 10:16:53 +04:00
|
|
|
struct evcnt sc_intrcnt; /* Interrupt counting */
|
1999-06-20 04:04:47 +04:00
|
|
|
struct ethercom sc_ec; /* Ethernet common part */
|
|
|
|
#define sc_if sc_ec.ec_if /* network-visible interface */
|
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_addr_t sc_ioh;
|
|
|
|
bus_dma_tag_t sc_dmat;
|
|
|
|
struct qe_cdata *sc_qedata; /* Descriptor struct */
|
|
|
|
struct qe_cdata *sc_pqedata; /* Unibus address of above */
|
|
|
|
struct mbuf* sc_txmbuf[TXDESCS];
|
|
|
|
struct mbuf* sc_rxmbuf[RXDESCS];
|
|
|
|
bus_dmamap_t sc_xmtmap[TXDESCS];
|
|
|
|
bus_dmamap_t sc_rcvmap[RXDESCS];
|
2003-01-17 18:45:59 +03:00
|
|
|
bus_dmamap_t sc_nulldmamap; /* ethernet padding buffer */
|
2001-04-27 00:05:46 +04:00
|
|
|
struct ubinfo sc_ui;
|
1999-06-20 04:04:47 +04:00
|
|
|
int sc_intvec; /* Interrupt vector */
|
|
|
|
int sc_nexttx;
|
|
|
|
int sc_inq;
|
|
|
|
int sc_lastack;
|
|
|
|
int sc_nextrx;
|
|
|
|
int sc_setup; /* Setup packet in queue */
|
1999-06-06 23:26:44 +04:00
|
|
|
};
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
static int qematch(device_t, cfdata_t, void *);
|
|
|
|
static void qeattach(device_t, device_t, void *);
|
2001-02-25 16:51:11 +03:00
|
|
|
static void qeinit(struct qe_softc *);
|
|
|
|
static void qestart(struct ifnet *);
|
|
|
|
static void qeintr(void *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int qeioctl(struct ifnet *, u_long, void *);
|
2001-02-25 16:51:11 +03:00
|
|
|
static int qe_add_rxbuf(struct qe_softc *, int);
|
|
|
|
static void qe_setup(struct qe_softc *);
|
|
|
|
static void qetimeout(struct ifnet *);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
CFATTACH_DECL_NEW(qe, sizeof(struct qe_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
qematch, qeattach, NULL, NULL);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
#define QE_WCSR(csr, val) \
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
|
|
|
|
#define QE_RCSR(csr) \
|
|
|
|
bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
#define LOWORD(x) ((int)(x) & 0xffff)
|
|
|
|
#define HIWORD(x) (((int)(x) >> 16) & 0x3f)
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2003-01-17 18:45:59 +03:00
|
|
|
#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
|
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Check for present DEQNA. Done by sending a fake setup packet
|
|
|
|
* and wait for interrupt.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
|
|
|
int
|
2008-03-11 08:34:01 +03:00
|
|
|
qematch(device_t parent, cfdata_t cf, void *aux)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
1999-06-20 04:04:47 +04:00
|
|
|
struct qe_softc ssc;
|
|
|
|
struct qe_softc *sc = &ssc;
|
1999-06-06 23:26:44 +04:00
|
|
|
struct uba_attach_args *ua = aux;
|
2008-03-11 08:34:01 +03:00
|
|
|
struct uba_softc *uh = device_private(parent);
|
2001-04-27 00:05:46 +04:00
|
|
|
struct ubinfo ui;
|
1999-06-20 04:04:47 +04:00
|
|
|
|
2002-06-08 16:28:37 +04:00
|
|
|
#define PROBESIZE 4096
|
|
|
|
struct qe_ring *ring;
|
1999-06-06 23:26:44 +04:00
|
|
|
struct qe_ring *rp;
|
2014-08-18 08:16:59 +04:00
|
|
|
int error, match;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
ring = malloc(PROBESIZE, M_TEMP, M_WAITOK|M_ZERO);
|
2009-03-18 19:00:08 +03:00
|
|
|
memset(sc, 0, sizeof(*sc));
|
1999-06-20 04:04:47 +04:00
|
|
|
sc->sc_iot = ua->ua_iot;
|
|
|
|
sc->sc_ioh = ua->ua_ioh;
|
|
|
|
sc->sc_dmat = ua->ua_dmat;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
uh->uh_lastiv -= 4;
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RESET);
|
2008-03-11 08:34:01 +03:00
|
|
|
QE_WCSR(QE_CSR_VECTOR, uh->uh_lastiv);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
2005-02-26 15:45:06 +03:00
|
|
|
* Map the ring area. Actually this is done only to be able to
|
1999-06-20 04:04:47 +04:00
|
|
|
* send and receive a internal packet; some junk is loopbacked
|
|
|
|
* so that the DEQNA has a reason to interrupt.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
2001-04-27 00:05:46 +04:00
|
|
|
ui.ui_size = PROBESIZE;
|
2007-03-04 08:59:00 +03:00
|
|
|
ui.ui_vaddr = (void *)&ring[0];
|
2014-08-18 08:16:59 +04:00
|
|
|
if ((error = uballoc(uh, &ui, UBA_CANTWAIT))) {
|
|
|
|
match = 0;
|
|
|
|
goto out0;
|
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Init a simple "fake" receive and transmit descriptor that
|
|
|
|
* points to some unused area. Send a fake setup packet.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
2001-04-27 00:05:46 +04:00
|
|
|
rp = (void *)ui.ui_baddr;
|
1999-06-20 04:04:47 +04:00
|
|
|
ring[0].qe_flag = ring[0].qe_status1 = QE_NOTYET;
|
|
|
|
ring[0].qe_addr_lo = LOWORD(&rp[4]);
|
|
|
|
ring[0].qe_addr_hi = HIWORD(&rp[4]) | QE_VALID | QE_EOMSG | QE_SETUP;
|
2002-06-08 16:28:37 +04:00
|
|
|
ring[0].qe_buf_len = -64;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
ring[2].qe_flag = ring[2].qe_status1 = QE_NOTYET;
|
|
|
|
ring[2].qe_addr_lo = LOWORD(&rp[4]);
|
|
|
|
ring[2].qe_addr_hi = HIWORD(&rp[4]) | QE_VALID;
|
2002-06-08 16:28:37 +04:00
|
|
|
ring[2].qe_buf_len = -(1500/2);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RCSR(QE_CSR_CSR) & ~QE_RESET);
|
|
|
|
DELAY(1000);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the interface and wait for the packet.
|
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_INT_ENABLE|QE_XMIT_INT|QE_RCV_INT);
|
|
|
|
QE_WCSR(QE_CSR_RCLL, LOWORD(&rp[2]));
|
|
|
|
QE_WCSR(QE_CSR_RCLH, HIWORD(&rp[2]));
|
|
|
|
QE_WCSR(QE_CSR_XMTL, LOWORD(rp));
|
|
|
|
QE_WCSR(QE_CSR_XMTH, HIWORD(rp));
|
1999-06-06 23:26:44 +04:00
|
|
|
DELAY(10000);
|
1999-06-20 04:04:47 +04:00
|
|
|
|
2014-08-18 08:16:59 +04:00
|
|
|
match = 1;
|
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
|
|
|
* All done with the bus resources.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
ubfree(uh, &ui);
|
2014-08-18 08:16:59 +04:00
|
|
|
out0: free(ring, M_TEMP);
|
|
|
|
return match;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
qeattach(device_t parent, device_t self, void *aux)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
2008-03-11 08:34:01 +03:00
|
|
|
struct uba_attach_args *ua = aux;
|
|
|
|
struct qe_softc *sc = device_private(self);
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct qe_ring *rp;
|
1999-06-20 04:04:47 +04:00
|
|
|
u_int8_t enaddr[ETHER_ADDR_LEN];
|
2001-04-27 00:05:46 +04:00
|
|
|
int i, error;
|
2003-01-17 18:45:59 +03:00
|
|
|
char *nullbuf;
|
1999-06-20 04:04:47 +04:00
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
sc->sc_dev = self;
|
|
|
|
sc->sc_uh = device_private(parent);
|
1999-06-20 04:04:47 +04:00
|
|
|
sc->sc_iot = ua->ua_iot;
|
|
|
|
sc->sc_ioh = ua->ua_ioh;
|
|
|
|
sc->sc_dmat = ua->ua_dmat;
|
|
|
|
|
2005-02-26 15:45:06 +03:00
|
|
|
/*
|
|
|
|
* Allocate DMA safe memory for descriptors and setup memory.
|
|
|
|
*/
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2003-01-17 18:45:59 +03:00
|
|
|
sc->sc_ui.ui_size = sizeof(struct qe_cdata) + ETHER_PAD_LEN;
|
2008-03-11 08:34:01 +03:00
|
|
|
if ((error = ubmemalloc(sc->sc_uh, &sc->sc_ui, 0))) {
|
|
|
|
aprint_error(": unable to ubmemalloc(), error = %d\n", error);
|
2001-04-27 00:05:46 +04:00
|
|
|
return;
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
2001-04-27 00:05:46 +04:00
|
|
|
sc->sc_pqedata = (struct qe_cdata *)sc->sc_ui.ui_baddr;
|
|
|
|
sc->sc_qedata = (struct qe_cdata *)sc->sc_ui.ui_vaddr;
|
1999-06-20 04:04:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero the newly allocated memory.
|
|
|
|
*/
|
2009-03-18 19:00:08 +03:00
|
|
|
memset(sc->sc_qedata, 0, sizeof(struct qe_cdata) + ETHER_PAD_LEN);
|
2003-01-17 18:45:59 +03:00
|
|
|
nullbuf = ((char*)sc->sc_qedata) + sizeof(struct qe_cdata);
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Create the transmit descriptor DMA maps. We take advantage
|
2005-02-26 15:45:06 +03:00
|
|
|
* of the fact that the Qbus address space is big, and therefore
|
1999-06-20 04:04:47 +04:00
|
|
|
* allocate map registers for all transmit descriptors also,
|
|
|
|
* so that we can avoid this each time we send a packet.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
for (i = 0; i < TXDESCS; i++) {
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
|
|
|
|
1, MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
|
|
|
|
&sc->sc_xmtmap[i]))) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error(
|
|
|
|
": unable to create tx DMA map %d, error = %d\n",
|
1999-06-20 04:04:47 +04:00
|
|
|
i, error);
|
|
|
|
goto fail_4;
|
|
|
|
}
|
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Create receive buffer DMA maps.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
|
|
|
|
MCLBYTES, 0, BUS_DMA_NOWAIT,
|
|
|
|
&sc->sc_rcvmap[i]))) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error(
|
|
|
|
": unable to create rx DMA map %d, error = %d\n",
|
1999-06-20 04:04:47 +04:00
|
|
|
i, error);
|
|
|
|
goto fail_5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Pre-allocate the receive buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
|
|
|
if ((error = qe_add_rxbuf(sc, i)) != 0) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error(
|
|
|
|
": unable to allocate or map rx buffer %d,"
|
1999-06-20 04:04:47 +04:00
|
|
|
" error = %d\n", i, error);
|
|
|
|
goto fail_6;
|
|
|
|
}
|
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2003-01-17 18:45:59 +03:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, ETHER_PAD_LEN, 1,
|
|
|
|
ETHER_PAD_LEN, 0, BUS_DMA_NOWAIT,&sc->sc_nulldmamap)) != 0) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error(
|
|
|
|
": unable to create pad buffer DMA map, error = %d\n",
|
|
|
|
error);
|
2003-01-17 18:45:59 +03:00
|
|
|
goto fail_6;
|
|
|
|
}
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_nulldmamap,
|
|
|
|
nullbuf, ETHER_PAD_LEN, NULL, BUS_DMA_NOWAIT)) != 0) {
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_error(
|
|
|
|
": unable to load pad buffer DMA map, error = %d\n",
|
|
|
|
error);
|
2003-01-17 18:45:59 +03:00
|
|
|
goto fail_7;
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_nulldmamap, 0, ETHER_PAD_LEN,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Create ring loops of the buffer chains.
|
|
|
|
* This is only done once.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
rp = sc->sc_qedata->qc_recv;
|
|
|
|
rp[RXDESCS].qe_addr_lo = LOWORD(&sc->sc_pqedata->qc_recv[0]);
|
|
|
|
rp[RXDESCS].qe_addr_hi = HIWORD(&sc->sc_pqedata->qc_recv[0]) |
|
|
|
|
QE_VALID | QE_CHAIN;
|
|
|
|
rp[RXDESCS].qe_flag = rp[RXDESCS].qe_status1 = QE_NOTYET;
|
|
|
|
|
|
|
|
rp = sc->sc_qedata->qc_xmit;
|
|
|
|
rp[TXDESCS].qe_addr_lo = LOWORD(&sc->sc_pqedata->qc_xmit[0]);
|
|
|
|
rp[TXDESCS].qe_addr_hi = HIWORD(&sc->sc_pqedata->qc_xmit[0]) |
|
|
|
|
QE_VALID | QE_CHAIN;
|
|
|
|
rp[TXDESCS].qe_flag = rp[TXDESCS].qe_status1 = QE_NOTYET;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the vector that were set at match time, and remember it.
|
|
|
|
*/
|
2008-03-11 08:34:01 +03:00
|
|
|
sc->sc_intvec = sc->sc_uh->uh_lastiv;
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RESET);
|
|
|
|
DELAY(1000);
|
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RCSR(QE_CSR_CSR) & ~QE_RESET);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read out ethernet address and tell which type this card is.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
enaddr[i] = QE_RCSR(i * 2) & 0xff;
|
|
|
|
|
|
|
|
QE_WCSR(QE_CSR_VECTOR, sc->sc_intvec | 1);
|
2008-03-11 08:34:01 +03:00
|
|
|
aprint_normal(": %s, hardware address %s\n",
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_RCSR(QE_CSR_VECTOR) & 1 ? "delqa":"deqna",
|
|
|
|
ether_sprintf(enaddr));
|
|
|
|
|
|
|
|
QE_WCSR(QE_CSR_VECTOR, QE_RCSR(QE_CSR_VECTOR) & ~1); /* ??? */
|
|
|
|
|
2000-06-04 10:16:53 +04:00
|
|
|
uba_intr_establish(ua->ua_icookie, ua->ua_cvec, qeintr,
|
|
|
|
sc, &sc->sc_intrcnt);
|
2000-06-05 04:09:17 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
|
2008-03-11 08:34:01 +03:00
|
|
|
device_xname(sc->sc_dev), "intr");
|
2000-01-24 05:40:28 +03:00
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
strcpy(ifp->if_xname, device_xname(sc->sc_dev));
|
1999-06-20 04:04:47 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
1999-06-06 23:26:44 +04:00
|
|
|
ifp->if_start = qestart;
|
|
|
|
ifp->if_ioctl = qeioctl;
|
1999-08-01 19:25:41 +04:00
|
|
|
ifp->if_watchdog = qetimeout;
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1999-06-20 04:04:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface.
|
|
|
|
*/
|
1999-06-06 23:26:44 +04:00
|
|
|
if_attach(ifp);
|
1999-06-20 04:04:47 +04:00
|
|
|
ether_ifattach(ifp, enaddr);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
return;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* Free any resources we've allocated during the failed attach
|
|
|
|
* attempt. Do this in reverse order and fall through.
|
|
|
|
*/
|
2003-01-17 18:45:59 +03:00
|
|
|
fail_7:
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_nulldmamap);
|
1999-06-20 04:04:47 +04:00
|
|
|
fail_6:
|
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
|
|
|
if (sc->sc_rxmbuf[i] != NULL) {
|
2003-01-17 18:45:59 +03:00
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
|
1999-06-20 04:04:47 +04:00
|
|
|
m_freem(sc->sc_rxmbuf[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail_5:
|
|
|
|
for (i = 0; i < RXDESCS; i++) {
|
2013-10-25 19:42:50 +04:00
|
|
|
if (sc->sc_rcvmap[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_rcvmap[i]);
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
|
|
|
fail_4:
|
|
|
|
for (i = 0; i < TXDESCS; i++) {
|
2013-10-25 19:42:50 +04:00
|
|
|
if (sc->sc_xmtmap[i] != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_xmtmap[i]);
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface.
|
|
|
|
*/
|
|
|
|
void
|
2001-02-25 16:51:11 +03:00
|
|
|
qeinit(struct qe_softc *sc)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
1999-06-20 04:04:47 +04:00
|
|
|
struct ifnet *ifp = (struct ifnet *)&sc->sc_if;
|
|
|
|
struct qe_cdata *qc = sc->sc_qedata;
|
1999-06-06 23:26:44 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Reset the interface.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RESET);
|
|
|
|
DELAY(1000);
|
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RCSR(QE_CSR_CSR) & ~QE_RESET);
|
|
|
|
QE_WCSR(QE_CSR_VECTOR, sc->sc_intvec);
|
|
|
|
|
|
|
|
sc->sc_nexttx = sc->sc_inq = sc->sc_lastack = 0;
|
|
|
|
/*
|
|
|
|
* Release and init transmit descriptors.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < TXDESCS; i++) {
|
|
|
|
if (sc->sc_txmbuf[i]) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_xmtmap[i]);
|
|
|
|
m_freem(sc->sc_txmbuf[i]);
|
|
|
|
sc->sc_txmbuf[i] = 0;
|
|
|
|
}
|
|
|
|
qc->qc_xmit[i].qe_addr_hi = 0; /* Clear valid bit */
|
|
|
|
qc->qc_xmit[i].qe_status1 = qc->qc_xmit[i].qe_flag = QE_NOTYET;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* Init receive descriptors.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < RXDESCS; i++)
|
|
|
|
qc->qc_recv[i].qe_status1 = qc->qc_recv[i].qe_flag = QE_NOTYET;
|
|
|
|
sc->sc_nextrx = 0;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* Write the descriptor addresses to the device.
|
|
|
|
* Receiving packets will be enabled in the interrupt routine.
|
|
|
|
*/
|
|
|
|
QE_WCSR(QE_CSR_CSR, QE_INT_ENABLE|QE_XMIT_INT|QE_RCV_INT);
|
|
|
|
QE_WCSR(QE_CSR_RCLL, LOWORD(sc->sc_pqedata->qc_recv));
|
|
|
|
QE_WCSR(QE_CSR_RCLH, HIWORD(sc->sc_pqedata->qc_recv));
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Send a setup frame.
|
|
|
|
* This will start the transmit machinery as well.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
qe_setup(sc);
|
|
|
|
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface.
|
|
|
|
*/
|
|
|
|
void
|
2001-02-25 16:51:11 +03:00
|
|
|
qestart(struct ifnet *ifp)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
1999-06-20 04:04:47 +04:00
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
|
|
|
struct qe_cdata *qc = sc->sc_qedata;
|
|
|
|
paddr_t buffer;
|
|
|
|
struct mbuf *m, *m0;
|
2013-10-25 19:42:50 +04:00
|
|
|
int idx, len, s, i, totlen, buflen;
|
2001-02-25 16:51:11 +03:00
|
|
|
short orword, csr;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
if ((QE_RCSR(QE_CSR_CSR) & QE_RCV_ENABLE) == 0)
|
|
|
|
return;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
2001-04-13 00:04:24 +04:00
|
|
|
s = splnet();
|
1999-06-20 04:04:47 +04:00
|
|
|
while (sc->sc_inq < (TXDESCS - 1)) {
|
|
|
|
|
|
|
|
if (sc->sc_setup) {
|
|
|
|
qe_setup(sc);
|
|
|
|
continue;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
1999-06-20 04:04:47 +04:00
|
|
|
idx = sc->sc_nexttx;
|
2000-12-14 10:15:45 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m);
|
1999-06-20 04:04:47 +04:00
|
|
|
if (m == 0)
|
|
|
|
goto out;
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Count number of mbufs in chain.
|
|
|
|
* Always do DMA directly from mbufs, therefore the transmit
|
|
|
|
* ring is really big.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
for (m0 = m, i = 0; m0; m0 = m0->m_next)
|
1999-08-01 19:25:41 +04:00
|
|
|
if (m0->m_len)
|
|
|
|
i++;
|
2003-01-17 18:45:59 +03:00
|
|
|
if (m->m_pkthdr.len < ETHER_PAD_LEN) {
|
|
|
|
buflen = ETHER_PAD_LEN;
|
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
buflen = m->m_pkthdr.len;
|
1999-06-20 04:04:47 +04:00
|
|
|
if (i >= TXDESCS)
|
|
|
|
panic("qestart");
|
|
|
|
|
|
|
|
if ((i + sc->sc_inq) >= (TXDESCS - 1)) {
|
1999-08-01 19:25:41 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
1999-06-20 04:04:47 +04:00
|
|
|
goto out;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
2000-12-14 10:15:45 +03:00
|
|
|
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1999-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* m now points to a mbuf chain that can be loaded.
|
|
|
|
* Loop around and set it.
|
|
|
|
*/
|
1999-08-01 19:25:41 +04:00
|
|
|
totlen = 0;
|
2003-01-17 18:45:59 +03:00
|
|
|
for (m0 = m; ; m0 = m0->m_next) {
|
|
|
|
if (m0) {
|
|
|
|
if (m0->m_len == 0)
|
|
|
|
continue;
|
2013-10-25 19:42:50 +04:00
|
|
|
bus_dmamap_load(sc->sc_dmat,
|
2003-01-17 18:45:59 +03:00
|
|
|
sc->sc_xmtmap[idx], mtod(m0, void *),
|
|
|
|
m0->m_len, 0, 0);
|
|
|
|
buffer = sc->sc_xmtmap[idx]->dm_segs[0].ds_addr;
|
|
|
|
len = m0->m_len;
|
|
|
|
} else if (totlen < ETHER_PAD_LEN) {
|
|
|
|
buffer = sc->sc_nulldmamap->dm_segs[0].ds_addr;
|
|
|
|
len = ETHER_PAD_LEN - totlen;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
1999-06-20 04:04:47 +04:00
|
|
|
|
1999-08-01 19:25:41 +04:00
|
|
|
totlen += len;
|
1999-06-20 04:04:47 +04:00
|
|
|
/* Word alignment calc */
|
|
|
|
orword = 0;
|
2003-01-17 18:45:59 +03:00
|
|
|
if (totlen == buflen) {
|
1999-06-20 04:04:47 +04:00
|
|
|
orword |= QE_EOMSG;
|
1999-08-01 19:25:41 +04:00
|
|
|
sc->sc_txmbuf[idx] = m;
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
|
|
|
if ((buffer & 1) || (len & 1))
|
|
|
|
len += 2;
|
|
|
|
if (buffer & 1)
|
|
|
|
orword |= QE_ODDBEGIN;
|
|
|
|
if ((buffer + len) & 1)
|
|
|
|
orword |= QE_ODDEND;
|
|
|
|
qc->qc_xmit[idx].qe_buf_len = -(len/2);
|
|
|
|
qc->qc_xmit[idx].qe_addr_lo = LOWORD(buffer);
|
|
|
|
qc->qc_xmit[idx].qe_addr_hi = HIWORD(buffer);
|
|
|
|
qc->qc_xmit[idx].qe_flag =
|
|
|
|
qc->qc_xmit[idx].qe_status1 = QE_NOTYET;
|
|
|
|
qc->qc_xmit[idx].qe_addr_hi |= (QE_VALID | orword);
|
|
|
|
if (++idx == TXDESCS)
|
|
|
|
idx = 0;
|
|
|
|
sc->sc_inq++;
|
2003-01-17 18:45:59 +03:00
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
1999-08-01 19:25:41 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2003-01-17 18:45:59 +03:00
|
|
|
if (totlen != buflen)
|
1999-08-01 19:25:41 +04:00
|
|
|
panic("qestart: len fault");
|
|
|
|
#endif
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Kick off the transmit logic, if it is stopped.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
2001-02-25 16:51:11 +03:00
|
|
|
csr = QE_RCSR(QE_CSR_CSR);
|
|
|
|
if (csr & QE_XL_INVALID) {
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_XMTL,
|
|
|
|
LOWORD(&sc->sc_pqedata->qc_xmit[sc->sc_nexttx]));
|
|
|
|
QE_WCSR(QE_CSR_XMTH,
|
|
|
|
HIWORD(&sc->sc_pqedata->qc_xmit[sc->sc_nexttx]));
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
1999-06-20 04:04:47 +04:00
|
|
|
sc->sc_nexttx = idx;
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
1999-06-20 04:04:47 +04:00
|
|
|
if (sc->sc_inq == (TXDESCS - 1))
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
1999-08-01 19:25:41 +04:00
|
|
|
|
|
|
|
out: if (sc->sc_inq)
|
|
|
|
ifp->if_timer = 5; /* If transmit logic dies */
|
|
|
|
splx(s);
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
2000-01-24 05:40:28 +03:00
|
|
|
static void
|
2001-02-25 16:51:11 +03:00
|
|
|
qeintr(void *arg)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
2000-01-24 05:40:28 +03:00
|
|
|
struct qe_softc *sc = arg;
|
1999-06-20 04:04:47 +04:00
|
|
|
struct qe_cdata *qc = sc->sc_qedata;
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
int csr, status1, status2, len;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
csr = QE_RCSR(QE_CSR_CSR);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
QE_WCSR(QE_CSR_CSR, QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT |
|
|
|
|
QE_RCV_INT | QE_ILOOP);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
if (csr & QE_RCV_INT)
|
|
|
|
while (qc->qc_recv[sc->sc_nextrx].qe_status1 != QE_NOTYET) {
|
|
|
|
status1 = qc->qc_recv[sc->sc_nextrx].qe_status1;
|
|
|
|
status2 = qc->qc_recv[sc->sc_nextrx].qe_status2;
|
2001-02-25 16:51:11 +03:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
m = sc->sc_rxmbuf[sc->sc_nextrx];
|
|
|
|
len = ((status1 & QE_RBL_HI) |
|
|
|
|
(status2 & QE_RBL_LO)) + 60;
|
|
|
|
qe_add_rxbuf(sc, sc->sc_nextrx);
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
|
|
|
if (++sc->sc_nextrx == RXDESCS)
|
|
|
|
sc->sc_nextrx = 0;
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
2001-02-25 16:51:11 +03:00
|
|
|
if ((status1 & QE_ESETUP) == 0)
|
2016-02-09 11:32:07 +03:00
|
|
|
if_percpuq_enqueue(ifp->if_percpuq, m);
|
2001-02-25 16:51:11 +03:00
|
|
|
else
|
|
|
|
m_freem(m);
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
2001-02-25 16:51:11 +03:00
|
|
|
if (csr & (QE_XMIT_INT|QE_XL_INVALID)) {
|
1999-06-20 04:04:47 +04:00
|
|
|
while (qc->qc_xmit[sc->sc_lastack].qe_status1 != QE_NOTYET) {
|
|
|
|
int idx = sc->sc_lastack;
|
|
|
|
|
|
|
|
sc->sc_inq--;
|
|
|
|
if (++sc->sc_lastack == TXDESCS)
|
|
|
|
sc->sc_lastack = 0;
|
|
|
|
|
|
|
|
/* XXX collect statistics */
|
|
|
|
qc->qc_xmit[idx].qe_addr_hi &= ~QE_VALID;
|
|
|
|
qc->qc_xmit[idx].qe_status1 =
|
|
|
|
qc->qc_xmit[idx].qe_flag = QE_NOTYET;
|
|
|
|
|
|
|
|
if (qc->qc_xmit[idx].qe_addr_hi & QE_SETUP)
|
|
|
|
continue;
|
2003-01-17 18:45:59 +03:00
|
|
|
if (sc->sc_txmbuf[idx] == NULL ||
|
|
|
|
sc->sc_txmbuf[idx]->m_pkthdr.len < ETHER_PAD_LEN)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat,
|
|
|
|
sc->sc_xmtmap[idx]);
|
1999-06-20 04:04:47 +04:00
|
|
|
if (sc->sc_txmbuf[idx]) {
|
|
|
|
m_freem(sc->sc_txmbuf[idx]);
|
2003-01-17 18:45:59 +03:00
|
|
|
sc->sc_txmbuf[idx] = NULL;
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
|
|
|
}
|
1999-08-01 19:25:41 +04:00
|
|
|
ifp->if_timer = 0;
|
1999-06-20 04:04:47 +04:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
qestart(ifp); /* Put in more in queue */
|
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* How can the receive list get invalid???
|
|
|
|
* Verified that it happens anyway.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
if ((qc->qc_recv[sc->sc_nextrx].qe_status1 == QE_NOTYET) &&
|
|
|
|
(QE_RCSR(QE_CSR_CSR) & QE_RL_INVALID)) {
|
|
|
|
QE_WCSR(QE_CSR_RCLL,
|
|
|
|
LOWORD(&sc->sc_pqedata->qc_recv[sc->sc_nextrx]));
|
|
|
|
QE_WCSR(QE_CSR_RCLH,
|
|
|
|
HIWORD(&sc->sc_pqedata->qc_recv[sc->sc_nextrx]));
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
qeioctl(struct ifnet *ifp, u_long cmd, void *data)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
|
|
|
struct qe_softc *sc = ifp->if_softc;
|
1999-06-20 04:04:47 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1999-06-06 23:26:44 +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-06-06 23:26:44 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1999-06-20 04:04:47 +04:00
|
|
|
qeinit(sc);
|
1999-06-06 23:26:44 +04:00
|
|
|
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-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running,
|
|
|
|
* stop it. (by disabling receive mechanism).
|
|
|
|
*/
|
|
|
|
QE_WCSR(QE_CSR_CSR,
|
|
|
|
QE_RCSR(QE_CSR_CSR) & ~QE_RCV_ENABLE);
|
|
|
|
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-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* If interface it marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
1999-06-06 23:26:44 +04:00
|
|
|
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;
|
|
|
|
case IFF_UP|IFF_RUNNING:
|
1999-06-20 04:04:47 +04:00
|
|
|
/*
|
|
|
|
* Send a new setup packet to match any new changes.
|
|
|
|
* (Like IFF_PROMISC etc)
|
|
|
|
*/
|
|
|
|
qe_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-06-20 04:04:47 +04:00
|
|
|
}
|
1999-06-06 23:26:44 +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-06-06 23:26:44 +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)
|
|
|
|
qe_setup(sc);
|
1999-06-06 23:26:44 +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-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Add a receive buffer to the indicated descriptor.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
int
|
2005-02-26 15:45:06 +03:00
|
|
|
qe_add_rxbuf(struct qe_softc *sc, int i)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
1999-06-20 04:04:47 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct qe_ring *rp;
|
|
|
|
vaddr_t addr;
|
|
|
|
int error;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
if (sc->sc_rxmbuf[i] != NULL)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
error = bus_dmamap_load(sc->sc_dmat, sc->sc_rcvmap[i],
|
|
|
|
m->m_ext.ext_buf, m->m_ext.ext_size, NULL, BUS_DMA_NOWAIT);
|
|
|
|
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-06-20 04:04:47 +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);
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* We know that the mbuf cluster is page aligned. Also, be sure
|
|
|
|
* that the IP header will be longword aligned.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
m->m_data += 2;
|
|
|
|
addr = sc->sc_rcvmap[i]->dm_segs[0].ds_addr + 2;
|
|
|
|
rp = &sc->sc_qedata->qc_recv[i];
|
|
|
|
rp->qe_flag = rp->qe_status1 = QE_NOTYET;
|
|
|
|
rp->qe_addr_lo = LOWORD(addr);
|
|
|
|
rp->qe_addr_hi = HIWORD(addr) | QE_VALID;
|
|
|
|
rp->qe_buf_len = -(m->m_ext.ext_size - 2)/2;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
return (0);
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Create a setup packet and put in queue for sending.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
|
|
|
void
|
2001-02-25 16:51:11 +03:00
|
|
|
qe_setup(struct qe_softc *sc)
|
1999-06-06 23:26:44 +04:00
|
|
|
{
|
1999-06-20 04:04:47 +04:00
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
struct qe_cdata *qc = sc->sc_qedata;
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
2007-12-22 11:23:01 +03:00
|
|
|
u_int8_t enaddr[ETHER_ADDR_LEN];
|
1999-06-20 04:04:47 +04:00
|
|
|
int i, j, k, idx, s;
|
|
|
|
|
2001-04-13 00:04:24 +04:00
|
|
|
s = splnet();
|
1999-06-20 04:04:47 +04:00
|
|
|
if (sc->sc_inq == (TXDESCS - 1)) {
|
|
|
|
sc->sc_setup = 1;
|
|
|
|
splx(s);
|
1999-06-06 23:26:44 +04:00
|
|
|
return;
|
1999-06-20 04:04:47 +04:00
|
|
|
}
|
|
|
|
sc->sc_setup = 0;
|
1999-06-06 23:26:44 +04:00
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* Init the setup packet with valid info.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
memset(qc->qc_setup, 0xff, sizeof(qc->qc_setup)); /* Broadcast */
|
2007-12-22 11:23:01 +03:00
|
|
|
memcpy(enaddr, CLLADDR(ifp->if_sadl), sizeof(enaddr));
|
1999-06-20 04:04:47 +04:00
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
qc->qc_setup[i * 8 + 1] = enaddr[i]; /* Own address */
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
2005-02-26 15:45:06 +03:00
|
|
|
* Multicast handling. The DEQNA can handle up to 12 direct
|
1999-06-20 04:04:47 +04:00
|
|
|
* ethernet addresses.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
1999-06-20 04:04:47 +04:00
|
|
|
j = 3; k = 0;
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
|
|
|
|
while (enm != NULL) {
|
2002-05-22 20:03:14 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6)) {
|
1999-06-20 04:04:47 +04:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
|
|
|
qc->qc_setup[i * 8 + j + k] = enm->enm_addrlo[i];
|
|
|
|
j++;
|
|
|
|
if (j == 8) {
|
|
|
|
j = 1; k += 64;
|
|
|
|
}
|
|
|
|
if (k > 64) {
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
idx = sc->sc_nexttx;
|
|
|
|
qc->qc_xmit[idx].qe_buf_len = -64;
|
1999-06-06 23:26:44 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-20 04:04:47 +04:00
|
|
|
* How is the DEQNA turned in ALLMULTI mode???
|
|
|
|
* Until someone tells me, fall back to PROMISC when more than
|
|
|
|
* 12 ethernet addresses.
|
1999-06-06 23:26:44 +04:00
|
|
|
*/
|
2000-10-02 03:32:39 +04:00
|
|
|
if (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
ifp->if_flags |= IFF_PROMISC;
|
|
|
|
else if (ifp->if_pcount == 0)
|
|
|
|
ifp->if_flags &= ~IFF_PROMISC;
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
1999-06-20 04:04:47 +04:00
|
|
|
qc->qc_xmit[idx].qe_buf_len = -65;
|
|
|
|
|
|
|
|
qc->qc_xmit[idx].qe_addr_lo = LOWORD(sc->sc_pqedata->qc_setup);
|
|
|
|
qc->qc_xmit[idx].qe_addr_hi =
|
|
|
|
HIWORD(sc->sc_pqedata->qc_setup) | QE_SETUP | QE_EOMSG;
|
|
|
|
qc->qc_xmit[idx].qe_status1 = qc->qc_xmit[idx].qe_flag = QE_NOTYET;
|
|
|
|
qc->qc_xmit[idx].qe_addr_hi |= QE_VALID;
|
|
|
|
|
|
|
|
if (QE_RCSR(QE_CSR_CSR) & QE_XL_INVALID) {
|
|
|
|
QE_WCSR(QE_CSR_XMTL,
|
|
|
|
LOWORD(&sc->sc_pqedata->qc_xmit[idx]));
|
|
|
|
QE_WCSR(QE_CSR_XMTH,
|
|
|
|
HIWORD(&sc->sc_pqedata->qc_xmit[idx]));
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
|
|
|
|
1999-06-20 04:04:47 +04:00
|
|
|
sc->sc_inq++;
|
|
|
|
if (++sc->sc_nexttx == TXDESCS)
|
|
|
|
sc->sc_nexttx = 0;
|
|
|
|
splx(s);
|
1999-06-06 23:26:44 +04:00
|
|
|
}
|
1999-08-01 19:25:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for dead transmit logic. Not uncommon.
|
|
|
|
*/
|
|
|
|
void
|
2001-02-25 16:51:11 +03:00
|
|
|
qetimeout(struct ifnet *ifp)
|
1999-08-01 19:25:41 +04:00
|
|
|
{
|
|
|
|
struct qe_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-01 19:25:41 +04:00
|
|
|
/*
|
|
|
|
* Do a reset of interface, to get it going again.
|
|
|
|
* Will it work by just restart the transmit logic?
|
|
|
|
*/
|
|
|
|
qeinit(sc);
|
|
|
|
}
|