2010-04-05 11:19:28 +04:00
|
|
|
/* $NetBSD: if_eg.c,v 1.82 2010/04/05 07:20:24 joerg Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1993 Dean Huxley <dean@fsa.ca>
|
|
|
|
* 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 Dean Huxley.
|
|
|
|
* 4. The name of Dean Huxley 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.
|
|
|
|
*/
|
1996-01-10 21:21:52 +03:00
|
|
|
/*
|
|
|
|
* Support for 3Com 3c505 Etherlink+ card.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
/*
|
|
|
|
* To do:
|
1994-08-23 21:59:33 +04:00
|
|
|
* - multicast
|
|
|
|
* - promiscuous
|
|
|
|
*/
|
2001-11-13 11:01:09 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2010-04-05 11:19:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_eg.c,v 1.82 2010/04/05 07:20:24 joerg Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1997-10-15 09:55:13 +04:00
|
|
|
#include "rnd.h"
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
1996-10-17 08:21:55 +04:00
|
|
|
#include <sys/systm.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/device.h>
|
1997-10-15 09:55:13 +04:00
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
|
|
|
|
#include <net/if_ether.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/intr.h>
|
|
|
|
#include <sys/bus.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/if_egreg.h>
|
|
|
|
#include <dev/isa/elink.h>
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* for debugging convenience */
|
|
|
|
#ifdef EGDEBUG
|
1996-10-13 05:37:04 +04:00
|
|
|
#define DPRINTF(x) printf x
|
1994-08-23 21:59:33 +04:00
|
|
|
#else
|
1996-10-11 02:04:48 +04:00
|
|
|
#define DPRINTF(x)
|
1994-08-23 21:59:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define EG_INLEN 10
|
|
|
|
#define EG_BUFLEN 0x0670
|
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
#define EG_PCBLEN 64
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* Ethernet software status per interface.
|
|
|
|
*/
|
|
|
|
struct eg_softc {
|
|
|
|
struct device sc_dev;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ethercom sc_ethercom; /* Ethernet common part */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t sc_iot; /* bus space identifier */
|
|
|
|
bus_space_handle_t sc_ioh; /* i/o handle */
|
2005-02-27 03:26:58 +03:00
|
|
|
u_int8_t eg_rom_major; /* Cards ROM version (major number) */
|
|
|
|
u_int8_t eg_rom_minor; /* Cards ROM version (minor number) */
|
1996-08-03 06:12:46 +04:00
|
|
|
short eg_ram; /* Amount of RAM on the card */
|
1998-01-12 23:48:17 +03:00
|
|
|
u_int8_t eg_pcb[EG_PCBLEN]; /* Primary Command Block buffer */
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t eg_incount; /* Number of buffers currently used */
|
2007-03-04 08:59:00 +03:00
|
|
|
void * eg_inbuf; /* Incoming packet buffer */
|
|
|
|
void * eg_outbuf; /* Outgoing packet buffer */
|
1997-10-15 09:55:13 +04:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rndsource_element_t rnd_source;
|
|
|
|
#endif
|
1994-08-23 21:59:33 +04:00
|
|
|
};
|
|
|
|
|
2009-05-12 13:10:15 +04:00
|
|
|
int egprobe(device_t, cfdata_t, void *);
|
|
|
|
void egattach(device_t, device_t, void *);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2002-10-02 06:00:07 +04:00
|
|
|
CFATTACH_DECL(eg, sizeof(struct eg_softc),
|
2002-10-02 07:10:45 +04:00
|
|
|
egprobe, egattach, NULL, NULL);
|
1996-03-17 03:43:52 +03:00
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int egintr(void *);
|
|
|
|
void eginit(struct eg_softc *);
|
2007-03-04 08:59:00 +03:00
|
|
|
int egioctl(struct ifnet *, u_long, void *);
|
2005-02-04 05:10:35 +03:00
|
|
|
void egrecv(struct eg_softc *);
|
|
|
|
void egstart(struct ifnet *);
|
|
|
|
void egwatchdog(struct ifnet *);
|
|
|
|
void egreset(struct eg_softc *);
|
2007-03-04 08:59:00 +03:00
|
|
|
void egread(struct eg_softc *, void *, int);
|
|
|
|
struct mbuf *egget(struct eg_softc *, void *, int);
|
2005-02-04 05:10:35 +03:00
|
|
|
void egstop(struct eg_softc *);
|
|
|
|
|
|
|
|
static inline void egprintpcb(u_int8_t *);
|
|
|
|
static inline void egprintstat(u_char);
|
|
|
|
static int egoutPCB(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
|
|
|
static int egreadPCBstat(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
|
|
|
static int egreadPCBready(bus_space_tag_t, bus_space_handle_t);
|
|
|
|
static int egwritePCB(bus_space_tag_t, bus_space_handle_t, u_int8_t *);
|
|
|
|
static int egreadPCB(bus_space_tag_t, bus_space_handle_t, u_int8_t *);
|
1996-10-17 08:21:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* Support stuff
|
|
|
|
*/
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
static inline void
|
2009-03-14 18:35:58 +03:00
|
|
|
egprintpcb(u_int8_t *pcb)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
for (i = 0; i < pcb[1] + 2; i++)
|
|
|
|
DPRINTF(("pcb[%2d] = %x\n", i, pcb[i]));
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
2006-11-16 04:32:37 +03:00
|
|
|
egprintstat(u_char b)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTF(("%s %s %s %s %s %s %s\n",
|
1994-08-23 21:59:33 +04:00
|
|
|
(b & EG_STAT_HCRE)?"HCRE":"",
|
|
|
|
(b & EG_STAT_ACRF)?"ACRF":"",
|
|
|
|
(b & EG_STAT_DIR )?"DIR ":"",
|
|
|
|
(b & EG_STAT_DONE)?"DONE":"",
|
|
|
|
(b & EG_STAT_ASF3)?"ASF3":"",
|
|
|
|
(b & EG_STAT_ASF2)?"ASF2":"",
|
|
|
|
(b & EG_STAT_ASF1)?"ASF1":""));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
egoutPCB(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t b)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 4000; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
if (bus_space_read_1(iot, ioh, EG_STATUS) & EG_STAT_HCRE) {
|
|
|
|
bus_space_write_1(iot, ioh, EG_COMMAND, b);
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
delay(10);
|
|
|
|
}
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("egoutPCB failed\n"));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
egreadPCBstat(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t statb)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 5000; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, EG_STATUS) &
|
2005-02-27 03:26:58 +03:00
|
|
|
EG_PCB_STAT) != EG_PCB_NULL)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((bus_space_read_1(iot, ioh, EG_STATUS) & EG_PCB_STAT) == statb)
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
egreadPCBready(bus_space_tag_t iot, bus_space_handle_t ioh)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < 10000; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
if (bus_space_read_1(iot, ioh, EG_STATUS) & EG_STAT_ACRF)
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
|
|
|
delay(5);
|
|
|
|
}
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("PCB read not ready\n"));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
egwritePCB(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t *pcb)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int8_t len;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
|
|
|
(bus_space_read_1(iot, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
len = pcb[1] + 2;
|
1994-08-23 21:59:33 +04:00
|
|
|
for (i = 0; i < len; i++)
|
1998-01-12 23:48:17 +03:00
|
|
|
egoutPCB(iot, ioh, pcb[i]);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
for (i=0; i < 4000; i++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
if (bus_space_read_1(iot, ioh, EG_STATUS) & EG_STAT_HCRE)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
|
|
|
(bus_space_read_1(iot, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_DONE);
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
egoutPCB(iot, ioh, len);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCBstat(iot, ioh, EG_PCB_ACCEPT))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
return 0;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
egreadPCB(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t *pcb)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
int i;
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
|
|
|
(bus_space_read_1(iot, ioh, EG_CONTROL) & ~EG_PCB_STAT) | EG_PCB_NULL);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2001-07-19 00:39:53 +04:00
|
|
|
memset(pcb, 0, EG_PCBLEN);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCBready(iot, ioh))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
pcb[0] = bus_space_read_1(iot, ioh, EG_COMMAND);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCBready(iot, ioh))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
pcb[1] = bus_space_read_1(iot, ioh, EG_COMMAND);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if (pcb[1] > 62) {
|
|
|
|
DPRINTF(("len %d too large\n", pcb[1]));
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
for (i = 0; i < pcb[1]; i++) {
|
|
|
|
if (egreadPCBready(iot, ioh))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
1998-01-12 23:48:17 +03:00
|
|
|
pcb[2+i] = bus_space_read_1(iot, ioh, EG_COMMAND);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCBready(iot, ioh))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCBstat(iot, ioh, EG_PCB_DONE))
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
2003-10-30 04:58:17 +03:00
|
|
|
if (bus_space_read_1(iot, ioh, EG_COMMAND) != pcb[1] + 2) {
|
1994-08-23 21:59:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
|
|
|
(bus_space_read_1(iot, ioh, EG_CONTROL) &
|
1996-08-03 06:12:46 +04:00
|
|
|
~EG_PCB_STAT) | EG_PCB_ACCEPT);
|
1995-07-24 01:14:31 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
return 0;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Real stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2009-05-12 13:10:15 +04:00
|
|
|
egprobe(device_t parent, cfdata_t match, void *aux)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1996-08-03 06:12:46 +04:00
|
|
|
int i, rval;
|
1998-01-12 23:48:17 +03:00
|
|
|
static u_int8_t pcb[EG_PCBLEN];
|
1996-08-03 06:12:46 +04:00
|
|
|
|
|
|
|
rval = 0;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2008-03-30 19:27:24 +04:00
|
|
|
/*
|
|
|
|
* XXX This probe is slow. If there are no ISA expansion slots,
|
|
|
|
* then skip it.
|
|
|
|
*/
|
|
|
|
if (isa_get_slotcount() == 0)
|
|
|
|
return (0);
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
|
|
|
return (0);
|
|
|
|
if (ia->ia_nirq < 1)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
|
|
|
return (0);
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1997-10-19 22:56:39 +04:00
|
|
|
/* Disallow wildcarded i/o address. */
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
1997-10-19 22:56:39 +04:00
|
|
|
return (0);
|
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
/* Disallow wildcarded IRQ. */
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
|
2002-01-08 00:46:56 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if ((ia->ia_io[0].ir_addr & ~0x07f0) != 0) {
|
|
|
|
DPRINTF(("Weird iobase %x\n", ia->ia_io[0].ir_addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
/* Map i/o space. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, 0x08, 0, &ioh)) {
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("egprobe: can't map i/o space in probe\n"));
|
1996-08-03 06:12:46 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/* hard reset card */
|
2005-02-27 03:26:58 +03:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, EG_CTL_RESET);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, 0);
|
2008-03-29 20:13:03 +03:00
|
|
|
for (i = 0; i < 500; i++) {
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(1000);
|
1996-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, EG_STATUS) &
|
2005-02-27 03:26:58 +03:00
|
|
|
EG_PCB_STAT) == EG_PCB_NULL)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, ioh, EG_STATUS) & EG_PCB_STAT) != EG_PCB_NULL) {
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("egprobe: Reset failed\n"));
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1998-01-12 23:48:17 +03:00
|
|
|
pcb[0] = EG_CMD_GETINFO; /* Get Adapter Info */
|
|
|
|
pcb[1] = 0;
|
|
|
|
if (egwritePCB(iot, ioh, pcb) != 0)
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if ((egreadPCB(iot, ioh, pcb) != 0) ||
|
|
|
|
pcb[0] != EG_RSP_GETINFO || /* Get Adapter Info Response */
|
|
|
|
pcb[1] != 0x0a) {
|
|
|
|
egprintpcb(pcb);
|
1996-08-03 06:12:46 +04:00
|
|
|
goto out;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1996-08-03 06:12:46 +04:00
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = 0x08;
|
|
|
|
|
|
|
|
ia->ia_nirq = 1;
|
|
|
|
|
|
|
|
ia->ia_niomem = 0;
|
|
|
|
ia->ia_ndrq = 0;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
rval = 1;
|
|
|
|
|
|
|
|
out:
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_unmap(iot, ioh, 0x08);
|
1996-08-03 06:12:46 +04:00
|
|
|
return rval;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:08:13 +04:00
|
|
|
void
|
2009-05-12 13:10:15 +04:00
|
|
|
egattach(device_t parent, device_t self, void *aux)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
struct eg_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
u_int8_t myaddr[ETHER_ADDR_LEN];
|
1996-08-03 06:12:46 +04:00
|
|
|
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("\n");
|
1996-08-03 06:12:46 +04:00
|
|
|
|
|
|
|
/* Map i/o space. */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (bus_space_map(iot, ia->ia_io[0].ir_addr, 0x08, 0, &ioh)) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "can't map i/o space\n");
|
1996-08-03 06:12:46 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
sc->sc_iot = iot;
|
1996-08-03 06:12:46 +04:00
|
|
|
sc->sc_ioh = ioh;
|
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
sc->eg_pcb[0] = EG_CMD_GETINFO; /* Get Adapter Info */
|
|
|
|
sc->eg_pcb[1] = 0;
|
|
|
|
if (egwritePCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "error requesting adapter info\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (egreadPCB(iot, ioh, sc->eg_pcb) != 0) {
|
|
|
|
egprintpcb(sc->eg_pcb);
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "error reading adapter info\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->eg_pcb[0] != EG_RSP_GETINFO || /* Get Adapter Info Response */
|
|
|
|
sc->eg_pcb[1] != 0x0a) {
|
|
|
|
egprintpcb(sc->eg_pcb);
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "bogus adapter info\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->eg_rom_major = sc->eg_pcb[3];
|
|
|
|
sc->eg_rom_minor = sc->eg_pcb[2];
|
|
|
|
sc->eg_ram = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
egstop(sc);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_GETEADDR; /* Get Station address */
|
|
|
|
sc->eg_pcb[1] = 0;
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egwritePCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "can't send Get Station Address\n");
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "can't read station address\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check Get station address response */
|
2005-02-27 03:26:58 +03:00
|
|
|
if (sc->eg_pcb[0] != EG_RSP_GETEADDR || sc->eg_pcb[1] != 0x06) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "card responded with garbage (1)\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-07-19 00:52:47 +04:00
|
|
|
memcpy(myaddr, &sc->eg_pcb[2], ETHER_ADDR_LEN);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2008-04-09 00:08:49 +04:00
|
|
|
printf("%s: ROM v%d.%02d %dk address %s\n", device_xname(self),
|
1994-08-24 03:40:55 +04:00
|
|
|
sc->eg_rom_major, sc->eg_rom_minor, sc->eg_ram,
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_sprintf(myaddr));
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_SETEADDR; /* Set station address */
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egwritePCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
printf("%s: can't send Set Station Address\n", device_xname(self));
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "can't read Set Station Address status\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
1994-08-24 03:40:55 +04:00
|
|
|
if (sc->eg_pcb[0] != EG_RSP_SETEADDR || sc->eg_pcb[1] != 0x02 ||
|
1994-11-05 00:32:23 +03:00
|
|
|
sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(self, "card responded with garbage (2)\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
/* Initialize ifnet structure. */
|
2008-04-09 00:08:49 +04:00
|
|
|
strlcpy(ifp->if_xname, device_xname(&sc->sc_dev), IFNAMSIZ);
|
1996-05-07 05:55:13 +04:00
|
|
|
ifp->if_softc = sc;
|
1994-08-23 21:59:33 +04:00
|
|
|
ifp->if_start = egstart;
|
|
|
|
ifp->if_ioctl = egioctl;
|
|
|
|
ifp->if_watchdog = egwatchdog;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
|
2000-12-14 09:59:01 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/* Now we can attach the interface. */
|
|
|
|
if_attach(ifp);
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_ifattach(ifp, myaddr);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-01-08 00:46:56 +03:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
|
|
|
|
IST_EDGE, IPL_NET, egintr, sc);
|
1997-10-15 09:55:13 +04:00
|
|
|
|
|
|
|
#if NRND > 0
|
2008-04-09 00:08:49 +04:00
|
|
|
rnd_attach_source(&sc->rnd_source, device_xname(&sc->sc_dev),
|
1999-02-28 20:08:05 +03:00
|
|
|
RND_TYPE_NET, 0);
|
1997-10-15 09:55:13 +04:00
|
|
|
#endif
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
eginit(struct eg_softc *sc)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* soft reset the board */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, EG_CTL_FLSH);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(100);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, EG_CTL_ATTN);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(100);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, 0);
|
1994-08-23 21:59:33 +04:00
|
|
|
delay(200);
|
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_CONFIG82586; /* Configure 82586 */
|
|
|
|
sc->eg_pcb[1] = 2;
|
|
|
|
sc->eg_pcb[2] = 3; /* receive broadcast & multicast */
|
|
|
|
sc->eg_pcb[3] = 0;
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egwritePCB(iot, ioh, sc->eg_pcb) != 0)
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't send Configure 82586\n");
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egreadPCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't read Configure 82586 status\n");
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
} else if (sc->eg_pcb[2] != 0 || sc->eg_pcb[3] != 0)
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "configure card command failed\n");
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_inbuf == NULL) {
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_inbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_inbuf == NULL) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't allocate inbuf\n");
|
1996-08-03 06:12:46 +04:00
|
|
|
panic("eginit");
|
|
|
|
}
|
|
|
|
}
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_incount = 0;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_outbuf == NULL) {
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_outbuf = malloc(EG_BUFLEN, M_TEMP, M_NOWAIT);
|
1996-08-03 06:12:46 +04:00
|
|
|
if (sc->eg_outbuf == NULL) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't allocate outbuf\n");
|
1996-08-03 06:12:46 +04:00
|
|
|
panic("eginit");
|
|
|
|
}
|
|
|
|
}
|
1995-07-24 00:27:48 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL, EG_CTL_CMDE);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
|
|
|
sc->eg_incount = 0;
|
|
|
|
egrecv(sc);
|
|
|
|
|
|
|
|
/* Interface is now `running', with no output active. */
|
1994-08-23 21:59:33 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
1995-07-24 00:54:23 +04:00
|
|
|
/* Attempt to start output, if any. */
|
1994-08-23 21:59:33 +04:00
|
|
|
egstart(ifp);
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egrecv(struct eg_softc *sc)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
while (sc->eg_incount < EG_INLEN) {
|
|
|
|
sc->eg_pcb[0] = EG_CMD_RECVPACKET;
|
|
|
|
sc->eg_pcb[1] = 0x08;
|
|
|
|
sc->eg_pcb[2] = 0; /* address not used.. we send zero */
|
|
|
|
sc->eg_pcb[3] = 0;
|
|
|
|
sc->eg_pcb[4] = 0;
|
|
|
|
sc->eg_pcb[5] = 0;
|
1996-05-07 05:55:13 +04:00
|
|
|
sc->eg_pcb[6] = EG_BUFLEN & 0xff; /* our buffer size */
|
|
|
|
sc->eg_pcb[7] = (EG_BUFLEN >> 8) & 0xff;
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_pcb[8] = 0; /* timeout, 0 == none */
|
|
|
|
sc->eg_pcb[9] = 0;
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egwritePCB(sc->sc_iot, sc->sc_ioh, sc->eg_pcb) != 0)
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
1995-07-24 00:54:23 +04:00
|
|
|
sc->eg_incount++;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egstart(struct ifnet *ifp)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct eg_softc *sc = ifp->if_softc;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct mbuf *m0, *m;
|
2007-03-04 08:59:00 +03:00
|
|
|
char *buffer;
|
1994-08-23 21:59:33 +04:00
|
|
|
int len;
|
1996-08-03 06:12:46 +04:00
|
|
|
u_int16_t *ptr;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
/* Don't transmit if interface is busy or not running */
|
1995-07-24 00:27:48 +04:00
|
|
|
if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
|
1995-07-23 23:45:42 +04:00
|
|
|
return;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1995-07-24 00:27:48 +04:00
|
|
|
loop:
|
1994-08-23 21:59:33 +04:00
|
|
|
/* Dequeue the next datagram. */
|
2000-12-14 09:59:01 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
1995-07-24 00:27:48 +04:00
|
|
|
if (m0 == 0)
|
1995-07-23 23:45:42 +04:00
|
|
|
return;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-07-24 00:27:48 +04:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* We need to use m->m_pkthdr.len, so require the header */
|
1996-08-03 06:12:46 +04:00
|
|
|
if ((m0->m_flags & M_PKTHDR) == 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "no header mbuf\n");
|
1996-08-03 06:12:46 +04:00
|
|
|
panic("egstart");
|
|
|
|
}
|
1999-08-26 02:41:42 +04:00
|
|
|
len = max(m0->m_pkthdr.len, ETHER_MIN_LEN - ETHER_CRC_LEN);
|
1995-07-24 00:27:48 +04:00
|
|
|
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m0);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
sc->eg_pcb[0] = EG_CMD_SENDPACKET;
|
|
|
|
sc->eg_pcb[1] = 0x06;
|
|
|
|
sc->eg_pcb[2] = 0; /* address not used, we send zero */
|
|
|
|
sc->eg_pcb[3] = 0;
|
|
|
|
sc->eg_pcb[4] = 0;
|
|
|
|
sc->eg_pcb[5] = 0;
|
1995-07-24 00:27:48 +04:00
|
|
|
sc->eg_pcb[6] = len; /* length of packet */
|
|
|
|
sc->eg_pcb[7] = len >> 8;
|
1998-01-12 23:48:17 +03:00
|
|
|
if (egwritePCB(iot, ioh, sc->eg_pcb) != 0) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't send Send Packet command\n");
|
1995-07-24 00:27:48 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1996-08-03 06:12:46 +04:00
|
|
|
m_freem(m0);
|
1995-07-24 00:27:48 +04:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = sc->eg_outbuf;
|
|
|
|
for (m = m0; m != 0; m = m->m_next) {
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(buffer, mtod(m, void *), m->m_len);
|
1995-07-24 00:27:48 +04:00
|
|
|
buffer += m->m_len;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
2003-01-16 01:00:43 +03:00
|
|
|
if (len > m0->m_pkthdr.len)
|
|
|
|
memset(buffer, 0, len - m0->m_pkthdr.len);
|
1995-07-24 00:27:48 +04:00
|
|
|
|
1995-07-24 00:54:23 +04:00
|
|
|
/* set direction bit: host -> adapter */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
2005-02-27 03:26:58 +03:00
|
|
|
bus_space_read_1(iot, ioh, EG_CONTROL) & ~EG_CTL_DIR);
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
for (ptr = (u_int16_t *) sc->eg_outbuf; len > 0; len -= 2) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_2(iot, ioh, EG_DATA, *ptr++);
|
|
|
|
while (!(bus_space_read_1(iot, ioh, EG_STATUS) & EG_STAT_HRDY))
|
1995-07-24 00:27:48 +04:00
|
|
|
; /* XXX need timeout here */
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-07-24 00:27:48 +04:00
|
|
|
m_freem(m0);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
egintr(void *arg)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct eg_softc *sc = arg;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1996-08-03 06:12:46 +04:00
|
|
|
int i, len, serviced;
|
|
|
|
u_int16_t *ptr;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 0;
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
while (bus_space_read_1(iot, ioh, EG_STATUS) & EG_STAT_ACRF) {
|
1998-01-12 23:48:17 +03:00
|
|
|
egreadPCB(iot, ioh, sc->eg_pcb);
|
1994-08-24 03:40:55 +04:00
|
|
|
switch (sc->eg_pcb[0]) {
|
1994-08-23 21:59:33 +04:00
|
|
|
case EG_RSP_RECVPACKET:
|
1994-11-05 00:32:23 +03:00
|
|
|
len = sc->eg_pcb[6] | (sc->eg_pcb[7] << 8);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1995-07-24 00:54:23 +04:00
|
|
|
/* Set direction bit : Adapter -> host */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, EG_CONTROL,
|
2005-02-27 03:26:58 +03:00
|
|
|
bus_space_read_1(iot, ioh, EG_CONTROL) | EG_CTL_DIR);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
for (ptr = (u_int16_t *) sc->eg_inbuf;
|
|
|
|
len > 0; len -= 2) {
|
1996-10-22 02:34:38 +04:00
|
|
|
while (!(bus_space_read_1(iot, ioh, EG_STATUS) &
|
1996-08-03 06:12:46 +04:00
|
|
|
EG_STAT_HRDY))
|
1994-08-23 21:59:33 +04:00
|
|
|
;
|
1996-10-22 02:34:38 +04:00
|
|
|
*ptr++ = bus_space_read_2(iot, ioh, EG_DATA);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1994-11-05 00:32:23 +03:00
|
|
|
len = sc->eg_pcb[8] | (sc->eg_pcb[9] << 8);
|
1994-08-23 21:59:33 +04:00
|
|
|
egread(sc, sc->eg_inbuf, len);
|
1995-07-24 00:54:23 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
sc->eg_incount--;
|
1995-07-24 00:54:23 +04:00
|
|
|
egrecv(sc);
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EG_RSP_SENDPACKET:
|
|
|
|
if (sc->eg_pcb[6] || sc->eg_pcb[7]) {
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("%s: packet dropped\n",
|
2008-04-09 00:08:49 +04:00
|
|
|
device_xname(&sc->sc_dev)));
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_oerrors++;
|
1994-08-24 03:40:55 +04:00
|
|
|
} else
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_opackets++;
|
|
|
|
sc->sc_ethercom.ec_if.if_collisions +=
|
1996-08-03 06:12:46 +04:00
|
|
|
sc->eg_pcb[8] & 0xf;
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
|
|
|
|
egstart(&sc->sc_ethercom.ec_if);
|
1996-08-03 06:12:46 +04:00
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
/* XXX byte-order and type-size bugs here... */
|
1994-08-23 21:59:33 +04:00
|
|
|
case EG_RSP_GETSTATS:
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("%s: Card Statistics\n",
|
2008-04-09 00:08:49 +04:00
|
|
|
device_xname(&sc->sc_dev)));
|
2001-07-19 00:52:47 +04:00
|
|
|
memcpy(&i, &sc->eg_pcb[2], sizeof(i));
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("Receive Packets %d\n", i));
|
2001-07-19 00:52:47 +04:00
|
|
|
memcpy(&i, &sc->eg_pcb[6], sizeof(i));
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("Transmit Packets %d\n", i));
|
|
|
|
DPRINTF(("CRC errors %d\n",
|
1996-08-03 06:12:46 +04:00
|
|
|
*(short *) &sc->eg_pcb[10]));
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("alignment errors %d\n",
|
1996-08-03 06:12:46 +04:00
|
|
|
*(short *) &sc->eg_pcb[12]));
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("no resources errors %d\n",
|
1996-08-03 06:12:46 +04:00
|
|
|
*(short *) &sc->eg_pcb[14]));
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("overrun errors %d\n",
|
1996-08-03 06:12:46 +04:00
|
|
|
*(short *) &sc->eg_pcb[16]));
|
|
|
|
serviced = 1;
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
default:
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: egintr: Unknown response %x??\n",
|
2008-04-09 00:08:49 +04:00
|
|
|
device_xname(&sc->sc_dev), sc->eg_pcb[0]);
|
1998-01-12 23:48:17 +03:00
|
|
|
egprintpcb(sc->eg_pcb);
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
}
|
1997-10-15 09:55:13 +04:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&sc->rnd_source, sc->eg_pcb[0]);
|
|
|
|
#endif
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1996-08-03 06:12:46 +04:00
|
|
|
return serviced;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet up to the higher levels.
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egread(struct eg_softc *sc, void *buf, int len)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1994-08-23 21:59:33 +04:00
|
|
|
struct mbuf *m;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
if (len <= sizeof(struct ether_header) ||
|
|
|
|
len > ETHER_MAX_LEN) {
|
2008-04-09 00:08:49 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "invalid packet size %d; dropping\n", len);
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ierrors++;
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
/* Pull packet off interface. */
|
1995-07-24 06:02:45 +04:00
|
|
|
m = egget(sc, buf, len);
|
1994-08-23 21:59:33 +04:00
|
|
|
if (m == 0) {
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ierrors++;
|
1994-08-23 21:59:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
1994-08-24 03:40:55 +04:00
|
|
|
* If so, hand off the raw packet to BPF.
|
1994-08-23 21:59:33 +04:00
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1999-05-19 03:52:51 +04:00
|
|
|
(*ifp->if_input)(ifp, m);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert buf into mbufs
|
|
|
|
*/
|
1995-07-24 06:02:45 +04:00
|
|
|
struct mbuf *
|
2009-03-14 18:35:58 +03:00
|
|
|
egget(struct eg_softc *sc, void *buf, int totlen)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1998-12-12 19:58:10 +03:00
|
|
|
struct mbuf *m, *m0, *newm;
|
1994-08-24 03:40:55 +04:00
|
|
|
int len;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
1998-12-12 19:58:10 +03:00
|
|
|
MGETHDR(m0, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m0 == 0)
|
|
|
|
return (0);
|
|
|
|
m0->m_pkthdr.rcvif = ifp;
|
|
|
|
m0->m_pkthdr.len = totlen;
|
1994-08-24 03:40:55 +04:00
|
|
|
len = MHLEN;
|
1998-12-12 19:58:10 +03:00
|
|
|
m = m0;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (totlen >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1998-12-12 19:58:10 +03:00
|
|
|
if ((m->m_flags & M_EXT) == 0)
|
|
|
|
goto bad;
|
1997-04-24 06:04:33 +04:00
|
|
|
len = MCLBYTES;
|
1994-08-24 03:40:55 +04:00
|
|
|
}
|
1998-12-12 19:58:10 +03:00
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
m->m_len = len = min(totlen, len);
|
2007-03-04 08:59:00 +03:00
|
|
|
memcpy(mtod(m, void *), buf, len);
|
|
|
|
buf = (char *)buf + len;
|
1998-12-12 19:58:10 +03:00
|
|
|
|
1994-08-24 03:40:55 +04:00
|
|
|
totlen -= len;
|
1998-12-12 19:58:10 +03:00
|
|
|
if (totlen > 0) {
|
|
|
|
MGET(newm, M_DONTWAIT, MT_DATA);
|
|
|
|
if (newm == 0)
|
|
|
|
goto bad;
|
|
|
|
len = MLEN;
|
|
|
|
m = m->m_next = newm;
|
|
|
|
}
|
1994-08-24 03:40:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-12 19:58:10 +03:00
|
|
|
return (m0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m0);
|
|
|
|
return (0);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
int
|
*** 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
|
|
|
egioctl(struct ifnet *ifp, unsigned long cmd, void *data)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct eg_softc *sc = ifp->if_softc;
|
1995-07-24 06:02:45 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1994-08-24 03:40:55 +04:00
|
|
|
int s, error = 0;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
switch (cmd) {
|
1994-08-23 21:59:33 +04:00
|
|
|
|
*** 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:
|
1994-08-23 21:59:33 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
*** 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
|
|
|
eginit(sc);
|
1994-08-23 21:59:33 +04:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1997-03-15 21:09:08 +03:00
|
|
|
arp_ifinit(ifp, ifa);
|
1994-08-23 21:59:33 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
case SIOCSIFFLAGS:
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
if ((error = ifioctl_common(ifp, cmd, data)) != 0)
|
|
|
|
break;
|
|
|
|
/* XXX re-use ether_ioctl() */
|
|
|
|
switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
|
|
|
|
case IFF_RUNNING:
|
1994-08-24 03:40:55 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
egstop(sc);
|
1994-08-24 03:40:55 +04:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
*** Summary ***
When a link-layer address changes (e.g., ifconfig ex0 link
02:de:ad:be:ef:02 active), send a gratuitous ARP and/or a Neighbor
Advertisement to update the network-/link-layer address bindings
on our LAN peers.
Refuse a change of ethernet address to the address 00:00:00:00:00:00
or to any multicast/broadcast address. (Thanks matt@.)
Reorder ifnet ioctl operations so that driver ioctls may inherit
the functions of their "class"---ether_ioctl(), fddi_ioctl(), et
cetera---and the class ioctls may inherit from the generic ioctl,
ifioctl_common(), but both driver- and class-ioctls may override
the generic behavior. Make network drivers share more code.
Distinguish a "factory" link-layer address from others for the
purposes of both protecting that address from deletion and computing
EUI64.
Return consistent, appropriate error codes from network drivers.
Improve readability. KNF.
*** Details ***
In if_attach(), always initialize the interface ioctl routine,
ifnet->if_ioctl, if the driver has not already initialized it.
Delete if_ioctl == NULL tests everywhere else, because it cannot
happen.
In the ioctl routines of network interfaces, inherit common ioctl
behaviors by calling either ifioctl_common() or whichever ioctl
routine is appropriate for the class of interface---e.g., ether_ioctl()
for ethernets.
Stop (ab)using SIOCSIFADDR and start to use SIOCINITIFADDR. In
the user->kernel interface, SIOCSIFADDR's argument was an ifreq,
but on the protocol->ifnet interface, SIOCSIFADDR's argument was
an ifaddr. That was confusing, and it would work against me as I
make it possible for a network interface to overload most ioctls.
On the protocol->ifnet interface, replace SIOCSIFADDR with
SIOCINITIFADDR. In ifioctl(), return EPERM if userland tries to
invoke SIOCINITIFADDR.
In ifioctl(), give the interface the first shot at handling most
interface ioctls, and give the protocol the second shot, instead
of the other way around. Finally, let compatibility code (COMPAT_OSOCK)
take a shot.
Pull device initialization out of switch statements under
SIOCINITIFADDR. For example, pull ..._init() out of any switch
statement that looks like this:
switch (...->sa_family) {
case ...:
..._init();
...
break;
...
default:
..._init();
...
break;
}
Rewrite many if-else clauses that handle all permutations of IFF_UP
and IFF_RUNNING to use a switch statement,
switch (x & (IFF_UP|IFF_RUNNING)) {
case 0:
...
break;
case IFF_RUNNING:
...
break;
case IFF_UP:
...
break;
case IFF_UP|IFF_RUNNING:
...
break;
}
unifdef lots of code containing #ifdef FreeBSD, #ifdef NetBSD, and
#ifdef SIOCSIFMTU, especially in fwip(4) and in ndis(4).
In ipw(4), remove an if_set_sadl() call that is out of place.
In nfe(4), reuse the jumbo MTU logic in ether_ioctl().
Let ethernets register a callback for setting h/w state such as
promiscuous mode and the multicast filter in accord with a change
in the if_flags: ether_set_ifflags_cb() registers a callback that
returns ENETRESET if the caller should reset the ethernet by calling
if_init(), 0 on success, != 0 on failure. Pull common code from
ex(4), gem(4), nfe(4), sip(4), tlp(4), vge(4) into ether_ioctl(),
and register if_flags callbacks for those drivers.
Return ENOTTY instead of EINVAL for inappropriate ioctls. In
zyd(4), use ENXIO instead of ENOTTY to indicate that the device is
not any longer attached.
Add to if_set_sadl() a boolean 'factory' argument that indicates
whether a link-layer address was assigned by the factory or some
other source. In a comment, recommend using the factory address
for generating an EUI64, and update in6_get_hw_ifid() to prefer a
factory address to any other link-layer address.
Add a routing message, RTM_LLINFO_UPD, that tells protocols to
update the binding of network-layer addresses to link-layer addresses.
Implement this message in IPv4 and IPv6 by sending a gratuitous
ARP or a neighbor advertisement, respectively. Generate RTM_LLINFO_UPD
messages on a change of an interface's link-layer address.
In ether_ioctl(), do not let SIOCALIFADDR set a link-layer address
that is broadcast/multicast or equal to 00:00:00:00:00:00.
Make ether_ioctl() call ifioctl_common() to handle ioctls that it
does not understand.
In gif(4), initialize if_softc and use it, instead of assuming that
the gif_softc and ifp overlap.
Let ifioctl_common() handle SIOCGIFADDR.
Sprinkle rtcache_invariants(), which checks on DIAGNOSTIC kernels
that certain invariants on a struct route are satisfied.
In agr(4), rewrite agr_ioctl_filter() to be a bit more explicit
about the ioctls that we do not allow on an agr(4) member interface.
bzero -> memset. Delete unnecessary casts to void *. Use
sockaddr_in_init() and sockaddr_in6_init(). Compare pointers with
NULL instead of "testing truth". Replace some instances of (type
*)0 with NULL. Change some K&R prototypes to ANSI C, and join
lines.
2008-11-07 03:20:01 +03:00
|
|
|
break;
|
|
|
|
case IFF_UP:
|
1994-08-24 03:40:55 +04:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
1994-08-23 21:59:33 +04:00
|
|
|
eginit(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:
|
1994-08-26 00:18:25 +04:00
|
|
|
sc->eg_pcb[0] = EG_CMD_GETSTATS;
|
|
|
|
sc->eg_pcb[1] = 0;
|
2006-10-04 19:49:59 +04:00
|
|
|
if (egwritePCB(sc->sc_iot, sc->sc_ioh, sc->eg_pcb) != 0) {
|
1996-10-11 02:04:48 +04:00
|
|
|
DPRINTF(("write error\n"));
|
2006-10-04 19:49:59 +04:00
|
|
|
}
|
1994-08-23 21:59:33 +04:00
|
|
|
/*
|
|
|
|
* XXX deal with flags changes:
|
|
|
|
* IFF_MULTICAST, IFF_PROMISC,
|
|
|
|
* IFF_LINK0, IFF_LINK1,
|
|
|
|
*/
|
*** 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;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
break;
|
1994-08-24 03:40:55 +04:00
|
|
|
|
1994-08-23 21:59:33 +04:00
|
|
|
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);
|
1995-07-24 06:02:45 +04:00
|
|
|
break;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
1994-08-24 03:40:55 +04:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return error;
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egreset(struct eg_softc *sc)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1994-08-24 03:40:55 +04:00
|
|
|
int s;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2008-04-09 00:08:49 +04:00
|
|
|
DPRINTF(("%s: egreset()\n", device_xname(&sc->sc_dev)));
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-08-24 03:40:55 +04:00
|
|
|
egstop(sc);
|
|
|
|
eginit(sc);
|
|
|
|
splx(s);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egwatchdog(struct ifnet *ifp)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
1996-05-07 05:55:13 +04:00
|
|
|
struct eg_softc *sc = ifp->if_softc;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
2008-04-09 00:08:49 +04:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", device_xname(&sc->sc_dev));
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_oerrors++;
|
1994-08-23 21:59:33 +04:00
|
|
|
|
|
|
|
egreset(sc);
|
|
|
|
}
|
|
|
|
|
1995-07-24 06:02:45 +04:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
egstop(struct eg_softc *sc)
|
1994-08-23 21:59:33 +04:00
|
|
|
{
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, EG_CONTROL, 0);
|
1994-08-23 21:59:33 +04:00
|
|
|
}
|