Home | History | Annotate | Line # | Download | only in ofw
ofnet.c revision 1.27
      1  1.27   thorpej /*	$NetBSD: ofnet.c,v 1.27 2002/09/30 22:10:08 thorpej Exp $	*/
      2   1.1        ws 
      3   1.1        ws /*
      4   1.1        ws  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5   1.1        ws  * Copyright (C) 1995, 1996 TooLs GmbH.
      6   1.1        ws  * All rights reserved.
      7   1.1        ws  *
      8   1.1        ws  * Redistribution and use in source and binary forms, with or without
      9   1.1        ws  * modification, are permitted provided that the following conditions
     10   1.1        ws  * are met:
     11   1.1        ws  * 1. Redistributions of source code must retain the above copyright
     12   1.1        ws  *    notice, this list of conditions and the following disclaimer.
     13   1.1        ws  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1        ws  *    notice, this list of conditions and the following disclaimer in the
     15   1.1        ws  *    documentation and/or other materials provided with the distribution.
     16   1.1        ws  * 3. All advertising materials mentioning features or use of this software
     17   1.1        ws  *    must display the following acknowledgement:
     18   1.1        ws  *	This product includes software developed by TooLs GmbH.
     19   1.1        ws  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20   1.1        ws  *    derived from this software without specific prior written permission.
     21   1.1        ws  *
     22   1.1        ws  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23   1.1        ws  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1        ws  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1        ws  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26   1.1        ws  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27   1.1        ws  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28   1.1        ws  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29   1.1        ws  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30   1.1        ws  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31   1.1        ws  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1        ws  */
     33  1.23     lukem 
     34  1.23     lukem #include <sys/cdefs.h>
     35  1.27   thorpej __KERNEL_RCSID(0, "$NetBSD: ofnet.c,v 1.27 2002/09/30 22:10:08 thorpej Exp $");
     36  1.23     lukem 
     37   1.1        ws #include "ofnet.h"
     38  1.15  jonathan #include "opt_inet.h"
     39   1.1        ws #include "bpfilter.h"
     40   1.1        ws 
     41   1.1        ws #include <sys/param.h>
     42  1.14        tv #include <sys/systm.h>
     43  1.18   thorpej #include <sys/callout.h>
     44   1.1        ws #include <sys/device.h>
     45  1.21      matt #include <sys/disk.h>
     46   1.1        ws #include <sys/ioctl.h>
     47   1.1        ws #include <sys/mbuf.h>
     48   1.1        ws #include <sys/socket.h>
     49   1.1        ws #include <sys/syslog.h>
     50   1.1        ws 
     51   1.1        ws #include <net/if.h>
     52   1.5        is #include <net/if_ether.h>
     53   1.1        ws 
     54   1.1        ws #ifdef INET
     55   1.1        ws #include <netinet/in.h>
     56   1.5        is #include <netinet/if_inarp.h>
     57   1.1        ws #endif
     58   1.1        ws 
     59   1.6   thorpej #if NBPFILTER > 0
     60   1.6   thorpej #include <net/bpf.h>
     61   1.6   thorpej #include <net/bpfdesc.h>
     62   1.6   thorpej #endif
     63   1.6   thorpej 
     64   1.1        ws #include <dev/ofw/openfirm.h>
     65   1.1        ws 
     66   1.4        ws #if NIPKDB_OFN > 0
     67   1.4        ws #include <ipkdb/ipkdb.h>
     68   1.4        ws #include <machine/ipkdb.h>
     69   1.1        ws 
     70  1.27   thorpej CFATTACH_DECL(ipkdb_ofn, 0,
     71  1.27   thorpej     ipkdb_probe, ipkdb_attach, NULL, NULL)
     72   1.1        ws 
     73   1.4        ws static struct ipkdb_if *kifp;
     74  1.13   mycroft static struct ofnet_softc *ipkdb_of;
     75   1.1        ws 
     76  1.21      matt static int ipkdbprobe (struct cfdata *, void *);
     77   1.1        ws #endif
     78   1.1        ws 
     79  1.13   mycroft struct ofnet_softc {
     80   1.1        ws 	struct device sc_dev;
     81   1.1        ws 	int sc_phandle;
     82   1.1        ws 	int sc_ihandle;
     83   1.5        is 	struct ethercom sc_ethercom;
     84  1.18   thorpej 	struct callout sc_callout;
     85   1.1        ws };
     86   1.1        ws 
     87  1.21      matt static int ofnet_match (struct device *, struct cfdata *, void *);
     88  1.21      matt static void ofnet_attach (struct device *, struct device *, void *);
     89   1.1        ws 
     90  1.26   thorpej const struct cfattach ofnet_ca = {
     91  1.13   mycroft 	sizeof(struct ofnet_softc), ofnet_match, ofnet_attach
     92   1.1        ws };
     93   1.1        ws 
     94  1.21      matt static void ofnet_read (struct ofnet_softc *);
     95  1.21      matt static void ofnet_timer (void *);
     96  1.21      matt static void ofnet_init (struct ofnet_softc *);
     97  1.21      matt static void ofnet_stop (struct ofnet_softc *);
     98  1.21      matt 
     99  1.21      matt static void ofnet_start (struct ifnet *);
    100  1.21      matt static int ofnet_ioctl (struct ifnet *, u_long, caddr_t);
    101  1.21      matt static void ofnet_watchdog (struct ifnet *);
    102   1.1        ws 
    103   1.1        ws static int
    104  1.21      matt ofnet_match(struct device *parent, struct cfdata *match, void *aux)
    105   1.1        ws {
    106  1.13   mycroft 	struct ofbus_attach_args *oba = aux;
    107   1.1        ws 	char type[32];
    108   1.1        ws 	int l;
    109   1.1        ws 
    110   1.4        ws #if NIPKDB_OFN > 0
    111   1.1        ws 	if (!parent)
    112   1.4        ws 		return ipkdbprobe(match, aux);
    113   1.1        ws #endif
    114  1.13   mycroft 	if (strcmp(oba->oba_busname, "ofw"))
    115  1.13   mycroft 		return (0);
    116  1.13   mycroft 	if ((l = OF_getprop(oba->oba_phandle, "device_type", type,
    117  1.13   mycroft 	    sizeof type - 1)) < 0)
    118   1.1        ws 		return 0;
    119   1.1        ws 	if (l >= sizeof type)
    120   1.1        ws 		return 0;
    121   1.1        ws 	type[l] = 0;
    122   1.1        ws 	if (strcmp(type, "network"))
    123   1.1        ws 		return 0;
    124   1.1        ws 	return 1;
    125   1.1        ws }
    126   1.1        ws 
    127   1.1        ws static void
    128  1.21      matt ofnet_attach(struct device *parent, struct device *self, void *aux)
    129   1.1        ws {
    130  1.13   mycroft 	struct ofnet_softc *of = (void *)self;
    131   1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    132  1.13   mycroft 	struct ofbus_attach_args *oba = aux;
    133   1.1        ws 	char path[256];
    134   1.1        ws 	int l;
    135   1.5        is 	u_int8_t myaddr[ETHER_ADDR_LEN];
    136   1.1        ws 
    137  1.13   mycroft 	of->sc_phandle = oba->oba_phandle;
    138   1.4        ws #if NIPKDB_OFN > 0
    139  1.13   mycroft 	if (kifp &&
    140  1.13   mycroft 	    kifp->unit - 1 == of->sc_dev.dv_unit &&
    141  1.13   mycroft 	    OF_instance_to_package(kifp->port) == oba->oba_phandle)  {
    142   1.4        ws 		ipkdb_of = of;
    143   1.1        ws 		of->sc_ihandle = kifp->port;
    144   1.1        ws 	} else
    145   1.1        ws #endif
    146  1.13   mycroft 	if ((l = OF_package_to_path(oba->oba_phandle, path,
    147  1.13   mycroft 	    sizeof path - 1)) < 0 ||
    148  1.13   mycroft 	    l >= sizeof path ||
    149  1.13   mycroft 	    (path[l] = 0, !(of->sc_ihandle = OF_open(path))))
    150  1.13   mycroft 		panic("ofnet_attach: unable to open");
    151  1.13   mycroft 	if (OF_getprop(oba->oba_phandle, "mac-address", myaddr,
    152  1.13   mycroft 	    sizeof myaddr) < 0)
    153  1.13   mycroft 		panic("ofnet_attach: no mac-address");
    154   1.5        is 	printf(": address %s\n", ether_sprintf(myaddr));
    155  1.18   thorpej 
    156  1.18   thorpej 	callout_init(&of->sc_callout);
    157  1.18   thorpej 
    158   1.1        ws 	bcopy(of->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
    159   1.1        ws 	ifp->if_softc = of;
    160  1.13   mycroft 	ifp->if_start = ofnet_start;
    161  1.13   mycroft 	ifp->if_ioctl = ofnet_ioctl;
    162  1.13   mycroft 	ifp->if_watchdog = ofnet_watchdog;
    163   1.1        ws 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
    164  1.24    itojun 	IFQ_SET_READY(&ifp->if_snd);
    165   1.1        ws 
    166   1.1        ws 	if_attach(ifp);
    167   1.5        is 	ether_ifattach(ifp, myaddr);
    168   1.1        ws }
    169   1.1        ws 
    170   1.1        ws static char buf[ETHERMTU + sizeof(struct ether_header)];
    171   1.1        ws 
    172   1.1        ws static void
    173  1.21      matt ofnet_read(struct ofnet_softc *of)
    174   1.1        ws {
    175   1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    176   1.1        ws 	struct mbuf *m, **mp, *head;
    177  1.25       chs 	int s, l, len;
    178   1.1        ws 	char *bufp;
    179   1.1        ws 
    180  1.25       chs 	s = splnet();
    181   1.4        ws #if NIPKDB_OFN > 0
    182   1.4        ws 	ipkdbrint(kifp, ifp);
    183   1.1        ws #endif
    184  1.25       chs 	for (;;) {
    185   1.1        ws 		if ((len = OF_read(of->sc_ihandle, buf, sizeof buf)) < 0) {
    186   1.9   mycroft 			if (len == -2 || len == 0)
    187  1.25       chs 				break;
    188   1.1        ws 			ifp->if_ierrors++;
    189   1.1        ws 			continue;
    190   1.1        ws 		}
    191   1.1        ws 		if (len < sizeof(struct ether_header)) {
    192   1.1        ws 			ifp->if_ierrors++;
    193   1.1        ws 			continue;
    194   1.1        ws 		}
    195   1.1        ws 		bufp = buf;
    196  1.22     billc 
    197   1.1        ws 		/* Allocate a header mbuf */
    198   1.1        ws 		MGETHDR(m, M_DONTWAIT, MT_DATA);
    199   1.1        ws 		if (m == 0) {
    200   1.1        ws 			ifp->if_ierrors++;
    201   1.1        ws 			continue;
    202   1.1        ws 		}
    203   1.1        ws 		m->m_pkthdr.rcvif = ifp;
    204   1.1        ws 		m->m_pkthdr.len = len;
    205  1.22     billc 
    206  1.22     billc 		/*
    207  1.22     billc 		 * We don't know if the interface included the FCS
    208  1.22     billc 		 * or not.  For now, assume that it did if we got
    209  1.22     billc 		 * a packet length that looks like it could include
    210  1.22     billc 		 * the FCS.
    211  1.22     billc  		 *
    212  1.22     billc 		 * XXX Yuck.
    213  1.22     billc 		 */
    214  1.22     billc 
    215  1.22     billc 		if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN))
    216  1.22     billc 			m->m_flags |= M_HASFCS;
    217  1.22     billc 
    218   1.1        ws 		l = MHLEN;
    219   1.1        ws 		head = 0;
    220   1.1        ws 		mp = &head;
    221   1.1        ws 
    222   1.1        ws 		while (len > 0) {
    223   1.1        ws 			if (head) {
    224   1.1        ws 				MGET(m, M_DONTWAIT, MT_DATA);
    225   1.1        ws 				if (m == 0) {
    226   1.1        ws 					ifp->if_ierrors++;
    227   1.1        ws 					m_freem(head);
    228   1.1        ws 					head = 0;
    229   1.1        ws 					break;
    230   1.1        ws 				}
    231   1.1        ws 				l = MLEN;
    232   1.1        ws 			}
    233   1.1        ws 			if (len >= MINCLSIZE) {
    234   1.1        ws 				MCLGET(m, M_DONTWAIT);
    235   1.8   mycroft 				if ((m->m_flags & M_EXT) == 0) {
    236   1.8   mycroft 					ifp->if_ierrors++;
    237   1.9   mycroft 					m_free(m);
    238   1.7   mycroft 					m_freem(head);
    239   1.7   mycroft 					head = 0;
    240   1.7   mycroft 					break;
    241   1.7   mycroft 				}
    242   1.7   mycroft 				l = MCLBYTES;
    243   1.1        ws 			}
    244  1.12       cgd 
    245  1.12       cgd 			/*
    246  1.12       cgd 			 * Make sure the data after the Ethernet header
    247  1.12       cgd 			 * is aligned.
    248  1.12       cgd 			 *
    249  1.12       cgd 			 * XXX Assumes the device is an ethernet, but
    250  1.12       cgd 			 * XXX then so does other code in this driver.
    251  1.12       cgd 			 */
    252  1.12       cgd 			if (head == NULL) {
    253  1.12       cgd 				caddr_t newdata = (caddr_t)ALIGN(m->m_data +
    254  1.12       cgd 				      sizeof(struct ether_header)) -
    255  1.12       cgd 				    sizeof(struct ether_header);
    256  1.12       cgd 				l -= newdata - m->m_data;
    257  1.12       cgd 				m->m_data = newdata;
    258  1.12       cgd 			}
    259  1.12       cgd 
    260   1.1        ws 			m->m_len = l = min(len, l);
    261   1.1        ws 			bcopy(bufp, mtod(m, char *), l);
    262   1.1        ws 			bufp += l;
    263   1.1        ws 			len -= l;
    264   1.1        ws 			*mp = m;
    265   1.1        ws 			mp = &m->m_next;
    266   1.1        ws 		}
    267   1.1        ws 		if (head == 0)
    268   1.1        ws 			continue;
    269   1.1        ws 
    270   1.6   thorpej #if NBPFILTER > 0
    271   1.6   thorpej 		if (ifp->if_bpf)
    272   1.6   thorpej 			bpf_mtap(ifp->if_bpf, m);
    273   1.1        ws #endif
    274   1.1        ws 		ifp->if_ipackets++;
    275  1.17   thorpej 		(*ifp->if_input)(ifp, head);
    276   1.1        ws 	}
    277  1.25       chs 	splx(s);
    278   1.1        ws }
    279   1.1        ws 
    280   1.1        ws static void
    281  1.16   thorpej ofnet_timer(arg)
    282  1.16   thorpej 	void *arg;
    283   1.1        ws {
    284  1.16   thorpej 	struct ofnet_softc *of = arg;
    285  1.16   thorpej 
    286  1.13   mycroft 	ofnet_read(of);
    287  1.18   thorpej 	callout_reset(&of->sc_callout, 1, ofnet_timer, of);
    288   1.1        ws }
    289   1.1        ws 
    290   1.1        ws static void
    291  1.21      matt ofnet_init(struct ofnet_softc *of)
    292   1.1        ws {
    293   1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    294   1.1        ws 
    295   1.1        ws 	if (ifp->if_flags & IFF_RUNNING)
    296   1.1        ws 		return;
    297   1.1        ws 
    298   1.1        ws 	ifp->if_flags |= IFF_RUNNING;
    299   1.1        ws 	/* Start reading from interface */
    300  1.13   mycroft 	ofnet_timer(of);
    301   1.1        ws 	/* Attempt to start output */
    302  1.13   mycroft 	ofnet_start(ifp);
    303   1.1        ws }
    304   1.1        ws 
    305   1.1        ws static void
    306  1.21      matt ofnet_stop(struct ofnet_softc *of)
    307   1.1        ws {
    308  1.18   thorpej 	callout_stop(&of->sc_callout);
    309   1.5        is 	of->sc_ethercom.ec_if.if_flags &= ~IFF_RUNNING;
    310   1.1        ws }
    311   1.1        ws 
    312   1.1        ws static void
    313  1.21      matt ofnet_start(struct ifnet *ifp)
    314   1.1        ws {
    315  1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    316   1.1        ws 	struct mbuf *m, *m0;
    317   1.1        ws 	char *bufp;
    318   1.1        ws 	int len;
    319   1.1        ws 
    320   1.1        ws 	if (!(ifp->if_flags & IFF_RUNNING))
    321   1.1        ws 		return;
    322   1.1        ws 
    323   1.1        ws 	for (;;) {
    324   1.1        ws 		/* First try reading any packets */
    325  1.13   mycroft 		ofnet_read(of);
    326   1.1        ws 
    327   1.1        ws 		/* Now get the first packet on the queue */
    328  1.24    itojun 		IFQ_DEQUEUE(&ifp->if_snd, m0);
    329   1.1        ws 		if (!m0)
    330   1.1        ws 			return;
    331   1.1        ws 
    332   1.1        ws 		if (!(m0->m_flags & M_PKTHDR))
    333  1.13   mycroft 			panic("ofnet_start: no header mbuf");
    334   1.1        ws 		len = m0->m_pkthdr.len;
    335   1.6   thorpej 
    336   1.6   thorpej #if NBPFILTER > 0
    337   1.6   thorpej 		if (ifp->if_bpf)
    338   1.6   thorpej 			bpf_mtap(ifp->if_bpf, m0);
    339   1.6   thorpej #endif
    340   1.6   thorpej 
    341   1.1        ws 		if (len > ETHERMTU + sizeof(struct ether_header)) {
    342   1.1        ws 			/* packet too large, toss it */
    343   1.1        ws 			ifp->if_oerrors++;
    344   1.1        ws 			m_freem(m0);
    345   1.1        ws 			continue;
    346   1.1        ws 		}
    347   1.1        ws 
    348  1.21      matt 		for (bufp = buf; (m = m0) != NULL;) {
    349   1.1        ws 			bcopy(mtod(m, char *), bufp, m->m_len);
    350   1.1        ws 			bufp += m->m_len;
    351   1.1        ws 			MFREE(m, m0);
    352   1.1        ws 		}
    353  1.22     billc 
    354  1.22     billc 		/*
    355  1.22     billc 		 * We don't know if the interface will auto-pad for
    356  1.22     billc 		 * us, so make sure it's at least as large as a
    357  1.22     billc 		 * minimum size Ethernet packet.
    358  1.22     billc 		 */
    359  1.22     billc 
    360  1.22     billc 		if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
    361  1.22     billc 			len = ETHER_MIN_LEN - ETHER_CRC_LEN;
    362  1.22     billc 		else
    363  1.22     billc 			len = bufp - buf;
    364  1.22     billc 
    365  1.22     billc 		if (OF_write(of->sc_ihandle, buf, len) != len)
    366   1.1        ws 			ifp->if_oerrors++;
    367   1.1        ws 		else
    368   1.1        ws 			ifp->if_opackets++;
    369   1.1        ws 	}
    370   1.1        ws }
    371   1.1        ws 
    372   1.1        ws static int
    373  1.21      matt ofnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
    374   1.1        ws {
    375  1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    376   1.1        ws 	struct ifaddr *ifa = (struct ifaddr *)data;
    377  1.21      matt 	/* struct ifreq *ifr = (struct ifreq *)data; */
    378   1.1        ws 	int error = 0;
    379   1.1        ws 
    380   1.1        ws 	switch (cmd) {
    381   1.1        ws 	case SIOCSIFADDR:
    382   1.1        ws 		ifp->if_flags |= IFF_UP;
    383   1.1        ws 
    384   1.1        ws 		switch (ifa->ifa_addr->sa_family) {
    385   1.1        ws #ifdef	INET
    386   1.1        ws 		case AF_INET:
    387   1.5        is 			arp_ifinit(ifp, ifa);
    388   1.1        ws 			break;
    389   1.1        ws #endif
    390   1.1        ws 		default:
    391   1.1        ws 			break;
    392   1.1        ws 		}
    393  1.13   mycroft 		ofnet_init(of);
    394   1.1        ws 		break;
    395   1.1        ws 	case SIOCSIFFLAGS:
    396  1.13   mycroft 		if ((ifp->if_flags & IFF_UP) == 0 &&
    397  1.13   mycroft 		    (ifp->if_flags & IFF_RUNNING) != 0) {
    398   1.1        ws 			/* If interface is down, but running, stop it. */
    399  1.13   mycroft 			ofnet_stop(of);
    400  1.13   mycroft 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
    401  1.13   mycroft 			   (ifp->if_flags & IFF_RUNNING) == 0) {
    402   1.1        ws 			/* If interface is up, but not running, start it. */
    403  1.13   mycroft 			ofnet_init(of);
    404   1.1        ws 		} else {
    405   1.1        ws 			/* Other flags are ignored. */
    406   1.1        ws 		}
    407   1.1        ws 		break;
    408   1.1        ws 	default:
    409   1.1        ws 		error = EINVAL;
    410   1.1        ws 		break;
    411   1.1        ws 	}
    412   1.1        ws 	return error;
    413   1.1        ws }
    414   1.1        ws 
    415   1.1        ws static void
    416  1.21      matt ofnet_watchdog(struct ifnet *ifp)
    417   1.1        ws {
    418  1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    419   1.1        ws 
    420   1.1        ws 	log(LOG_ERR, "%s: device timeout\n", of->sc_dev.dv_xname);
    421   1.5        is 	ifp->if_oerrors++;
    422  1.13   mycroft 	ofnet_stop(of);
    423  1.13   mycroft 	ofnet_init(of);
    424   1.1        ws }
    425   1.1        ws 
    426   1.4        ws #if NIPKDB_OFN > 0
    427   1.1        ws static void
    428  1.21      matt ipkdbofstart(struct ipkdb_if *kip)
    429   1.1        ws {
    430   1.1        ws 	int unit = kip->unit - 1;
    431   1.1        ws 
    432   1.4        ws 	if (ipkdb_of)
    433   1.5        is 		ipkdbattach(kip, &ipkdb_of->sc_ethercom);
    434   1.1        ws }
    435   1.1        ws 
    436   1.1        ws static void
    437  1.21      matt ipkdbofleave(struct ipkdb_if *kip)
    438   1.1        ws {
    439   1.1        ws }
    440   1.1        ws 
    441   1.1        ws static int
    442  1.21      matt ipkdbofrcv(struct ipkdb_if *kip, u_char *buf, int poll)
    443   1.1        ws {
    444   1.1        ws 	int l;
    445   1.1        ws 
    446   1.1        ws 	do {
    447   1.1        ws 		l = OF_read(kip->port, buf, ETHERMTU);
    448   1.1        ws 		if (l < 0)
    449   1.1        ws 			l = 0;
    450   1.1        ws 	} while (!poll && !l);
    451   1.1        ws 	return l;
    452   1.1        ws }
    453   1.1        ws 
    454   1.1        ws static void
    455  1.21      matt ipkdbofsend(struct ipkdb_if *kip, u_char *buf, int l)
    456   1.1        ws {
    457   1.1        ws 	OF_write(kip->port, buf, l);
    458   1.1        ws }
    459   1.1        ws 
    460   1.1        ws static int
    461  1.21      matt ipkdbprobe(struct cfdata *match, void *aux)
    462   1.1        ws {
    463   1.4        ws 	struct ipkdb_if *kip = aux;
    464   1.1        ws 	static char name[256];
    465   1.1        ws 	int len;
    466   1.1        ws 	int phandle;
    467   1.1        ws 
    468   1.6   thorpej 	kip->unit = match->cf_unit + 1;
    469   1.1        ws 
    470   1.1        ws 	if (!(kip->port = OF_open("net")))
    471   1.1        ws 		return -1;
    472  1.13   mycroft 	if ((len = OF_instance_to_path(kip->port, name, sizeof name - 1)) < 0 ||
    473  1.13   mycroft 	    len >= sizeof name)
    474   1.1        ws 		return -1;
    475   1.1        ws 	name[len] = 0;
    476   1.1        ws 	if ((phandle = OF_instance_to_package(kip->port)) == -1)
    477   1.1        ws 		return -1;
    478  1.13   mycroft 	if (OF_getprop(phandle, "mac-address", kip->myenetaddr,
    479  1.13   mycroft 	    sizeof kip->myenetaddr) < 0)
    480   1.1        ws 		return -1;
    481   1.1        ws 
    482   1.4        ws 	kip->flags |= IPKDB_MYHW;
    483   1.1        ws 	kip->name = name;
    484   1.4        ws 	kip->start = ipkdbofstart;
    485   1.4        ws 	kip->leave = ipkdbofleave;
    486   1.4        ws 	kip->receive = ipkdbofrcv;
    487   1.4        ws 	kip->send = ipkdbofsend;
    488   1.1        ws 
    489   1.1        ws 	kifp = kip;
    490   1.1        ws 
    491   1.1        ws 	return 0;
    492   1.1        ws }
    493   1.1        ws #endif
    494