2008-12-17 01:35:21 +03:00
|
|
|
/* $NetBSD: mb8795.c,v 1.44 2008/12/16 22:35:24 christos Exp $ */
|
1998-06-09 11:53:05 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 Darrin B. Jewell
|
|
|
|
* 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:
|
|
|
|
* This product includes software developed by Darrin B. Jewell
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2008-12-17 01:35:21 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mb8795.c,v 1.44 2008/12/16 22:35:24 christos Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1998-06-09 11:53:05 +04:00
|
|
|
#include "bpfilter.h"
|
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
/* @@@ this is here for the REALIGN_DMABUF hack below */
|
|
|
|
#include "nextdmareg.h"
|
|
|
|
#include "nextdmavar.h"
|
|
|
|
|
|
|
|
#include "mb8795reg.h"
|
|
|
|
#include "mb8795var.h"
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
#include "bmapreg.h"
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define MB8795_DEBUG
|
1998-06-09 11:53:05 +04:00
|
|
|
#endif
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
#define PRINTF(x) printf x;
|
2002-09-11 05:46:29 +04:00
|
|
|
#ifdef MB8795_DEBUG
|
|
|
|
int mb8795_debug = 0;
|
|
|
|
#define DPRINTF(x) if (mb8795_debug) printf x;
|
1998-06-09 11:53:05 +04:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
extern int turbo;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for
|
|
|
|
* Fujitsu Ethernet Data Link Controller (MB8795)
|
|
|
|
* and the Fujitsu Manchester Encoder/Decoder (MB502).
|
|
|
|
*/
|
|
|
|
|
2005-01-19 04:58:21 +03:00
|
|
|
void mb8795_shutdown(void *);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2005-01-19 04:58:21 +03:00
|
|
|
bus_dmamap_t mb8795_txdma_restart(bus_dmamap_t, void *);
|
|
|
|
void mb8795_start_dma(struct mb8795_softc *);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2005-01-19 04:58:21 +03:00
|
|
|
int mb8795_mediachange(struct ifnet *);
|
|
|
|
void mb8795_mediastatus(struct ifnet *, struct ifmediareq *);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_config(struct mb8795_softc *sc, int *media, int nmedia, int defmedia)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
2002-07-11 20:03:09 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: mb8795_config()\n",sc->sc_dev.dv_xname));
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
/* Initialize ifnet structure. */
|
|
|
|
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = mb8795_start;
|
|
|
|
ifp->if_ioctl = mb8795_ioctl;
|
|
|
|
ifp->if_watchdog = mb8795_watchdog;
|
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_NOTRAILERS;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
/* Initialize media goo. */
|
|
|
|
ifmedia_init(&sc->sc_media, 0, mb8795_mediachange,
|
2002-09-11 05:46:29 +04:00
|
|
|
mb8795_mediastatus);
|
2002-07-11 20:03:09 +04:00
|
|
|
if (media != NULL) {
|
2002-09-11 05:46:29 +04:00
|
|
|
int i;
|
2002-07-11 20:03:09 +04:00
|
|
|
for (i = 0; i < nmedia; i++)
|
|
|
|
ifmedia_add(&sc->sc_media, media[i], 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, defmedia);
|
|
|
|
} else {
|
|
|
|
ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
|
|
|
|
}
|
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
|
|
|
|
sc->sc_sh = shutdownhook_establish(mb8795_shutdown, sc);
|
|
|
|
if (sc->sc_sh == NULL)
|
|
|
|
panic("mb8795_config: can't establish shutdownhook");
|
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
|
1999-02-28 20:08:05 +03:00
|
|
|
RND_TYPE_NET, 0);
|
1998-06-09 11:53:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DPRINTF(("%s: leaving mb8795_config()\n",sc->sc_dev.dv_xname));
|
|
|
|
}
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
/*
|
|
|
|
* Media change callback.
|
|
|
|
*/
|
|
|
|
int
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_mediachange(struct ifnet *ifp)
|
2002-07-11 20:03:09 +04:00
|
|
|
{
|
|
|
|
struct mb8795_softc *sc = ifp->if_softc;
|
|
|
|
int data;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
if (turbo)
|
|
|
|
return (0);
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
switch IFM_SUBTYPE(sc->sc_media.ifm_media) {
|
|
|
|
case IFM_AUTO:
|
2002-09-11 05:46:29 +04:00
|
|
|
if ((bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
|
|
|
|
BMAP_DATA_UTPENABLED_MASK) ||
|
|
|
|
!(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
|
|
|
|
BMAP_DATA_UTPCARRIER_MASK)) {
|
2002-07-11 20:03:09 +04:00
|
|
|
data = BMAP_DATA_UTPENABLE;
|
|
|
|
sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_T;
|
2002-09-11 05:46:29 +04:00
|
|
|
} else {
|
|
|
|
data = BMAP_DATA_BNCENABLE;
|
|
|
|
sc->sc_media.ifm_cur->ifm_data = IFM_ETHER|IFM_10_2;
|
2002-07-11 20:03:09 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFM_10_T:
|
|
|
|
data = BMAP_DATA_UTPENABLE;
|
|
|
|
break;
|
|
|
|
case IFM_10_2:
|
2002-09-11 05:46:29 +04:00
|
|
|
data = BMAP_DATA_BNCENABLE;
|
2002-07-11 20:03:09 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh,
|
|
|
|
BMAP_DDIR, BMAP_DDIR_UTPENABLE_MASK);
|
|
|
|
bus_space_write_1(sc->sc_bmap_bst, sc->sc_bmap_bsh,
|
|
|
|
BMAP_DATA, data);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Media status callback.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
|
2002-07-11 20:03:09 +04:00
|
|
|
{
|
|
|
|
struct mb8795_softc *sc = ifp->if_softc;
|
2002-09-11 05:46:29 +04:00
|
|
|
|
|
|
|
if (turbo)
|
|
|
|
return;
|
2002-07-11 20:03:09 +04:00
|
|
|
|
|
|
|
if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_AUTO) {
|
|
|
|
ifmr->ifm_active = sc->sc_media.ifm_cur->ifm_data;
|
|
|
|
}
|
|
|
|
if (IFM_SUBTYPE(ifmr->ifm_active) == IFM_10_T) {
|
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
if (!(bus_space_read_1(sc->sc_bmap_bst, sc->sc_bmap_bsh, BMAP_DATA) &
|
|
|
|
BMAP_DATA_UTPCARRIER_MASK))
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
} else {
|
|
|
|
ifmr->ifm_status &= ~IFM_AVALID; /* don't know for 10_2 */
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
/****************************************************************/
|
2002-09-11 05:46:29 +04:00
|
|
|
#ifdef MB8795_DEBUG
|
2005-05-17 08:14:57 +04:00
|
|
|
#define XCHR(x) hexdigits[(x) & 0xf]
|
1998-06-09 11:53:05 +04:00
|
|
|
static void
|
2002-09-11 05:46:29 +04:00
|
|
|
mb8795_hex_dump(unsigned char *pkt, size_t len)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
size_t i, j;
|
|
|
|
|
2001-04-02 09:29:42 +04:00
|
|
|
printf("00000000 ");
|
1998-06-09 11:53:05 +04:00
|
|
|
for(i=0; i<len; i++) {
|
|
|
|
printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i]));
|
2001-04-02 09:29:42 +04:00
|
|
|
if ((i+1) % 16 == 8) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
if ((i+1) % 16 == 0) {
|
2001-04-02 09:29:42 +04:00
|
|
|
printf(" %c", '|');
|
|
|
|
for(j=0; j<16; j++) {
|
1998-06-09 11:53:05 +04:00
|
|
|
printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.');
|
2001-04-02 09:29:42 +04:00
|
|
|
}
|
|
|
|
printf("%c\n%c%c%c%c%c%c%c%c ", '|',
|
|
|
|
XCHR((i+1)>>28),XCHR((i+1)>>24),XCHR((i+1)>>20),XCHR((i+1)>>16),
|
|
|
|
XCHR((i+1)>>12), XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1));
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2001-04-02 09:29:42 +04:00
|
|
|
#undef XCHR
|
1998-07-20 01:41:16 +04:00
|
|
|
#endif
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller receive interrupt.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_rint(struct mb8795_softc *sc)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
int error = 0;
|
|
|
|
u_char rxstat;
|
|
|
|
u_char rxmask;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
rxstat = MB_READ_REG(sc, MB8795_RXSTAT);
|
|
|
|
rxmask = MB_READ_REG(sc, MB8795_RXMASK);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_RESET) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: rx reset packet\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
|
|
|
error++;
|
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_SHORT) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: rx short packet\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
|
|
|
error++;
|
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_ALIGNERR) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: rx alignment error\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
2001-04-02 09:29:42 +04:00
|
|
|
#if 0
|
1998-06-09 11:53:05 +04:00
|
|
|
error++;
|
2001-04-02 09:29:42 +04:00
|
|
|
#endif
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_CRCERR) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: rx CRC error\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
2001-04-02 09:29:42 +04:00
|
|
|
#if 0
|
1998-06-09 11:53:05 +04:00
|
|
|
error++;
|
2001-04-02 09:29:42 +04:00
|
|
|
#endif
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_OVERFLOW) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: rx overflow error\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
2001-04-02 09:29:42 +04:00
|
|
|
#if 0
|
1998-06-09 11:53:05 +04:00
|
|
|
error++;
|
2001-04-02 09:29:42 +04:00
|
|
|
#endif
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
/* @@@ handle more gracefully, free memory, etc. */
|
|
|
|
}
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
if (rxstat & MB8795_RXSTAT_OK) {
|
|
|
|
struct mbuf *m;
|
1998-06-09 11:53:05 +04:00
|
|
|
int s;
|
|
|
|
s = spldma();
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
while ((m = MBDMA_RX_MBUF (sc))) {
|
2005-01-30 22:03:23 +03:00
|
|
|
/* CRC is included with the packet; trim it. */
|
|
|
|
m->m_pkthdr.len = m->m_len = m->m_len - ETHER_CRC_LEN;
|
2001-04-16 18:12:12 +04:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2001-04-16 18:12:12 +04:00
|
|
|
/* Find receive length, keep crc */
|
2003-05-03 22:10:37 +04:00
|
|
|
/* enable DMA interrupts while we process the packet */
|
1998-06-09 11:53:05 +04:00
|
|
|
splx(s);
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
#if defined(MB8795_DEBUG)
|
1998-06-09 11:53:05 +04:00
|
|
|
/* Peek at the packet */
|
2001-05-13 20:55:37 +04:00
|
|
|
DPRINTF(("%s: received packet, at VA %p-%p,len %d\n",
|
1998-06-09 11:53:05 +04:00
|
|
|
sc->sc_dev.dv_xname,mtod(m,u_char *),mtod(m,u_char *)+m->m_len,m->m_len));
|
2002-09-11 05:46:29 +04:00
|
|
|
if (mb8795_debug > 3) {
|
|
|
|
mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len);
|
|
|
|
} else if (mb8795_debug > 2) {
|
|
|
|
mb8795_hex_dump(mtod(m,u_char *), m->m_pkthdr.len < 255 ? m->m_pkthdr.len : 128 );
|
2001-04-02 09:29:42 +04:00
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
#endif
|
2001-04-16 18:12:12 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Pass packet to bpf if there is a listener.
|
|
|
|
*/
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
1999-05-19 03:52:51 +04:00
|
|
|
/* Pass the packet up. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s = spldma();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
#ifdef MB8795_DEBUG
|
|
|
|
if (mb8795_debug) {
|
2000-08-09 06:26:26 +04:00
|
|
|
char sbuf[256];
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS, rxstat);
|
2000-08-09 06:26:26 +04:00
|
|
|
printf("%s: rx interrupt, rxstat = %s\n",
|
|
|
|
sc->sc_dev.dv_xname, sbuf);
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(sbuf, sizeof(sbuf), MB8795_RXSTAT_BITS,
|
|
|
|
MB_READ_REG(sc, MB8795_RXSTAT));
|
|
|
|
|
2000-08-09 06:26:26 +04:00
|
|
|
printf("rxstat = 0x%s\n", sbuf);
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(sbuf, sizeof(sbuf), MB8795_RXMASK_BITS,
|
|
|
|
MB_READ_REG(sc, MB8795_RXMASK));
|
2000-08-09 06:26:26 +04:00
|
|
|
printf("rxmask = 0x%s\n", sbuf);
|
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(sbuf, sizeof(sbuf), MB8795_RXMODE_BITS,
|
|
|
|
MB_READ_REG(sc, MB8795_RXMODE));
|
2000-08-09 06:26:26 +04:00
|
|
|
printf("rxmode = 0x%s\n", sbuf);
|
|
|
|
}
|
|
|
|
#endif
|
1999-08-29 09:51:45 +04:00
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller transmit interrupt.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_tint(struct mb8795_softc *sc)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
u_char txstat;
|
|
|
|
u_char txmask;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
panic ("tint");
|
|
|
|
txstat = MB_READ_REG(sc, MB8795_TXSTAT);
|
|
|
|
txmask = MB_READ_REG(sc, MB8795_TXMASK);
|
|
|
|
|
|
|
|
if ((txstat & MB8795_TXSTAT_READY) ||
|
|
|
|
(txstat & MB8795_TXSTAT_TXRECV)) {
|
|
|
|
/* printf("X"); */
|
|
|
|
MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
|
|
|
|
/* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE); */
|
|
|
|
/* MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_TXRXIE); */
|
|
|
|
MB_WRITE_REG(sc, MB8795_TXMASK, 0);
|
|
|
|
if ((ifp->if_flags & IFF_RUNNING) && !IF_IS_EMPTY(&sc->sc_tx_snd)) {
|
2005-01-19 04:58:21 +03:00
|
|
|
void mb8795_start_dma(struct mb8795_softc *); /* XXXX */
|
2002-09-11 05:46:29 +04:00
|
|
|
/* printf ("Z"); */
|
|
|
|
mb8795_start_dma(sc);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
if (txstat & MB8795_TXSTAT_SHORTED) {
|
1998-06-09 11:53:05 +04:00
|
|
|
printf("%s: tx cable shorted\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (txstat & MB8795_TXSTAT_UNDERFLOW) {
|
1998-06-09 11:53:05 +04:00
|
|
|
printf("%s: tx underflow\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (txstat & MB8795_TXSTAT_COLLERR) {
|
1998-06-09 11:53:05 +04:00
|
|
|
DPRINTF(("%s: tx collision\n", sc->sc_dev.dv_xname));
|
|
|
|
ifp->if_collisions++;
|
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
if (txstat & MB8795_TXSTAT_COLLERR16) {
|
1998-06-09 11:53:05 +04:00
|
|
|
printf("%s: tx 16th collision\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
ifp->if_collisions += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2002-09-11 05:46:29 +04:00
|
|
|
if (txstat & MB8795_TXSTAT_READY) {
|
2000-08-09 06:26:26 +04:00
|
|
|
char sbuf[256];
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2008-12-17 01:35:21 +03:00
|
|
|
snprintb(sbuf, sizeof(sbuf), MB8795_TXSTAT_BITS, txstat);
|
2000-08-09 06:26:26 +04:00
|
|
|
panic("%s: unexpected tx interrupt %s",
|
|
|
|
sc->sc_dev.dv_xname, sbuf);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
/* turn interrupt off */
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXMASK, txmask & ~MB8795_TXMASK_READYIE);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
return;
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_reset(struct mb8795_softc *sc)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
int s;
|
2002-07-11 20:03:09 +04:00
|
|
|
int i;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2001-01-14 20:33:48 +03:00
|
|
|
s = splnet();
|
2002-07-11 20:03:09 +04:00
|
|
|
|
|
|
|
DPRINTF (("%s: mb8795_reset()\n",sc->sc_dev.dv_xname));
|
|
|
|
|
|
|
|
sc->sc_ethercom.ec_if.if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
|
|
|
|
sc->sc_ethercom.ec_if.if_timer = 0;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MBDMA_RESET(sc);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RESET, MB8795_RESET_MODE);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
|
|
|
mb8795_mediachange(&sc->sc_ethercom.ec_if);
|
|
|
|
|
|
|
|
#if 0 /* This interrupt was sometimes failing to ack correctly
|
|
|
|
* causing a loop @@@
|
|
|
|
*/
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXMASK,
|
|
|
|
MB8795_TXMASK_UNDERFLOWIE | MB8795_TXMASK_COLLIE | MB8795_TXMASK_COLL16IE
|
|
|
|
| MB8795_TXMASK_PARERRIE);
|
2002-07-11 20:03:09 +04:00
|
|
|
#else
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXMASK, 0);
|
2002-07-11 20:03:09 +04:00
|
|
|
#endif
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
|
|
|
#if 0
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RXMASK,
|
|
|
|
MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE |
|
|
|
|
MB8795_RXMASK_ALIGNERRIE | MB8795_RXMASK_CRCERRIE | MB8795_RXMASK_OVERFLOWIE);
|
2002-07-11 20:03:09 +04:00
|
|
|
#else
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RXMASK,
|
|
|
|
MB8795_RXMASK_OKIE | MB8795_RXMASK_RESETIE | MB8795_RXMASK_SHORTIE);
|
2002-07-11 20:03:09 +04:00
|
|
|
#endif
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RXSTAT, MB8795_RXSTAT_CLEAR);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
|
|
|
for(i=0;i<sizeof(sc->sc_enaddr);i++) {
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_ENADDR+i, sc->sc_enaddr[i]);
|
2002-07-11 20:03:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(("%s: initializing ethernet %02x:%02x:%02x:%02x:%02x:%02x, size=%d\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
|
|
|
|
sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5],
|
|
|
|
sizeof(sc->sc_enaddr)));
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_RESET, 0);
|
2002-07-11 20:03:09 +04:00
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_watchdog(struct ifnet *ifp)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
|
|
|
struct mb8795_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
++ifp->if_oerrors;
|
|
|
|
|
2001-05-13 20:55:37 +04:00
|
|
|
DPRINTF(("%s: %lld input errors, %lld input packets\n",
|
1998-06-09 11:53:05 +04:00
|
|
|
sc->sc_dev.dv_xname, ifp->if_ierrors, ifp->if_ipackets));
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
mb8795_init(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface; set up initialization block
|
|
|
|
* and transmit/receive descriptor rings.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_init(struct mb8795_softc *sc)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
2002-07-11 20:03:09 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
int s;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
DPRINTF (("%s: mb8795_init()\n",sc->sc_dev.dv_xname));
|
2002-09-11 05:46:29 +04:00
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
|
|
|
int rxmode;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 17:15:58 +04:00
|
|
|
s = spldma();
|
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0)
|
2002-07-11 20:03:09 +04:00
|
|
|
mb8795_reset(sc);
|
2002-09-11 17:15:58 +04:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
2002-09-11 05:46:29 +04:00
|
|
|
rxmode = MB8795_RXMODE_PROMISCUOUS;
|
2002-09-11 17:15:58 +04:00
|
|
|
else
|
|
|
|
rxmode = MB8795_RXMODE_NORMAL;
|
|
|
|
/* XXX add support for multicast */
|
|
|
|
if (turbo)
|
|
|
|
rxmode |= MB8795_RXMODE_TEST;
|
2002-07-11 20:03:09 +04:00
|
|
|
|
2002-09-11 17:15:58 +04:00
|
|
|
/* switching mode probably borken now with turbo */
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXMODE,
|
|
|
|
turbo ? MB8795_TXMODE_TURBO1 : MB8795_TXMODE_LB_DISABLE);
|
|
|
|
MB_WRITE_REG(sc, MB8795_RXMODE, rxmode);
|
|
|
|
|
2002-09-11 17:15:58 +04:00
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0) {
|
2002-09-11 05:46:29 +04:00
|
|
|
MBDMA_RX_SETUP(sc);
|
|
|
|
MBDMA_TX_SETUP(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MBDMA_RX_GO(sc);
|
2002-07-11 20:03:09 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
2001-04-02 09:29:42 +04:00
|
|
|
#if 0
|
2002-07-11 20:03:09 +04:00
|
|
|
s = spldma();
|
|
|
|
if (! IF_IS_EMPTY(&sc->sc_tx_snd)) {
|
|
|
|
mb8795_start_dma(ifp);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
2002-07-11 20:03:09 +04:00
|
|
|
splx(s);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
mb8795_reset(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_shutdown(void *arg)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
2002-07-11 20:03:09 +04:00
|
|
|
struct mb8795_softc *sc = (struct mb8795_softc *)arg;
|
2002-09-11 05:46:29 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: mb8795_shutdown()\n",sc->sc_dev.dv_xname));
|
|
|
|
|
2002-07-11 20:03:09 +04:00
|
|
|
mb8795_reset(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
mb8795_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
2005-01-19 04:58:21 +03:00
|
|
|
struct mb8795_softc *sc = ifp->if_softc;
|
1998-06-09 11:53:05 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
2001-01-14 20:33:48 +03:00
|
|
|
s = splnet();
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
DPRINTF(("%s: mb8795_ioctl()\n",sc->sc_dev.dv_xname));
|
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
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:
|
|
|
|
DPRINTF(("%s: mb8795_ioctl() SIOCINITIFADDR\n",sc->sc_dev.dv_xname));
|
1998-06-09 11:53:05 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
mb8795_init(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
arp_ifinit(ifp, ifa);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
2002-09-11 05:46:29 +04:00
|
|
|
DPRINTF(("%s: mb8795_ioctl() SIOCSIFFLAGS\n",sc->sc_dev.dv_xname));
|
*** 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:
|
1998-06-09 11:53:05 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
2002-07-11 20:03:09 +04:00
|
|
|
/* ifp->if_flags &= ~IFF_RUNNING; */
|
|
|
|
mb8795_reset(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:
|
1998-06-09 11:53:05 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
mb8795_init(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:
|
1998-06-09 11:53:05 +04:00
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect hardware registers.
|
|
|
|
*/
|
|
|
|
mb8795_init(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;
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
2002-09-11 05:46:29 +04:00
|
|
|
#ifdef MB8795_DEBUG
|
1998-06-09 11:53:05 +04:00
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
|
|
|
sc->sc_debug = 1;
|
|
|
|
else
|
|
|
|
sc->sc_debug = 0;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2007-09-01 11:32:22 +04:00
|
|
|
DPRINTF(("%s: mb8795_ioctl() SIOCADDMULTI\n",
|
|
|
|
sc->sc_dev.dv_xname));
|
|
|
|
if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
|
1998-06-09 11:53:05 +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)
|
|
|
|
mb8795_init(sc);
|
1998-06-09 11:53:05 +04:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
2002-09-11 05:46:29 +04:00
|
|
|
DPRINTF(("%s: mb8795_ioctl() SIOCSIFMEDIA\n",sc->sc_dev.dv_xname));
|
1998-06-09 11:53:05 +04:00
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
|
|
|
|
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);
|
1998-06-09 11:53:05 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
DPRINTF(("DEBUG: mb8795_ioctl(0x%lx) returning %d\n",
|
|
|
|
cmd,error));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup output on interface.
|
|
|
|
* Get another datagram to send off of the interface queue, and map it to the
|
|
|
|
* interface before starting the output.
|
2001-01-14 20:33:48 +03:00
|
|
|
* Called only at splnet or interrupt level.
|
1998-06-09 11:53:05 +04:00
|
|
|
*/
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_start(struct ifnet *ifp)
|
1998-06-09 11:53:05 +04:00
|
|
|
{
|
2002-05-18 18:33:35 +04:00
|
|
|
struct mb8795_softc *sc = ifp->if_softc;
|
2002-05-21 00:19:36 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int s;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-05-21 00:19:36 +04:00
|
|
|
DPRINTF(("%s: mb8795_start()\n",sc->sc_dev.dv_xname));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
IFQ_POLL(&ifp->if_snd, m);
|
|
|
|
if (m == 0) {
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("%s: No packet to start",
|
2002-05-21 00:19:36 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
return; /* @@@ Turn off xmit for debugging */
|
|
|
|
#endif
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-05-21 00:19:36 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Pass packet to bpf if there is a listener.
|
|
|
|
*/
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = spldma();
|
|
|
|
IF_ENQUEUE(&sc->sc_tx_snd, m);
|
2002-09-11 05:46:29 +04:00
|
|
|
if (!MBDMA_TX_ISACTIVE(sc))
|
|
|
|
mb8795_start_dma(sc);
|
2002-05-21 00:19:36 +04:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-19 04:58:21 +03:00
|
|
|
mb8795_start_dma(struct mb8795_softc *sc)
|
2002-05-21 00:19:36 +04:00
|
|
|
{
|
2002-09-11 05:46:29 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct mbuf *m;
|
|
|
|
u_char txmask;
|
2002-05-21 00:19:36 +04:00
|
|
|
|
|
|
|
DPRINTF(("%s: mb8795_start_dma()\n",sc->sc_dev.dv_xname));
|
1998-06-09 11:53:05 +04:00
|
|
|
|
|
|
|
#if (defined(DIAGNOSTIC))
|
2002-05-18 18:33:35 +04:00
|
|
|
{
|
|
|
|
u_char txstat;
|
2002-09-11 05:46:29 +04:00
|
|
|
txstat = MB_READ_REG(sc, MB8795_TXSTAT);
|
|
|
|
if (!turbo && !(txstat & MB8795_TXSTAT_READY)) {
|
1998-07-11 11:06:16 +04:00
|
|
|
/* @@@ I used to panic here, but then it paniced once.
|
|
|
|
* Let's see if I can just reset instead. [ dbj 980706.1900 ]
|
|
|
|
*/
|
2002-05-18 18:33:35 +04:00
|
|
|
printf("%s: transmitter not ready\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2002-07-11 20:03:09 +04:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
mb8795_init(sc);
|
1998-07-11 11:06:16 +04:00
|
|
|
return;
|
2002-05-18 18:33:35 +04:00
|
|
|
}
|
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
return; /* @@@ Turn off xmit for debugging */
|
|
|
|
#endif
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
IF_DEQUEUE(&sc->sc_tx_snd, m);
|
|
|
|
if (m == 0) {
|
2002-05-21 00:19:36 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("%s: No packet to start_dma",
|
2002-05-21 00:19:36 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
2002-05-18 18:33:35 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MB_WRITE_REG(sc, MB8795_TXSTAT, MB8795_TXSTAT_CLEAR);
|
|
|
|
txmask = MB_READ_REG(sc, MB8795_TXMASK);
|
|
|
|
/* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_READYIE); */
|
|
|
|
/* MB_WRITE_REG(sc, MB8795_TXMASK, txmask | MB8795_TXMASK_TXRXIE); */
|
2002-05-21 00:19:36 +04:00
|
|
|
|
1998-06-09 11:53:05 +04:00
|
|
|
ifp->if_timer = 5;
|
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
if (MBDMA_TX_MBUF(sc, m))
|
2002-05-18 18:33:35 +04:00
|
|
|
return;
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-09-11 05:46:29 +04:00
|
|
|
MBDMA_TX_GO(sc);
|
|
|
|
if (turbo)
|
|
|
|
MB_WRITE_REG(sc, MB8795_TXMODE, MB8795_TXMODE_TURBO1 | MB8795_TXMODE_TURBOSTART);
|
1998-06-09 11:53:05 +04:00
|
|
|
|
2002-05-21 00:19:36 +04:00
|
|
|
ifp->if_opackets++;
|
1998-06-09 11:53:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************/
|