2013-10-25 19:11:32 +04:00
|
|
|
/* $NetBSD: if_ni.c,v 1.41 2013/10/25 15:11:32 martin Exp $ */
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 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
|
2000-04-09 20:49:57 +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 DEBNA/DEBNT/DEBNK ethernet cards.
|
|
|
|
* Things that is still to do:
|
|
|
|
* Collect statistics.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 15:51:12 +03:00
|
|
|
#include <sys/cdefs.h>
|
2013-10-25 19:11:32 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_ni.c,v 1.41 2013/10/25 15:11:32 martin Exp $");
|
2001-11-13 15:51:12 +03:00
|
|
|
|
2000-04-09 20:49:57 +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>
|
2001-06-03 19:15:02 +04:00
|
|
|
#include <sys/sched.h>
|
2000-04-09 20:49:57 +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>
|
2000-04-09 20:49:57 +04:00
|
|
|
#ifdef __vax__
|
|
|
|
#include <machine/mtpr.h>
|
|
|
|
#include <machine/pte.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dev/bi/bireg.h>
|
|
|
|
#include <dev/bi/bivar.h>
|
|
|
|
|
|
|
|
#include "ioconf.h"
|
|
|
|
#include "locators.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tunable buffer parameters. Good idea to have them as power of 8; then
|
|
|
|
* they will fit into a logical VAX page.
|
|
|
|
*/
|
|
|
|
#define NMSGBUF 8 /* Message queue entries */
|
|
|
|
#define NTXBUF 16 /* Transmit queue entries */
|
|
|
|
#define NTXFRAGS 8 /* Number of transmit buffer fragments */
|
|
|
|
#define NRXBUF 24 /* Receive queue entries */
|
|
|
|
#define NBDESCS (NTXBUF * NTXFRAGS + NRXBUF)
|
|
|
|
#define NQUEUES 3 /* RX + TX + MSG */
|
|
|
|
#define PKTHDR 18 /* Length of (control) packet header */
|
|
|
|
#define RXADD 18 /* Additional length of receive datagram */
|
|
|
|
#define TXADD (10+NTXFRAGS*8) /* "" transmit "" */
|
|
|
|
#define MSGADD 134 /* "" message "" */
|
|
|
|
|
|
|
|
#include <dev/bi/if_nireg.h> /* XXX include earlier */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for (most cases of) insqti/remqhi.
|
|
|
|
* Retry NRETRIES times to do the operation, if it still fails assume
|
|
|
|
* a lost lock and panic.
|
|
|
|
*/
|
|
|
|
#define NRETRIES 100
|
|
|
|
#define INSQTI(e, h) ({ \
|
2005-06-27 15:05:24 +04:00
|
|
|
int ret = 0, __i; \
|
|
|
|
for (__i = 0; __i < NRETRIES; __i++) { \
|
2000-04-09 20:49:57 +04:00
|
|
|
if ((ret = insqti(e, h)) != ILCK_FAILED) \
|
|
|
|
break; \
|
|
|
|
} \
|
2005-06-27 15:05:24 +04:00
|
|
|
if (__i == NRETRIES) \
|
2000-04-09 20:49:57 +04:00
|
|
|
panic("ni: insqti failed at %d", __LINE__); \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
#define REMQHI(h) ({ \
|
2005-06-27 15:05:24 +04:00
|
|
|
int __i; void *ret = NULL; \
|
|
|
|
for (__i = 0; __i < NRETRIES; __i++) { \
|
2000-04-09 20:49:57 +04:00
|
|
|
if ((ret = remqhi(h)) != (void *)ILCK_FAILED) \
|
|
|
|
break; \
|
|
|
|
} \
|
2005-06-27 15:05:24 +04:00
|
|
|
if (__i == NRETRIES) \
|
2000-04-09 20:49:57 +04:00
|
|
|
panic("ni: remqhi failed at %d", __LINE__); \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define nipqb (&sc->sc_gvppqb->nc_pqb)
|
|
|
|
#define gvp sc->sc_gvppqb
|
|
|
|
#define fqb sc->sc_fqb
|
|
|
|
#define bbd sc->sc_bbd
|
|
|
|
|
|
|
|
struct ni_softc {
|
2008-07-09 21:51:21 +04:00
|
|
|
device_t sc_dev; /* Configuration common part */
|
2000-06-04 10:16:53 +04:00
|
|
|
struct evcnt sc_intrcnt; /* Interrupt coounting */
|
2000-04-09 20:49:57 +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 ni_gvppqb *sc_gvppqb; /* Port queue block */
|
|
|
|
struct ni_gvppqb *sc_pgvppqb; /* Phys address of PQB */
|
|
|
|
struct ni_fqb *sc_fqb; /* Free Queue block */
|
|
|
|
struct ni_bbd *sc_bbd; /* Buffer descriptors */
|
|
|
|
u_int8_t sc_enaddr[ETHER_ADDR_LEN];
|
|
|
|
};
|
|
|
|
|
2008-03-11 08:34:01 +03:00
|
|
|
static int nimatch(device_t, cfdata_t, void *);
|
|
|
|
static void niattach(device_t, device_t, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
static void niinit(struct ni_softc *);
|
|
|
|
static void nistart(struct ifnet *);
|
|
|
|
static void niintr(void *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int niioctl(struct ifnet *, u_long, void *);
|
2000-04-09 20:49:57 +04:00
|
|
|
static int ni_add_rxbuf(struct ni_softc *, struct ni_dg *, int);
|
2005-02-04 05:10:35 +03:00
|
|
|
static void ni_setup(struct ni_softc *);
|
|
|
|
static void nitimeout(struct ifnet *);
|
2000-04-16 13:55:39 +04:00
|
|
|
static void ni_shutdown(void *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static void ni_getpgs(struct ni_softc *sc, int size, void **v, paddr_t *p);
|
2005-06-27 15:05:24 +04:00
|
|
|
static int failtest(struct ni_softc *, int, int, int, const char *);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
volatile int endwait, retry; /* Used during autoconfig */
|
2000-04-09 20:49:57 +04:00
|
|
|
|
2008-07-09 21:51:21 +04:00
|
|
|
CFATTACH_DECL_NEW(ni, sizeof(struct ni_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
nimatch, niattach, NULL, NULL);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
#define NI_WREG(csr, val) \
|
|
|
|
bus_space_write_4(sc->sc_iot, sc->sc_ioh, csr, val)
|
|
|
|
#define NI_RREG(csr) \
|
|
|
|
bus_space_read_4(sc->sc_iot, sc->sc_ioh, csr)
|
|
|
|
|
|
|
|
#define WAITREG(csr,val) while (NI_RREG(csr) & val);
|
|
|
|
/*
|
|
|
|
* Check for present device.
|
|
|
|
*/
|
2008-07-09 21:51:21 +04:00
|
|
|
static int
|
|
|
|
nimatch(device_t parent, cfdata_t cf, void *aux)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
struct bi_attach_args *ba = aux;
|
|
|
|
u_short type;
|
|
|
|
|
|
|
|
type = bus_space_read_2(ba->ba_iot, ba->ba_ioh, BIREG_DTYPE);
|
|
|
|
if (type != BIDT_DEBNA && type != BIDT_DEBNT && type != BIDT_DEBNK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
|
|
|
|
cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a bunch of descriptor-safe memory.
|
|
|
|
* We need to get the structures from the beginning of its own pages.
|
|
|
|
*/
|
|
|
|
static void
|
2007-03-04 08:59:00 +03:00
|
|
|
ni_getpgs(struct ni_softc *sc, int size, void **v, paddr_t *p)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
int nsegs, error;
|
|
|
|
|
2003-04-01 05:58:14 +04:00
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &seg, 1,
|
2000-04-09 20:49:57 +04:00
|
|
|
&nsegs, BUS_DMA_NOWAIT)) != 0)
|
|
|
|
panic(" unable to allocate memory: error %d", error);
|
|
|
|
|
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &seg, nsegs, size, v,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0)
|
|
|
|
panic(" unable to map memory: error %d", error);
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
*p = seg.ds_addr;
|
2001-07-18 20:51:39 +04:00
|
|
|
memset(*v, 0, size);
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
static int
|
2005-06-27 15:05:24 +04:00
|
|
|
failtest(struct ni_softc *sc, int reg, int mask, int test, const char *str)
|
2000-04-16 13:55:39 +04:00
|
|
|
{
|
|
|
|
int i = 100;
|
|
|
|
|
|
|
|
do {
|
|
|
|
DELAY(100000);
|
|
|
|
} while (((NI_RREG(reg) & mask) != test) && --i);
|
|
|
|
|
|
|
|
if (i == 0) {
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: %s\n", device_xname(sc->sc_dev), str);
|
2000-04-16 13:55:39 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets.
|
|
|
|
*/
|
2008-07-09 21:51:21 +04:00
|
|
|
static void
|
|
|
|
niattach(device_t parent, device_t self, void *aux)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
struct bi_attach_args *ba = aux;
|
2008-07-09 21:51:21 +04:00
|
|
|
struct ni_softc *sc = device_private(self);
|
2000-04-09 20:49:57 +04:00
|
|
|
struct ifnet *ifp = (struct ifnet *)&sc->sc_if;
|
|
|
|
struct ni_msg *msg;
|
|
|
|
struct ni_ptdb *ptdb;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *va;
|
2013-10-25 19:11:32 +04:00
|
|
|
int i, j, s;
|
2000-04-09 20:49:57 +04:00
|
|
|
u_short type;
|
|
|
|
|
2008-07-09 21:51:21 +04:00
|
|
|
sc->sc_dev = self;
|
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
type = bus_space_read_2(ba->ba_iot, ba->ba_ioh, BIREG_DTYPE);
|
|
|
|
printf(": DEBN%c\n", type == BIDT_DEBNA ? 'A' : type == BIDT_DEBNT ?
|
|
|
|
'T' : 'K');
|
|
|
|
sc->sc_iot = ba->ba_iot;
|
|
|
|
sc->sc_ioh = ba->ba_ioh;
|
|
|
|
sc->sc_dmat = ba->ba_dmat;
|
|
|
|
|
2000-06-04 10:16:53 +04:00
|
|
|
bi_intr_establish(ba->ba_icookie, ba->ba_ivec,
|
|
|
|
niintr, sc, &sc->sc_intrcnt);
|
2000-06-05 04:09:17 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
|
2008-07-09 21:51:21 +04:00
|
|
|
device_xname(self), "intr");
|
2000-04-09 20:49:57 +04:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
ni_getpgs(sc, sizeof(struct ni_gvppqb), (void **)&sc->sc_gvppqb,
|
2000-04-09 20:49:57 +04:00
|
|
|
(paddr_t *)&sc->sc_pgvppqb);
|
2007-03-04 08:59:00 +03:00
|
|
|
ni_getpgs(sc, sizeof(struct ni_fqb), (void **)&sc->sc_fqb, 0);
|
2000-04-09 20:49:57 +04:00
|
|
|
ni_getpgs(sc, NBDESCS * sizeof(struct ni_bbd),
|
2007-03-04 08:59:00 +03:00
|
|
|
(void **)&sc->sc_bbd, 0);
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Zero the newly allocated memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nipqb->np_veclvl = (ba->ba_ivec << 2) + 2;
|
|
|
|
nipqb->np_node = ba->ba_intcpu;
|
|
|
|
nipqb->np_vpqb = (u_int32_t)gvp;
|
|
|
|
#ifdef __vax__
|
|
|
|
nipqb->np_spt = nipqb->np_gpt = mfpr(PR_SBR);
|
|
|
|
nipqb->np_sptlen = nipqb->np_gptlen = mfpr(PR_SLR);
|
|
|
|
#else
|
|
|
|
#error Must fix support for non-vax.
|
|
|
|
#endif
|
|
|
|
nipqb->np_bvplvl = 1;
|
|
|
|
nipqb->np_vfqb = (u_int32_t)fqb;
|
|
|
|
nipqb->np_vbdt = (u_int32_t)bbd;
|
|
|
|
nipqb->np_nbdr = NBDESCS;
|
|
|
|
|
|
|
|
/* Free queue block */
|
|
|
|
nipqb->np_freeq = NQUEUES;
|
|
|
|
fqb->nf_mlen = PKTHDR+MSGADD;
|
|
|
|
fqb->nf_dlen = PKTHDR+TXADD;
|
|
|
|
fqb->nf_rlen = PKTHDR+RXADD;
|
|
|
|
|
2008-07-09 21:51:21 +04:00
|
|
|
strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
|
2000-04-09 20:49:57 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_start = nistart;
|
|
|
|
ifp->if_ioctl = niioctl;
|
|
|
|
ifp->if_watchdog = nitimeout;
|
2000-12-14 09:59:01 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start init sequence.
|
|
|
|
*/
|
2000-04-16 13:55:39 +04:00
|
|
|
|
|
|
|
/* Reset the node */
|
|
|
|
NI_WREG(BIREG_VAXBICSR, NI_RREG(BIREG_VAXBICSR) | BICSR_NRST);
|
|
|
|
DELAY(500000);
|
|
|
|
i = 20;
|
|
|
|
while ((NI_RREG(BIREG_VAXBICSR) & BICSR_BROKE) && --i)
|
|
|
|
DELAY(500000);
|
|
|
|
if (i == 0) {
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: BROKE bit set after reset\n", device_xname(self));
|
2000-04-09 20:49:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
/* Check state */
|
|
|
|
if (failtest(sc, NI_PSR, PSR_STATE, PSR_UNDEF, "not undefined state"))
|
|
|
|
return;
|
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
/* Clear owner bits */
|
|
|
|
NI_WREG(NI_PSR, NI_RREG(NI_PSR) & ~PSR_OWN);
|
|
|
|
NI_WREG(NI_PCR, NI_RREG(NI_PCR) & ~PCR_OWN);
|
|
|
|
|
|
|
|
/* kick off init */
|
|
|
|
NI_WREG(NI_PCR, (u_int32_t)sc->sc_pgvppqb | PCR_INIT | PCR_OWN);
|
|
|
|
while (NI_RREG(NI_PCR) & PCR_OWN)
|
|
|
|
DELAY(100000);
|
|
|
|
|
|
|
|
/* Check state */
|
2000-04-16 13:55:39 +04:00
|
|
|
if (failtest(sc, NI_PSR, PSR_INITED, PSR_INITED, "failed initialize"))
|
2000-04-09 20:49:57 +04:00
|
|
|
return;
|
2000-04-16 13:55:39 +04:00
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
NI_WREG(NI_PSR, NI_RREG(NI_PSR) & ~PSR_OWN);
|
|
|
|
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_OWN|PCR_ENABLE);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
WAITREG(NI_PSR, PSR_OWN);
|
|
|
|
|
|
|
|
/* Check state */
|
2000-04-16 13:55:39 +04:00
|
|
|
if (failtest(sc, NI_PSR, PSR_STATE, PSR_ENABLED, "failed enable"))
|
2000-04-09 20:49:57 +04:00
|
|
|
return;
|
2000-04-16 13:55:39 +04:00
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
NI_WREG(NI_PSR, NI_RREG(NI_PSR) & ~PSR_OWN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The message queue packets must be located on the beginning
|
|
|
|
* of a page. A VAX page is 512 bytes, but it clusters 8 pages.
|
|
|
|
* This knowledge is used here when allocating pages.
|
|
|
|
* !!! How should this be done on MIPS and Alpha??? !!!
|
|
|
|
*/
|
|
|
|
#if NBPG < 4096
|
|
|
|
#error pagesize too small
|
|
|
|
#endif
|
2001-04-13 00:38:25 +04:00
|
|
|
s = splvm();
|
2000-04-09 20:49:57 +04:00
|
|
|
/* Set up message free queue */
|
|
|
|
ni_getpgs(sc, NMSGBUF * 512, &va, 0);
|
|
|
|
for (i = 0; i < NMSGBUF; i++) {
|
2007-03-09 02:17:56 +03:00
|
|
|
msg = (void *)((char *)va + i * 512);
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(msg, &fqb->nf_mforw);
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_MFREEQ|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
|
|
|
|
/* Set up xmit queue */
|
|
|
|
ni_getpgs(sc, NTXBUF * 512, &va, 0);
|
|
|
|
for (i = 0; i < NTXBUF; i++) {
|
|
|
|
struct ni_dg *data;
|
|
|
|
|
2007-03-09 02:17:56 +03:00
|
|
|
data = (void *)((char *)va + i * 512);
|
2000-04-09 20:49:57 +04:00
|
|
|
data->nd_status = 0;
|
|
|
|
data->nd_len = TXADD;
|
|
|
|
data->nd_ptdbidx = 1;
|
|
|
|
data->nd_opcode = BVP_DGRAM;
|
|
|
|
for (j = 0; j < NTXFRAGS; j++) {
|
|
|
|
data->bufs[j]._offset = 0;
|
|
|
|
data->bufs[j]._key = 1;
|
|
|
|
bbd[i * NTXFRAGS + j].nb_key = 1;
|
|
|
|
bbd[i * NTXFRAGS + j].nb_status = 0;
|
|
|
|
data->bufs[j]._index = i * NTXFRAGS + j;
|
|
|
|
}
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(data, &fqb->nf_dforw);
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_DFREEQ|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
|
|
|
|
/* recv buffers */
|
|
|
|
ni_getpgs(sc, NRXBUF * 512, &va, 0);
|
|
|
|
for (i = 0; i < NRXBUF; i++) {
|
|
|
|
struct ni_dg *data;
|
|
|
|
int idx;
|
|
|
|
|
2007-03-09 02:17:56 +03:00
|
|
|
data = (void *)((char *)va + i * 512);
|
2000-04-09 20:49:57 +04:00
|
|
|
data->nd_len = RXADD;
|
|
|
|
data->nd_opcode = BVP_DGRAMRX;
|
|
|
|
data->nd_ptdbidx = 2;
|
|
|
|
data->bufs[0]._key = 1;
|
|
|
|
|
|
|
|
idx = NTXBUF * NTXFRAGS + i;
|
|
|
|
if (ni_add_rxbuf(sc, data, idx))
|
|
|
|
panic("niattach: ni_add_rxbuf: out of mbufs");
|
|
|
|
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(data, &fqb->nf_rforw);
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_RFREEQ|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
splx(s);
|
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
/* Set initial parameters */
|
|
|
|
msg = REMQHI(&fqb->nf_mforw);
|
|
|
|
|
|
|
|
msg->nm_opcode = BVP_MSG;
|
|
|
|
msg->nm_status = 0;
|
|
|
|
msg->nm_len = sizeof(struct ni_param) + 6;
|
|
|
|
msg->nm_opcode2 = NI_WPARAM;
|
|
|
|
((struct ni_param *)&msg->nm_text[0])->np_flags = NP_PAD;
|
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
endwait = retry = 0;
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(msg, &gvp->nc_forw0);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
retry: WAITREG(NI_PCR, PCR_OWN);
|
2000-04-09 20:49:57 +04:00
|
|
|
NI_WREG(NI_PCR, PCR_CMDQNE|PCR_CMDQ0|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
2000-04-16 13:55:39 +04:00
|
|
|
i = 1000;
|
|
|
|
while (endwait == 0 && --i)
|
|
|
|
DELAY(10000);
|
|
|
|
|
|
|
|
if (endwait == 0) {
|
|
|
|
if (++retry < 3)
|
|
|
|
goto retry;
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: no response to set params\n", device_xname(self));
|
2000-04-16 13:55:39 +04:00
|
|
|
return;
|
|
|
|
}
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
/* Clear counters */
|
|
|
|
msg = REMQHI(&fqb->nf_mforw);
|
|
|
|
msg->nm_opcode = BVP_MSG;
|
|
|
|
msg->nm_status = 0;
|
|
|
|
msg->nm_len = sizeof(struct ni_param) + 6;
|
|
|
|
msg->nm_opcode2 = NI_RCCNTR;
|
|
|
|
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(msg, &gvp->nc_forw0);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_CMDQNE|PCR_CMDQ0|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
|
|
|
|
/* Enable transmit logic */
|
|
|
|
msg = REMQHI(&fqb->nf_mforw);
|
|
|
|
|
|
|
|
msg->nm_opcode = BVP_MSG;
|
|
|
|
msg->nm_status = 0;
|
|
|
|
msg->nm_len = 18;
|
|
|
|
msg->nm_opcode2 = NI_STPTDB;
|
|
|
|
ptdb = (struct ni_ptdb *)&msg->nm_text[0];
|
2001-07-18 20:51:39 +04:00
|
|
|
memset(ptdb, 0, sizeof(struct ni_ptdb));
|
2000-04-09 20:49:57 +04:00
|
|
|
ptdb->np_index = 1;
|
|
|
|
ptdb->np_fque = 1;
|
|
|
|
|
2013-10-25 19:11:32 +04:00
|
|
|
INSQTI(msg, &gvp->nc_forw0);
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_CMDQNE|PCR_CMDQ0|PCR_OWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
|
|
|
|
/* Wait for everything to finish */
|
|
|
|
WAITREG(NI_PSR, PSR_OWN);
|
|
|
|
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: hardware address %s\n", device_xname(self),
|
2000-04-09 20:49:57 +04:00
|
|
|
ether_sprintf(sc->sc_enaddr));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
2000-04-16 13:55:39 +04:00
|
|
|
if (shutdownhook_establish(ni_shutdown, sc) == 0)
|
2008-07-09 21:51:21 +04:00
|
|
|
aprint_error_dev(self, "WARNING: unable to establish shutdown hook\n");
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface.
|
|
|
|
*/
|
|
|
|
void
|
2008-07-09 21:51:21 +04:00
|
|
|
niinit(struct ni_softc *sc)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
2008-07-09 21:51:21 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set flags (so ni_setup() do the right thing).
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send setup messages so that the rx/tx locic starts.
|
|
|
|
*/
|
|
|
|
ni_setup(sc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface.
|
|
|
|
*/
|
|
|
|
void
|
2008-07-09 21:51:21 +04:00
|
|
|
nistart(struct ifnet *ifp)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
struct ni_softc *sc = ifp->if_softc;
|
|
|
|
struct ni_dg *data;
|
|
|
|
struct ni_bbd *bdp;
|
|
|
|
struct mbuf *m, *m0;
|
|
|
|
int i, cnt, res, mlen;
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_OACTIVE)
|
|
|
|
return;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: nistart\n", device_xname(sc->sc_dev));
|
2000-04-09 20:49:57 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
while (fqb->nf_dforw) {
|
2000-12-14 09:59:01 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m);
|
2000-04-09 20:49:57 +04:00
|
|
|
if (m == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
data = REMQHI(&fqb->nf_dforw);
|
|
|
|
if ((int)data == Q_EMPTY) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-14 09:59:01 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Count number of mbufs in chain.
|
|
|
|
* Always do DMA directly from mbufs, therefore the transmit
|
|
|
|
* ring is really big.
|
|
|
|
*/
|
|
|
|
for (m0 = m, cnt = 0; m0; m0 = m0->m_next)
|
|
|
|
if (m0->m_len)
|
|
|
|
cnt++;
|
|
|
|
if (cnt > NTXFRAGS)
|
|
|
|
panic("nistart"); /* XXX */
|
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
2000-04-09 20:49:57 +04:00
|
|
|
bdp = &bbd[(data->bufs[0]._index & 0x7fff)];
|
|
|
|
for (m0 = m, i = 0, mlen = 0; m0; m0 = m0->m_next) {
|
|
|
|
if (m0->m_len == 0)
|
|
|
|
continue;
|
|
|
|
bdp->nb_status = (mtod(m0, u_int32_t) & NIBD_OFFSET) |
|
|
|
|
NIBD_VALID;
|
|
|
|
bdp->nb_pte = (u_int32_t)kvtopte(mtod(m0, void *));
|
|
|
|
bdp->nb_len = m0->m_len;
|
|
|
|
data->bufs[i]._offset = 0;
|
|
|
|
data->bufs[i]._len = bdp->nb_len;
|
|
|
|
data->bufs[i]._index |= NIDG_CHAIN;
|
|
|
|
mlen += bdp->nb_len;
|
|
|
|
bdp++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
data->nd_opcode = BVP_DGRAM;
|
|
|
|
data->nd_pad3 = 1;
|
|
|
|
data->nd_ptdbidx = 1;
|
|
|
|
data->nd_len = 10 + i * 8;
|
|
|
|
data->bufs[i - 1]._index &= ~NIDG_CHAIN;
|
|
|
|
data->nd_cmdref = (u_int32_t)m;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
|
|
|
printf("%s: sending %d bytes (%d segments)\n",
|
2008-07-09 21:51:21 +04:00
|
|
|
device_xname(sc->sc_dev), mlen, i);
|
2000-04-09 20:49:57 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
res = INSQTI(data, &gvp->nc_forw0);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_CMDQNE|PCR_CMDQ0|PCR_OWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
niintr(void *arg)
|
|
|
|
{
|
|
|
|
struct ni_softc *sc = arg;
|
|
|
|
struct ni_dg *data;
|
|
|
|
struct ni_msg *msg;
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct ni_bbd *bd;
|
|
|
|
struct mbuf *m;
|
|
|
|
int idx, res;
|
|
|
|
|
2000-04-16 13:55:39 +04:00
|
|
|
if ((NI_RREG(NI_PSR) & PSR_STATE) != PSR_ENABLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((NI_RREG(NI_PSR) & PSR_ERR))
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: PSR %x\n", device_xname(sc->sc_dev), NI_RREG(NI_PSR));
|
2000-04-16 13:55:39 +04:00
|
|
|
|
2007-02-16 16:41:45 +03:00
|
|
|
KERNEL_LOCK(1, NULL);
|
2000-04-09 20:49:57 +04:00
|
|
|
/* Got any response packets? */
|
|
|
|
while ((NI_RREG(NI_PSR) & PSR_RSQ) && (data = REMQHI(&gvp->nc_forwr))) {
|
|
|
|
|
|
|
|
switch (data->nd_opcode) {
|
|
|
|
case BVP_DGRAMRX: /* Receive datagram */
|
|
|
|
idx = data->bufs[0]._index;
|
|
|
|
bd = &bbd[idx];
|
|
|
|
m = (void *)data->nd_cmdref;
|
2001-05-27 23:36:06 +04:00
|
|
|
m->m_pkthdr.len = m->m_len =
|
|
|
|
data->bufs[0]._len - ETHER_CRC_LEN;
|
2000-04-09 20:49:57 +04:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
if (ni_add_rxbuf(sc, data, idx)) {
|
|
|
|
bd->nb_len = (m->m_ext.ext_size - 2);
|
|
|
|
bd->nb_pte =
|
|
|
|
(long)kvtopte(m->m_ext.ext_buf);
|
|
|
|
bd->nb_status = 2 | NIBD_VALID;
|
|
|
|
bd->nb_key = 1;
|
|
|
|
}
|
|
|
|
data->nd_len = RXADD;
|
|
|
|
data->nd_status = 0;
|
|
|
|
res = INSQTI(data, &fqb->nf_rforw);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_RFREEQ|PCR_OWN);
|
|
|
|
}
|
|
|
|
if (m == (void *)data->nd_cmdref)
|
|
|
|
break; /* Out of mbufs */
|
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
2000-04-09 20:49:57 +04:00
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BVP_DGRAM:
|
|
|
|
m = (struct mbuf *)data->nd_cmdref;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
m_freem(m);
|
|
|
|
res = INSQTI(data, &fqb->nf_dforw);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_DFREEQ|PCR_OWN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BVP_MSGRX:
|
|
|
|
msg = (struct ni_msg *)data;
|
|
|
|
switch (msg->nm_opcode2) {
|
|
|
|
case NI_WPARAM:
|
2001-07-18 20:53:52 +04:00
|
|
|
memcpy(sc->sc_enaddr, ((struct ni_param *)&msg->nm_text[0])->np_dpa, ETHER_ADDR_LEN);
|
2000-04-09 20:49:57 +04:00
|
|
|
endwait = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NI_RCCNTR:
|
|
|
|
case NI_CLPTDB:
|
|
|
|
case NI_STPTDB:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-02-27 03:26:58 +03:00
|
|
|
printf("Unkn resp %d\n",
|
2000-04-09 20:49:57 +04:00
|
|
|
msg->nm_opcode2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = INSQTI(data, &fqb->nf_mforw);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_MFREEQ|PCR_OWN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unknown opcode %d\n", data->nd_opcode);
|
|
|
|
res = INSQTI(data, &fqb->nf_mforw);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_FREEQNE|PCR_MFREEQ|PCR_OWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to kick on the start routine again */
|
|
|
|
nistart(ifp);
|
|
|
|
|
|
|
|
NI_WREG(NI_PSR, NI_RREG(NI_PSR) & ~(PSR_OWN|PSR_RSQ));
|
2007-02-16 16:41:45 +03:00
|
|
|
KERNEL_UNLOCK_ONE(NULL);
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
int
|
2008-07-09 21:51:21 +04:00
|
|
|
niioctl(struct ifnet *ifp, u_long cmd, void *data)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
struct ni_softc *sc = ifp->if_softc;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
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:
|
2000-04-09 20:49:57 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
niinit(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;
|
|
|
|
switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
|
|
|
|
case IFF_RUNNING:
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running,
|
|
|
|
* stop it.
|
|
|
|
*/
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
ni_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 IFF_UP:
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* If interface it marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
niinit(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:
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Send a new setup packet to match any new changes.
|
|
|
|
* (Like IFF_PROMISC etc)
|
|
|
|
*/
|
|
|
|
ni_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;
|
|
|
|
default:
|
|
|
|
break;
|
2000-04-09 20:49:57 +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) {
|
2000-04-09 20:49:57 +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)
|
|
|
|
ni_setup(sc);
|
2000-04-09 20:49:57 +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);
|
|
|
|
break;
|
2000-04-09 20:49:57 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a receive buffer to the indicated descriptor.
|
|
|
|
*/
|
|
|
|
int
|
2005-02-27 03:26:58 +03:00
|
|
|
ni_add_rxbuf(struct ni_softc *sc, struct ni_dg *data, int idx)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
struct ni_bbd *bd = &bbd[idx];
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
m->m_data += 2;
|
|
|
|
bd->nb_len = (m->m_ext.ext_size - 2);
|
|
|
|
bd->nb_pte = (long)kvtopte(m->m_ext.ext_buf);
|
|
|
|
bd->nb_status = 2 | NIBD_VALID;
|
|
|
|
bd->nb_key = 1;
|
|
|
|
|
|
|
|
data->bufs[0]._offset = 0;
|
|
|
|
data->bufs[0]._len = bd->nb_len;
|
|
|
|
data->bufs[0]._index = idx;
|
|
|
|
data->nd_cmdref = (long)m;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create setup packet and put in queue for sending.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ni_setup(struct ni_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
struct ni_msg *msg;
|
|
|
|
struct ni_ptdb *ptdb;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
int i, res;
|
|
|
|
|
|
|
|
msg = REMQHI(&fqb->nf_mforw);
|
|
|
|
if ((int)msg == Q_EMPTY)
|
|
|
|
return; /* What to do? */
|
|
|
|
|
|
|
|
ptdb = (struct ni_ptdb *)&msg->nm_text[0];
|
2001-07-18 20:51:39 +04:00
|
|
|
memset(ptdb, 0, sizeof(struct ni_ptdb));
|
2000-04-09 20:49:57 +04:00
|
|
|
|
|
|
|
msg->nm_opcode = BVP_MSG;
|
|
|
|
msg->nm_len = 18;
|
|
|
|
ptdb->np_index = 2; /* definition type index */
|
|
|
|
ptdb->np_fque = 2; /* Free queue */
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
msg->nm_opcode2 = NI_STPTDB;
|
|
|
|
ptdb->np_type = ETHERTYPE_IP;
|
|
|
|
ptdb->np_flags = PTDB_UNKN|PTDB_BDC;
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
ptdb->np_flags |= PTDB_PROMISC;
|
|
|
|
memset(ptdb->np_mcast[0], 0xff, ETHER_ADDR_LEN); /* Broadcast */
|
|
|
|
ptdb->np_adrlen = 1;
|
|
|
|
msg->nm_len += 8;
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) == 0) {
|
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ec, enm);
|
|
|
|
i = 1;
|
|
|
|
while (enm != NULL) {
|
2002-05-22 20:03:14 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6)) {
|
2000-04-09 20:49:57 +04:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
ptdb->np_flags |= PTDB_AMC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
msg->nm_len += 8;
|
|
|
|
ptdb->np_adrlen++;
|
2001-07-18 20:53:52 +04:00
|
|
|
memcpy(ptdb->np_mcast[i++], enm->enm_addrlo,
|
2000-04-09 20:49:57 +04:00
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
msg->nm_opcode2 = NI_CLPTDB;
|
|
|
|
|
|
|
|
res = INSQTI(msg, &gvp->nc_forw0);
|
|
|
|
if (res == Q_EMPTY) {
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_CMDQNE|PCR_CMDQ0|PCR_OWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for dead transmit logic. Not uncommon.
|
|
|
|
*/
|
|
|
|
void
|
2008-07-09 21:51:21 +04:00
|
|
|
nitimeout(struct ifnet *ifp)
|
2000-04-09 20:49:57 +04:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct ni_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->sc_inq == 0)
|
|
|
|
return;
|
|
|
|
|
2008-07-09 21:51:21 +04:00
|
|
|
printf("%s: xmit logic died, resetting...\n", device_xname(sc->sc_dev));
|
2000-04-09 20:49:57 +04:00
|
|
|
/*
|
|
|
|
* Do a reset of interface, to get it going again.
|
|
|
|
* Will it work by just restart the transmit logic?
|
|
|
|
*/
|
|
|
|
niinit(sc);
|
|
|
|
#endif
|
|
|
|
}
|
2000-04-16 13:55:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown hook. Make sure the interface is stopped at reboot.
|
|
|
|
*/
|
|
|
|
void
|
2008-07-09 21:51:21 +04:00
|
|
|
ni_shutdown(void *arg)
|
2000-04-16 13:55:39 +04:00
|
|
|
{
|
|
|
|
struct ni_softc *sc = arg;
|
|
|
|
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
NI_WREG(NI_PCR, PCR_OWN|PCR_SHUTDOWN);
|
|
|
|
WAITREG(NI_PCR, PCR_OWN);
|
|
|
|
WAITREG(NI_PSR, PSR_OWN);
|
|
|
|
}
|