Home | History | Annotate | Line # | Download | only in ofw
ofnet.c revision 1.52.12.2
      1  1.52.12.2  jdolecek /*	$NetBSD: ofnet.c,v 1.52.12.2 2017/12/03 11:37:07 jdolecek 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.52.12.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: ofnet.c,v 1.52.12.2 2017/12/03 11:37:07 jdolecek Exp $");
     36       1.23     lukem 
     37        1.1        ws #include "ofnet.h"
     38       1.15  jonathan #include "opt_inet.h"
     39        1.1        ws 
     40        1.1        ws #include <sys/param.h>
     41       1.14        tv #include <sys/systm.h>
     42       1.18   thorpej #include <sys/callout.h>
     43        1.1        ws #include <sys/device.h>
     44       1.21      matt #include <sys/disk.h>
     45        1.1        ws #include <sys/ioctl.h>
     46        1.1        ws #include <sys/mbuf.h>
     47        1.1        ws #include <sys/socket.h>
     48        1.1        ws #include <sys/syslog.h>
     49        1.1        ws 
     50        1.1        ws #include <net/if.h>
     51        1.5        is #include <net/if_ether.h>
     52        1.1        ws 
     53        1.1        ws #ifdef INET
     54        1.1        ws #include <netinet/in.h>
     55        1.5        is #include <netinet/if_inarp.h>
     56        1.1        ws #endif
     57        1.1        ws 
     58        1.6   thorpej #include <net/bpf.h>
     59        1.6   thorpej #include <net/bpfdesc.h>
     60        1.6   thorpej 
     61        1.1        ws #include <dev/ofw/openfirm.h>
     62        1.1        ws 
     63        1.4        ws #if NIPKDB_OFN > 0
     64        1.4        ws #include <ipkdb/ipkdb.h>
     65        1.4        ws #include <machine/ipkdb.h>
     66        1.1        ws 
     67  1.52.12.1       tls CFATTACH_DECL_NEW(ipkdb_ofn, 0,
     68       1.29   thorpej     ipkdb_probe, ipkdb_attach, NULL, NULL);
     69        1.1        ws 
     70        1.4        ws static struct ipkdb_if *kifp;
     71       1.13   mycroft static struct ofnet_softc *ipkdb_of;
     72        1.1        ws 
     73       1.47    cegger static int ipkdbprobe (cfdata_t, void *);
     74        1.1        ws #endif
     75        1.1        ws 
     76       1.13   mycroft struct ofnet_softc {
     77       1.52       mrg 	device_t sc_dev;
     78        1.1        ws 	int sc_phandle;
     79        1.1        ws 	int sc_ihandle;
     80        1.5        is 	struct ethercom sc_ethercom;
     81       1.18   thorpej 	struct callout sc_callout;
     82        1.1        ws };
     83        1.1        ws 
     84       1.48    cegger static int ofnet_match (device_t, cfdata_t, void *);
     85       1.48    cegger static void ofnet_attach (device_t, device_t, void *);
     86        1.1        ws 
     87       1.52       mrg CFATTACH_DECL_NEW(ofnet, sizeof(struct ofnet_softc),
     88       1.28   thorpej     ofnet_match, ofnet_attach, NULL, NULL);
     89        1.1        ws 
     90       1.21      matt static void ofnet_read (struct ofnet_softc *);
     91       1.21      matt static void ofnet_timer (void *);
     92       1.21      matt static void ofnet_init (struct ofnet_softc *);
     93       1.21      matt static void ofnet_stop (struct ofnet_softc *);
     94       1.21      matt 
     95       1.21      matt static void ofnet_start (struct ifnet *);
     96       1.38  christos static int ofnet_ioctl (struct ifnet *, u_long, void *);
     97       1.21      matt static void ofnet_watchdog (struct ifnet *);
     98        1.1        ws 
     99        1.1        ws static int
    100       1.48    cegger ofnet_match(device_t parent, cfdata_t match, void *aux)
    101        1.1        ws {
    102       1.13   mycroft 	struct ofbus_attach_args *oba = aux;
    103        1.1        ws 	char type[32];
    104        1.1        ws 	int l;
    105       1.33     perry 
    106        1.4        ws #if NIPKDB_OFN > 0
    107        1.1        ws 	if (!parent)
    108        1.4        ws 		return ipkdbprobe(match, aux);
    109        1.1        ws #endif
    110       1.13   mycroft 	if (strcmp(oba->oba_busname, "ofw"))
    111       1.13   mycroft 		return (0);
    112       1.13   mycroft 	if ((l = OF_getprop(oba->oba_phandle, "device_type", type,
    113       1.13   mycroft 	    sizeof type - 1)) < 0)
    114        1.1        ws 		return 0;
    115        1.1        ws 	if (l >= sizeof type)
    116        1.1        ws 		return 0;
    117        1.1        ws 	type[l] = 0;
    118        1.1        ws 	if (strcmp(type, "network"))
    119        1.1        ws 		return 0;
    120        1.1        ws 	return 1;
    121        1.1        ws }
    122        1.1        ws 
    123        1.1        ws static void
    124       1.48    cegger ofnet_attach(device_t parent, device_t self, void *aux)
    125        1.1        ws {
    126       1.36   thorpej 	struct ofnet_softc *of = device_private(self);
    127        1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    128       1.13   mycroft 	struct ofbus_attach_args *oba = aux;
    129        1.1        ws 	char path[256];
    130        1.1        ws 	int l;
    131        1.5        is 	u_int8_t myaddr[ETHER_ADDR_LEN];
    132       1.33     perry 
    133       1.52       mrg 	of->sc_dev = self;
    134       1.52       mrg 
    135       1.13   mycroft 	of->sc_phandle = oba->oba_phandle;
    136        1.4        ws #if NIPKDB_OFN > 0
    137       1.13   mycroft 	if (kifp &&
    138       1.52       mrg 	    kifp->unit - 1 == device_unit(of->sc_dev) &&
    139       1.13   mycroft 	    OF_instance_to_package(kifp->port) == oba->oba_phandle)  {
    140        1.4        ws 		ipkdb_of = of;
    141        1.1        ws 		of->sc_ihandle = kifp->port;
    142        1.1        ws 	} else
    143        1.1        ws #endif
    144       1.13   mycroft 	if ((l = OF_package_to_path(oba->oba_phandle, path,
    145       1.13   mycroft 	    sizeof path - 1)) < 0 ||
    146       1.13   mycroft 	    l >= sizeof path ||
    147       1.13   mycroft 	    (path[l] = 0, !(of->sc_ihandle = OF_open(path))))
    148       1.13   mycroft 		panic("ofnet_attach: unable to open");
    149       1.13   mycroft 	if (OF_getprop(oba->oba_phandle, "mac-address", myaddr,
    150       1.13   mycroft 	    sizeof myaddr) < 0)
    151       1.13   mycroft 		panic("ofnet_attach: no mac-address");
    152        1.5        is 	printf(": address %s\n", ether_sprintf(myaddr));
    153       1.18   thorpej 
    154       1.40        ad 	callout_init(&of->sc_callout, 0);
    155       1.18   thorpej 
    156       1.52       mrg 	strlcpy(ifp->if_xname, device_xname(of->sc_dev), IFNAMSIZ);
    157        1.1        ws 	ifp->if_softc = of;
    158       1.13   mycroft 	ifp->if_start = ofnet_start;
    159       1.13   mycroft 	ifp->if_ioctl = ofnet_ioctl;
    160       1.13   mycroft 	ifp->if_watchdog = ofnet_watchdog;
    161        1.1        ws 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
    162       1.24    itojun 	IFQ_SET_READY(&ifp->if_snd);
    163        1.1        ws 
    164        1.1        ws 	if_attach(ifp);
    165        1.5        is 	ether_ifattach(ifp, myaddr);
    166        1.1        ws }
    167        1.1        ws 
    168       1.32   thorpej static char buf[ETHER_MAX_LEN];
    169        1.1        ws 
    170        1.1        ws static void
    171       1.21      matt ofnet_read(struct ofnet_softc *of)
    172        1.1        ws {
    173        1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    174        1.1        ws 	struct mbuf *m, **mp, *head;
    175       1.25       chs 	int s, l, len;
    176        1.1        ws 	char *bufp;
    177        1.1        ws 
    178       1.25       chs 	s = splnet();
    179        1.4        ws #if NIPKDB_OFN > 0
    180        1.4        ws 	ipkdbrint(kifp, ifp);
    181       1.33     perry #endif
    182       1.25       chs 	for (;;) {
    183       1.30       chs 		len = OF_read(of->sc_ihandle, buf, sizeof buf);
    184       1.30       chs 		if (len == -2 || len == 0)
    185       1.30       chs 			break;
    186        1.1        ws 		if (len < sizeof(struct ether_header)) {
    187        1.1        ws 			ifp->if_ierrors++;
    188        1.1        ws 			continue;
    189        1.1        ws 		}
    190        1.1        ws 		bufp = buf;
    191       1.22     billc 
    192       1.32   thorpej 		/*
    193       1.32   thorpej 		 * We don't know if the interface included the FCS
    194       1.32   thorpej 		 * or not.  For now, assume that it did if we got
    195       1.32   thorpej 		 * a packet length that looks like it could include
    196       1.32   thorpej 		 * the FCS.
    197       1.32   thorpej 		 *
    198       1.32   thorpej 		 * XXX Yuck.
    199       1.32   thorpej 		 */
    200       1.32   thorpej 		if (len > ETHER_MAX_LEN - ETHER_CRC_LEN)
    201       1.32   thorpej 			len = ETHER_MAX_LEN - ETHER_CRC_LEN;
    202       1.32   thorpej 
    203        1.1        ws 		/* Allocate a header mbuf */
    204        1.1        ws 		MGETHDR(m, M_DONTWAIT, MT_DATA);
    205        1.1        ws 		if (m == 0) {
    206        1.1        ws 			ifp->if_ierrors++;
    207        1.1        ws 			continue;
    208        1.1        ws 		}
    209  1.52.12.2  jdolecek 		m_set_rcvif(m, ifp);
    210        1.1        ws 		m->m_pkthdr.len = len;
    211       1.22     billc 
    212        1.1        ws 		l = MHLEN;
    213        1.1        ws 		head = 0;
    214        1.1        ws 		mp = &head;
    215       1.33     perry 
    216        1.1        ws 		while (len > 0) {
    217        1.1        ws 			if (head) {
    218        1.1        ws 				MGET(m, M_DONTWAIT, MT_DATA);
    219        1.1        ws 				if (m == 0) {
    220        1.1        ws 					ifp->if_ierrors++;
    221        1.1        ws 					m_freem(head);
    222        1.1        ws 					head = 0;
    223        1.1        ws 					break;
    224        1.1        ws 				}
    225        1.1        ws 				l = MLEN;
    226        1.1        ws 			}
    227        1.1        ws 			if (len >= MINCLSIZE) {
    228        1.1        ws 				MCLGET(m, M_DONTWAIT);
    229        1.8   mycroft 				if ((m->m_flags & M_EXT) == 0) {
    230        1.8   mycroft 					ifp->if_ierrors++;
    231        1.9   mycroft 					m_free(m);
    232        1.7   mycroft 					m_freem(head);
    233        1.7   mycroft 					head = 0;
    234        1.7   mycroft 					break;
    235        1.7   mycroft 				}
    236        1.7   mycroft 				l = MCLBYTES;
    237        1.1        ws 			}
    238       1.12       cgd 
    239       1.12       cgd 			/*
    240       1.12       cgd 			 * Make sure the data after the Ethernet header
    241       1.12       cgd 			 * is aligned.
    242       1.12       cgd 			 *
    243       1.12       cgd 			 * XXX Assumes the device is an ethernet, but
    244       1.12       cgd 			 * XXX then so does other code in this driver.
    245       1.12       cgd 			 */
    246       1.12       cgd 			if (head == NULL) {
    247       1.39      matt 				char *newdata = (char *)ALIGN(m->m_data +
    248       1.12       cgd 				      sizeof(struct ether_header)) -
    249       1.12       cgd 				    sizeof(struct ether_header);
    250       1.12       cgd 				l -= newdata - m->m_data;
    251       1.12       cgd 				m->m_data = newdata;
    252       1.12       cgd 			}
    253       1.12       cgd 
    254        1.1        ws 			m->m_len = l = min(len, l);
    255       1.45    cegger 			memcpy(mtod(m, char *), bufp, l);
    256        1.1        ws 			bufp += l;
    257        1.1        ws 			len -= l;
    258        1.1        ws 			*mp = m;
    259        1.1        ws 			mp = &m->m_next;
    260        1.1        ws 		}
    261        1.1        ws 		if (head == 0)
    262        1.1        ws 			continue;
    263        1.1        ws 
    264  1.52.12.2  jdolecek 		if_percpuq_enqueue(ifp->if_percpuq, head);
    265        1.1        ws 	}
    266       1.25       chs 	splx(s);
    267        1.1        ws }
    268        1.1        ws 
    269        1.1        ws static void
    270       1.43       dsl ofnet_timer(void *arg)
    271        1.1        ws {
    272       1.16   thorpej 	struct ofnet_softc *of = arg;
    273       1.16   thorpej 
    274       1.13   mycroft 	ofnet_read(of);
    275       1.18   thorpej 	callout_reset(&of->sc_callout, 1, ofnet_timer, of);
    276        1.1        ws }
    277        1.1        ws 
    278        1.1        ws static void
    279       1.21      matt ofnet_init(struct ofnet_softc *of)
    280        1.1        ws {
    281        1.5        is 	struct ifnet *ifp = &of->sc_ethercom.ec_if;
    282        1.1        ws 
    283        1.1        ws 	if (ifp->if_flags & IFF_RUNNING)
    284        1.1        ws 		return;
    285        1.1        ws 
    286        1.1        ws 	ifp->if_flags |= IFF_RUNNING;
    287        1.1        ws 	/* Start reading from interface */
    288       1.13   mycroft 	ofnet_timer(of);
    289        1.1        ws 	/* Attempt to start output */
    290       1.13   mycroft 	ofnet_start(ifp);
    291        1.1        ws }
    292        1.1        ws 
    293        1.1        ws static void
    294       1.21      matt ofnet_stop(struct ofnet_softc *of)
    295        1.1        ws {
    296       1.18   thorpej 	callout_stop(&of->sc_callout);
    297        1.5        is 	of->sc_ethercom.ec_if.if_flags &= ~IFF_RUNNING;
    298        1.1        ws }
    299        1.1        ws 
    300        1.1        ws static void
    301       1.21      matt ofnet_start(struct ifnet *ifp)
    302        1.1        ws {
    303       1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    304        1.1        ws 	struct mbuf *m, *m0;
    305        1.1        ws 	char *bufp;
    306        1.1        ws 	int len;
    307       1.33     perry 
    308        1.1        ws 	if (!(ifp->if_flags & IFF_RUNNING))
    309        1.1        ws 		return;
    310        1.1        ws 
    311        1.1        ws 	for (;;) {
    312        1.1        ws 		/* First try reading any packets */
    313       1.13   mycroft 		ofnet_read(of);
    314       1.33     perry 
    315        1.1        ws 		/* Now get the first packet on the queue */
    316       1.24    itojun 		IFQ_DEQUEUE(&ifp->if_snd, m0);
    317        1.1        ws 		if (!m0)
    318        1.1        ws 			return;
    319       1.33     perry 
    320        1.1        ws 		if (!(m0->m_flags & M_PKTHDR))
    321       1.13   mycroft 			panic("ofnet_start: no header mbuf");
    322        1.1        ws 		len = m0->m_pkthdr.len;
    323        1.6   thorpej 
    324       1.50     joerg 		bpf_mtap(ifp, m0);
    325        1.6   thorpej 
    326        1.1        ws 		if (len > ETHERMTU + sizeof(struct ether_header)) {
    327        1.1        ws 			/* packet too large, toss it */
    328        1.1        ws 			ifp->if_oerrors++;
    329        1.1        ws 			m_freem(m0);
    330        1.1        ws 			continue;
    331        1.1        ws 		}
    332        1.1        ws 
    333       1.21      matt 		for (bufp = buf; (m = m0) != NULL;) {
    334       1.46   tsutsui 			memcpy(bufp, mtod(m, char *), m->m_len);
    335        1.1        ws 			bufp += m->m_len;
    336  1.52.12.2  jdolecek 			m0 = m_free(m);
    337        1.1        ws 		}
    338       1.22     billc 
    339       1.22     billc 		/*
    340       1.22     billc 		 * We don't know if the interface will auto-pad for
    341       1.22     billc 		 * us, so make sure it's at least as large as a
    342       1.22     billc 		 * minimum size Ethernet packet.
    343       1.22     billc 		 */
    344       1.22     billc 
    345       1.31    bouyer 		if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN)) {
    346       1.31    bouyer 			memset(bufp, 0, ETHER_MIN_LEN - ETHER_CRC_LEN - len);
    347       1.31    bouyer 			bufp += ETHER_MIN_LEN - ETHER_CRC_LEN - len;
    348       1.31    bouyer 		} else
    349       1.22     billc 			len = bufp - buf;
    350       1.22     billc 
    351       1.22     billc 		if (OF_write(of->sc_ihandle, buf, len) != len)
    352        1.1        ws 			ifp->if_oerrors++;
    353        1.1        ws 		else
    354        1.1        ws 			ifp->if_opackets++;
    355        1.1        ws 	}
    356        1.1        ws }
    357        1.1        ws 
    358        1.1        ws static int
    359       1.38  christos ofnet_ioctl(struct ifnet *ifp, u_long cmd, void *data)
    360        1.1        ws {
    361       1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    362        1.1        ws 	struct ifaddr *ifa = (struct ifaddr *)data;
    363       1.21      matt 	/* struct ifreq *ifr = (struct ifreq *)data; */
    364        1.1        ws 	int error = 0;
    365       1.33     perry 
    366        1.1        ws 	switch (cmd) {
    367       1.42    dyoung 	case SIOCINITIFADDR:
    368        1.1        ws 		ifp->if_flags |= IFF_UP;
    369       1.33     perry 
    370        1.1        ws 		switch (ifa->ifa_addr->sa_family) {
    371        1.1        ws #ifdef	INET
    372        1.1        ws 		case AF_INET:
    373        1.5        is 			arp_ifinit(ifp, ifa);
    374        1.1        ws 			break;
    375        1.1        ws #endif
    376        1.1        ws 		default:
    377        1.1        ws 			break;
    378        1.1        ws 		}
    379       1.13   mycroft 		ofnet_init(of);
    380        1.1        ws 		break;
    381        1.1        ws 	case SIOCSIFFLAGS:
    382       1.42    dyoung 		if ((error = ifioctl_common(ifp, cmd, data)) != 0)
    383       1.42    dyoung 			break;
    384       1.42    dyoung 		/* XXX re-use ether_ioctl() */
    385       1.42    dyoung 		switch (ifp->if_flags & (IFF_UP|IFF_RUNNING)) {
    386       1.42    dyoung 		case IFF_RUNNING:
    387        1.1        ws 			/* If interface is down, but running, stop it. */
    388       1.13   mycroft 			ofnet_stop(of);
    389       1.42    dyoung 			break;
    390       1.42    dyoung 		case IFF_UP:
    391        1.1        ws 			/* If interface is up, but not running, start it. */
    392       1.13   mycroft 			ofnet_init(of);
    393       1.42    dyoung 			break;
    394       1.42    dyoung 		default:
    395        1.1        ws 			/* Other flags are ignored. */
    396       1.42    dyoung 			break;
    397        1.1        ws 		}
    398        1.1        ws 		break;
    399        1.1        ws 	default:
    400       1.42    dyoung 		error = ether_ioctl(ifp, cmd, data);
    401        1.1        ws 		break;
    402        1.1        ws 	}
    403        1.1        ws 	return error;
    404        1.1        ws }
    405        1.1        ws 
    406        1.1        ws static void
    407       1.21      matt ofnet_watchdog(struct ifnet *ifp)
    408        1.1        ws {
    409       1.13   mycroft 	struct ofnet_softc *of = ifp->if_softc;
    410       1.33     perry 
    411       1.52       mrg 	log(LOG_ERR, "%s: device timeout\n", device_xname(of->sc_dev));
    412        1.5        is 	ifp->if_oerrors++;
    413       1.13   mycroft 	ofnet_stop(of);
    414       1.13   mycroft 	ofnet_init(of);
    415        1.1        ws }
    416        1.1        ws 
    417        1.4        ws #if NIPKDB_OFN > 0
    418        1.1        ws static void
    419       1.21      matt ipkdbofstart(struct ipkdb_if *kip)
    420        1.1        ws {
    421        1.4        ws 	if (ipkdb_of)
    422        1.5        is 		ipkdbattach(kip, &ipkdb_of->sc_ethercom);
    423        1.1        ws }
    424        1.1        ws 
    425        1.1        ws static void
    426       1.21      matt ipkdbofleave(struct ipkdb_if *kip)
    427        1.1        ws {
    428        1.1        ws }
    429        1.1        ws 
    430        1.1        ws static int
    431       1.21      matt ipkdbofrcv(struct ipkdb_if *kip, u_char *buf, int poll)
    432        1.1        ws {
    433        1.1        ws 	int l;
    434       1.33     perry 
    435        1.1        ws 	do {
    436        1.1        ws 		l = OF_read(kip->port, buf, ETHERMTU);
    437        1.1        ws 		if (l < 0)
    438        1.1        ws 			l = 0;
    439        1.1        ws 	} while (!poll && !l);
    440        1.1        ws 	return l;
    441        1.1        ws }
    442        1.1        ws 
    443        1.1        ws static void
    444       1.21      matt ipkdbofsend(struct ipkdb_if *kip, u_char *buf, int l)
    445        1.1        ws {
    446        1.1        ws 	OF_write(kip->port, buf, l);
    447        1.1        ws }
    448        1.1        ws 
    449        1.1        ws static int
    450       1.47    cegger ipkdbprobe(cfdata_t match, void *aux)
    451        1.1        ws {
    452        1.4        ws 	struct ipkdb_if *kip = aux;
    453        1.1        ws 	static char name[256];
    454        1.1        ws 	int len;
    455        1.1        ws 	int phandle;
    456       1.33     perry 
    457        1.6   thorpej 	kip->unit = match->cf_unit + 1;
    458        1.1        ws 
    459        1.1        ws 	if (!(kip->port = OF_open("net")))
    460        1.1        ws 		return -1;
    461       1.13   mycroft 	if ((len = OF_instance_to_path(kip->port, name, sizeof name - 1)) < 0 ||
    462       1.13   mycroft 	    len >= sizeof name)
    463        1.1        ws 		return -1;
    464        1.1        ws 	name[len] = 0;
    465        1.1        ws 	if ((phandle = OF_instance_to_package(kip->port)) == -1)
    466        1.1        ws 		return -1;
    467       1.13   mycroft 	if (OF_getprop(phandle, "mac-address", kip->myenetaddr,
    468       1.13   mycroft 	    sizeof kip->myenetaddr) < 0)
    469        1.1        ws 		return -1;
    470       1.33     perry 
    471        1.4        ws 	kip->flags |= IPKDB_MYHW;
    472        1.1        ws 	kip->name = name;
    473        1.4        ws 	kip->start = ipkdbofstart;
    474        1.4        ws 	kip->leave = ipkdbofleave;
    475        1.4        ws 	kip->receive = ipkdbofrcv;
    476        1.4        ws 	kip->send = ipkdbofsend;
    477        1.1        ws 
    478        1.1        ws 	kifp = kip;
    479       1.33     perry 
    480        1.1        ws 	return 0;
    481        1.1        ws }
    482        1.1        ws #endif
    483