2002-10-02 20:33:28 +04:00
|
|
|
/* $NetBSD: ofnet.c,v 1.29 2002/10/02 16:34:34 thorpej Exp $ */
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1995, 1996 TooLs GmbH.
|
|
|
|
* 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 TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
|
|
|
|
*/
|
2001-11-13 10:24:43 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 20:33:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ofnet.c,v 1.29 2002/10/02 16:34:34 thorpej Exp $");
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
#include "ofnet.h"
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1996-09-30 20:34:14 +04:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1998-06-11 02:58:05 +04:00
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1996-09-30 20:34:14 +04:00
|
|
|
#include <sys/device.h>
|
2001-08-26 06:49:18 +04:00
|
|
|
#include <sys/disk.h>
|
1996-09-30 20:34:14 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1996-09-30 20:34:14 +04:00
|
|
|
#endif
|
|
|
|
|
1997-04-17 03:41:19 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
#if NIPKDB_OFN > 0
|
|
|
|
#include <ipkdb/ipkdb.h>
|
|
|
|
#include <machine/ipkdb.h>
|
1996-09-30 20:34:14 +04:00
|
|
|
|
2002-10-01 01:57:46 +04:00
|
|
|
CFATTACH_DECL(ipkdb_ofn, 0,
|
2002-10-02 20:33:28 +04:00
|
|
|
ipkdb_probe, ipkdb_attach, NULL, NULL);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
static struct ipkdb_if *kifp;
|
1998-02-24 08:44:39 +03:00
|
|
|
static struct ofnet_softc *ipkdb_of;
|
1996-09-30 20:34:14 +04:00
|
|
|
|
2001-08-26 06:49:18 +04:00
|
|
|
static int ipkdbprobe (struct cfdata *, void *);
|
1996-09-30 20:34:14 +04:00
|
|
|
#endif
|
|
|
|
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofnet_softc {
|
1996-09-30 20:34:14 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
int sc_phandle;
|
|
|
|
int sc_ihandle;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ethercom sc_ethercom;
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout sc_callout;
|
1996-09-30 20:34:14 +04:00
|
|
|
};
|
|
|
|
|
2001-08-26 06:49:18 +04:00
|
|
|
static int ofnet_match (struct device *, struct cfdata *, void *);
|
|
|
|
static void ofnet_attach (struct device *, struct device *, void *);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
2002-10-02 06:16:10 +04:00
|
|
|
CFATTACH_DECL(ofnet, sizeof(struct ofnet_softc),
|
|
|
|
ofnet_match, ofnet_attach, NULL, NULL);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
2001-08-26 06:49:18 +04:00
|
|
|
static void ofnet_read (struct ofnet_softc *);
|
|
|
|
static void ofnet_timer (void *);
|
|
|
|
static void ofnet_init (struct ofnet_softc *);
|
|
|
|
static void ofnet_stop (struct ofnet_softc *);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
2001-08-26 06:49:18 +04:00
|
|
|
static void ofnet_start (struct ifnet *);
|
|
|
|
static int ofnet_ioctl (struct ifnet *, u_long, caddr_t);
|
|
|
|
static void ofnet_watchdog (struct ifnet *);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
static int
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_match(struct device *parent, struct cfdata *match, void *aux)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
1996-09-30 20:34:14 +04:00
|
|
|
char type[32];
|
|
|
|
int l;
|
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
#if NIPKDB_OFN > 0
|
1996-09-30 20:34:14 +04:00
|
|
|
if (!parent)
|
1996-10-16 23:32:08 +04:00
|
|
|
return ipkdbprobe(match, aux);
|
1996-09-30 20:34:14 +04:00
|
|
|
#endif
|
1998-02-24 08:44:39 +03:00
|
|
|
if (strcmp(oba->oba_busname, "ofw"))
|
|
|
|
return (0);
|
|
|
|
if ((l = OF_getprop(oba->oba_phandle, "device_type", type,
|
|
|
|
sizeof type - 1)) < 0)
|
1996-09-30 20:34:14 +04:00
|
|
|
return 0;
|
|
|
|
if (l >= sizeof type)
|
|
|
|
return 0;
|
|
|
|
type[l] = 0;
|
|
|
|
if (strcmp(type, "network"))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_attach(struct device *parent, struct device *self, void *aux)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofnet_softc *of = (void *)self;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &of->sc_ethercom.ec_if;
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofbus_attach_args *oba = aux;
|
1996-09-30 20:34:14 +04:00
|
|
|
char path[256];
|
|
|
|
int l;
|
1997-03-15 21:09:08 +03:00
|
|
|
u_int8_t myaddr[ETHER_ADDR_LEN];
|
1996-09-30 20:34:14 +04:00
|
|
|
|
1998-02-24 08:44:39 +03:00
|
|
|
of->sc_phandle = oba->oba_phandle;
|
1996-10-16 23:32:08 +04:00
|
|
|
#if NIPKDB_OFN > 0
|
1998-02-24 08:44:39 +03:00
|
|
|
if (kifp &&
|
|
|
|
kifp->unit - 1 == of->sc_dev.dv_unit &&
|
|
|
|
OF_instance_to_package(kifp->port) == oba->oba_phandle) {
|
1996-10-16 23:32:08 +04:00
|
|
|
ipkdb_of = of;
|
1996-09-30 20:34:14 +04:00
|
|
|
of->sc_ihandle = kifp->port;
|
|
|
|
} else
|
|
|
|
#endif
|
1998-02-24 08:44:39 +03:00
|
|
|
if ((l = OF_package_to_path(oba->oba_phandle, path,
|
|
|
|
sizeof path - 1)) < 0 ||
|
|
|
|
l >= sizeof path ||
|
|
|
|
(path[l] = 0, !(of->sc_ihandle = OF_open(path))))
|
|
|
|
panic("ofnet_attach: unable to open");
|
|
|
|
if (OF_getprop(oba->oba_phandle, "mac-address", myaddr,
|
|
|
|
sizeof myaddr) < 0)
|
|
|
|
panic("ofnet_attach: no mac-address");
|
1997-03-15 21:09:08 +03:00
|
|
|
printf(": address %s\n", ether_sprintf(myaddr));
|
2000-03-23 10:01:25 +03:00
|
|
|
|
|
|
|
callout_init(&of->sc_callout);
|
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
bcopy(of->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = of;
|
1998-02-24 08:44:39 +03:00
|
|
|
ifp->if_start = ofnet_start;
|
|
|
|
ifp->if_ioctl = ofnet_ioctl;
|
|
|
|
ifp->if_watchdog = ofnet_watchdog;
|
1996-09-30 20:34:14 +04:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
|
2002-03-05 07:12:57 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
if_attach(ifp);
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_ifattach(ifp, myaddr);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static char buf[ETHERMTU + sizeof(struct ether_header)];
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_read(struct ofnet_softc *of)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &of->sc_ethercom.ec_if;
|
1996-09-30 20:34:14 +04:00
|
|
|
struct mbuf *m, **mp, *head;
|
2002-09-18 05:47:08 +04:00
|
|
|
int s, l, len;
|
1996-09-30 20:34:14 +04:00
|
|
|
char *bufp;
|
|
|
|
|
2002-09-18 05:47:08 +04:00
|
|
|
s = splnet();
|
1996-10-16 23:32:08 +04:00
|
|
|
#if NIPKDB_OFN > 0
|
|
|
|
ipkdbrint(kifp, ifp);
|
1996-09-30 20:34:14 +04:00
|
|
|
#endif
|
2002-09-18 05:47:08 +04:00
|
|
|
for (;;) {
|
1996-09-30 20:34:14 +04:00
|
|
|
if ((len = OF_read(of->sc_ihandle, buf, sizeof buf)) < 0) {
|
1997-04-28 22:32:58 +04:00
|
|
|
if (len == -2 || len == 0)
|
2002-09-18 05:47:08 +04:00
|
|
|
break;
|
1996-09-30 20:34:14 +04:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (len < sizeof(struct ether_header)) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bufp = buf;
|
2001-10-20 12:19:47 +04:00
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
/* Allocate a header mbuf */
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = len;
|
2001-10-20 12:19:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't know if the interface included the FCS
|
|
|
|
* or not. For now, assume that it did if we got
|
|
|
|
* a packet length that looks like it could include
|
|
|
|
* the FCS.
|
|
|
|
*
|
|
|
|
* XXX Yuck.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN))
|
|
|
|
m->m_flags |= M_HASFCS;
|
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
l = MHLEN;
|
|
|
|
head = 0;
|
|
|
|
mp = &head;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
if (head) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
m_freem(head);
|
|
|
|
head = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
l = MLEN;
|
|
|
|
}
|
|
|
|
if (len >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1997-04-24 12:05:13 +04:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
ifp->if_ierrors++;
|
1997-04-28 22:32:58 +04:00
|
|
|
m_free(m);
|
1997-04-24 06:04:33 +04:00
|
|
|
m_freem(head);
|
|
|
|
head = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
l = MCLBYTES;
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
1998-01-28 02:55:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the data after the Ethernet header
|
|
|
|
* is aligned.
|
|
|
|
*
|
|
|
|
* XXX Assumes the device is an ethernet, but
|
|
|
|
* XXX then so does other code in this driver.
|
|
|
|
*/
|
|
|
|
if (head == NULL) {
|
|
|
|
caddr_t newdata = (caddr_t)ALIGN(m->m_data +
|
|
|
|
sizeof(struct ether_header)) -
|
|
|
|
sizeof(struct ether_header);
|
|
|
|
l -= newdata - m->m_data;
|
|
|
|
m->m_data = newdata;
|
|
|
|
}
|
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
m->m_len = l = min(len, l);
|
|
|
|
bcopy(bufp, mtod(m, char *), l);
|
|
|
|
bufp += l;
|
|
|
|
len -= l;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
|
|
|
if (head == 0)
|
|
|
|
continue;
|
|
|
|
|
1997-04-17 03:41:19 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
1996-09-30 20:34:14 +04:00
|
|
|
#endif
|
|
|
|
ifp->if_ipackets++;
|
1999-05-19 03:52:51 +04:00
|
|
|
(*ifp->if_input)(ifp, head);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
2002-09-18 05:47:08 +04:00
|
|
|
splx(s);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-05-05 03:55:27 +04:00
|
|
|
ofnet_timer(arg)
|
|
|
|
void *arg;
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1999-05-05 03:55:27 +04:00
|
|
|
struct ofnet_softc *of = arg;
|
|
|
|
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_read(of);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&of->sc_callout, 1, ofnet_timer, of);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_init(struct ofnet_softc *of)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &of->sc_ethercom.ec_if;
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
/* Start reading from interface */
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_timer(of);
|
1996-09-30 20:34:14 +04:00
|
|
|
/* Attempt to start output */
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_start(ifp);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_stop(struct ofnet_softc *of)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&of->sc_callout);
|
1997-03-15 21:09:08 +03:00
|
|
|
of->sc_ethercom.ec_if.if_flags &= ~IFF_RUNNING;
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_start(struct ifnet *ifp)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofnet_softc *of = ifp->if_softc;
|
1996-09-30 20:34:14 +04:00
|
|
|
struct mbuf *m, *m0;
|
|
|
|
char *bufp;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!(ifp->if_flags & IFF_RUNNING))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* First try reading any packets */
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_read(of);
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
/* Now get the first packet on the queue */
|
2002-03-05 07:12:57 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
1996-09-30 20:34:14 +04:00
|
|
|
if (!m0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(m0->m_flags & M_PKTHDR))
|
1998-02-24 08:44:39 +03:00
|
|
|
panic("ofnet_start: no header mbuf");
|
1996-09-30 20:34:14 +04:00
|
|
|
len = m0->m_pkthdr.len;
|
1997-04-17 03:41:19 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
|
|
|
#endif
|
|
|
|
|
1996-09-30 20:34:14 +04:00
|
|
|
if (len > ETHERMTU + sizeof(struct ether_header)) {
|
|
|
|
/* packet too large, toss it */
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
m_freem(m0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-08-26 06:49:18 +04:00
|
|
|
for (bufp = buf; (m = m0) != NULL;) {
|
1996-09-30 20:34:14 +04:00
|
|
|
bcopy(mtod(m, char *), bufp, m->m_len);
|
|
|
|
bufp += m->m_len;
|
|
|
|
MFREE(m, m0);
|
|
|
|
}
|
2001-10-20 12:19:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't know if the interface will auto-pad for
|
|
|
|
* us, so make sure it's at least as large as a
|
|
|
|
* minimum size Ethernet packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
|
|
|
|
len = ETHER_MIN_LEN - ETHER_CRC_LEN;
|
|
|
|
else
|
|
|
|
len = bufp - buf;
|
|
|
|
|
|
|
|
if (OF_write(of->sc_ihandle, buf, len) != len)
|
1996-09-30 20:34:14 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
else
|
|
|
|
ifp->if_opackets++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofnet_softc *of = ifp->if_softc;
|
1996-09-30 20:34:14 +04:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
2001-08-26 06:49:18 +04:00
|
|
|
/* struct ifreq *ifr = (struct ifreq *)data; */
|
1996-09-30 20:34:14 +04:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1997-03-15 21:09:08 +03:00
|
|
|
arp_ifinit(ifp, ifa);
|
1996-09-30 20:34:14 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_init(of);
|
1996-09-30 20:34:14 +04:00
|
|
|
break;
|
|
|
|
case SIOCSIFFLAGS:
|
1998-02-24 08:44:39 +03:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
1996-09-30 20:34:14 +04:00
|
|
|
/* If interface is down, but running, stop it. */
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_stop(of);
|
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
1996-09-30 20:34:14 +04:00
|
|
|
/* If interface is up, but not running, start it. */
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_init(of);
|
1996-09-30 20:34:14 +04:00
|
|
|
} else {
|
|
|
|
/* Other flags are ignored. */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ofnet_watchdog(struct ifnet *ifp)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1998-02-24 08:44:39 +03:00
|
|
|
struct ofnet_softc *of = ifp->if_softc;
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
log(LOG_ERR, "%s: device timeout\n", of->sc_dev.dv_xname);
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp->if_oerrors++;
|
1998-02-24 08:44:39 +03:00
|
|
|
ofnet_stop(of);
|
|
|
|
ofnet_init(of);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
#if NIPKDB_OFN > 0
|
1996-09-30 20:34:14 +04:00
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ipkdbofstart(struct ipkdb_if *kip)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
|
|
|
int unit = kip->unit - 1;
|
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
if (ipkdb_of)
|
1997-03-15 21:09:08 +03:00
|
|
|
ipkdbattach(kip, &ipkdb_of->sc_ethercom);
|
1996-09-30 20:34:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ipkdbofleave(struct ipkdb_if *kip)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-08-26 06:49:18 +04:00
|
|
|
ipkdbofrcv(struct ipkdb_if *kip, u_char *buf, int poll)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
|
|
|
int l;
|
|
|
|
|
|
|
|
do {
|
|
|
|
l = OF_read(kip->port, buf, ETHERMTU);
|
|
|
|
if (l < 0)
|
|
|
|
l = 0;
|
|
|
|
} while (!poll && !l);
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-26 06:49:18 +04:00
|
|
|
ipkdbofsend(struct ipkdb_if *kip, u_char *buf, int l)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
|
|
|
OF_write(kip->port, buf, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-08-26 06:49:18 +04:00
|
|
|
ipkdbprobe(struct cfdata *match, void *aux)
|
1996-09-30 20:34:14 +04:00
|
|
|
{
|
1996-10-16 23:32:08 +04:00
|
|
|
struct ipkdb_if *kip = aux;
|
1996-09-30 20:34:14 +04:00
|
|
|
static char name[256];
|
|
|
|
int len;
|
|
|
|
int phandle;
|
|
|
|
|
1997-04-17 03:41:19 +04:00
|
|
|
kip->unit = match->cf_unit + 1;
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
if (!(kip->port = OF_open("net")))
|
|
|
|
return -1;
|
1998-02-24 08:44:39 +03:00
|
|
|
if ((len = OF_instance_to_path(kip->port, name, sizeof name - 1)) < 0 ||
|
|
|
|
len >= sizeof name)
|
1996-09-30 20:34:14 +04:00
|
|
|
return -1;
|
|
|
|
name[len] = 0;
|
|
|
|
if ((phandle = OF_instance_to_package(kip->port)) == -1)
|
|
|
|
return -1;
|
1998-02-24 08:44:39 +03:00
|
|
|
if (OF_getprop(phandle, "mac-address", kip->myenetaddr,
|
|
|
|
sizeof kip->myenetaddr) < 0)
|
1996-09-30 20:34:14 +04:00
|
|
|
return -1;
|
|
|
|
|
1996-10-16 23:32:08 +04:00
|
|
|
kip->flags |= IPKDB_MYHW;
|
1996-09-30 20:34:14 +04:00
|
|
|
kip->name = name;
|
1996-10-16 23:32:08 +04:00
|
|
|
kip->start = ipkdbofstart;
|
|
|
|
kip->leave = ipkdbofleave;
|
|
|
|
kip->receive = ipkdbofrcv;
|
|
|
|
kip->send = ipkdbofsend;
|
1996-09-30 20:34:14 +04:00
|
|
|
|
|
|
|
kifp = kip;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|