if_cfe.c revision 1.5
11.5Scegger/* $NetBSD: if_cfe.c,v 1.5 2009/03/18 17:06:46 cegger Exp $ */
21.1Scgd
31.1Scgd/*
41.1Scgd * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
51.1Scgd * Copyright (c) 1993 Adam Glass
61.1Scgd * All rights reserved.
71.1Scgd *
81.1Scgd * Redistribution and use in source and binary forms, with or without
91.1Scgd * modification, are permitted provided that the following conditions
101.1Scgd * are met:
111.1Scgd * 1. Redistributions of source code must retain the above copyright
121.1Scgd *    notice, this list of conditions and the following disclaimer.
131.1Scgd * 2. Redistributions in binary form must reproduce the above copyright
141.1Scgd *    notice, this list of conditions and the following disclaimer in the
151.1Scgd *    documentation and/or other materials provided with the distribution.
161.1Scgd * 3. All advertising materials mentioning features or use of this software
171.1Scgd *    must display the following acknowledgement:
181.1Scgd *	This product includes software developed by Adam Glass.
191.1Scgd * 4. The name of the Author may not be used to endorse or promote products
201.1Scgd *    derived from this software without specific prior written permission.
211.1Scgd *
221.1Scgd * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
231.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Scgd * SUCH DAMAGE.
331.1Scgd */
341.1Scgd
351.1Scgd#include <sys/param.h>
361.1Scgd#include <sys/types.h>
371.1Scgd
381.1Scgd#include <netinet/in.h>
391.1Scgd#include <netinet/in_systm.h>
401.1Scgd
411.1Scgd#include <lib/libsa/stand.h>
421.1Scgd#include <lib/libsa/net.h>
431.1Scgd#include <lib/libsa/netif.h>
441.1Scgd#include <lib/libkern/libkern.h>
451.1Scgd
461.1Scgd#include "stand/common/common.h"
471.1Scgd#include "stand/common/bbinfo.h"
481.1Scgd#include "stand/common/cfe_api.h"
491.1Scgd#include "stand/common/cfe_ioctl.h"
501.1Scgd
511.1Scgdint cfenet_probe(struct netif *, void *);
521.1Scgdint cfenet_match(struct netif *, void *);
531.1Scgdvoid cfenet_init(struct iodesc *, void *);
541.3Stsutsuiint cfenet_get(struct iodesc *, void *, size_t, saseconds_t);
551.1Scgdint cfenet_put(struct iodesc *, void *, size_t);
561.1Scgdvoid cfenet_end(struct netif *);
571.1Scgd
581.1Scgdextern struct netif_stats	cfenet_stats[];
591.1Scgd
601.1Scgdstruct netif_dif cfenet_ifs[] = {
611.1Scgd/*	dif_unit	dif_nsel	dif_stats	dif_private	*/
621.1Scgd{	0,		1,		&cfenet_stats[0],	0,		},
631.1Scgd};
641.2Sdrochner#define NCFENET_IFS (sizeof(cfenet_ifs) / sizeof(cfenet_ifs[0]))
651.1Scgd
661.2Sdrochnerstruct netif_stats cfenet_stats[NCFENET_IFS];
671.1Scgd
681.1Scgdstruct netif_driver prom_netif_driver = {
691.1Scgd	"cfe",			/* netif_bname */
701.1Scgd	cfenet_match,		/* netif_match */
711.1Scgd	cfenet_probe,		/* netif_probe */
721.1Scgd	cfenet_init,		/* netif_init */
731.1Scgd	cfenet_get,		/* netif_get */
741.1Scgd	cfenet_put,		/* netif_put */
751.1Scgd	cfenet_end,		/* netif_end */
761.1Scgd	cfenet_ifs,		/* netif_ifs */
771.2Sdrochner	NCFENET_IFS		/* netif_nifs */
781.1Scgd};
791.1Scgd
801.1Scgdint
811.4Sdslcfenet_match(struct netif *nif, void *machdep_hint)
821.1Scgd{
831.1Scgd
841.1Scgd	return (1);
851.1Scgd}
861.1Scgd
871.1Scgdint
881.4Sdslcfenet_probe(struct netif *nif, void *machdep_hint)
891.1Scgd{
901.1Scgd
911.1Scgd	return 0;
921.1Scgd}
931.1Scgd
941.1Scgdint
951.4Sdslcfenet_put(struct iodesc *desc, void *pkt, size_t len)
961.1Scgd{
971.1Scgd
981.1Scgd    cfe_write(booted_dev_fd,pkt,len);
991.1Scgd
1001.1Scgd    return len;
1011.1Scgd}
1021.1Scgd
1031.1Scgd
1041.1Scgdint
1051.4Sdslcfenet_get(struct iodesc *desc, void *pkt, size_t len, saseconds_t timeout)
1061.1Scgd{
1071.3Stsutsui	satime_t t;
1081.1Scgd	int cc;
1091.1Scgd
1101.1Scgd	t = getsecs();
1111.1Scgd	cc = 0;
1121.1Scgd	while (((getsecs() - t) < timeout) && !cc) {
1131.1Scgd	    cc = cfe_read(booted_dev_fd,pkt,len);
1141.1Scgd	    if (cc < 0) break;
1151.1Scgd	    break;
1161.1Scgd	}
1171.1Scgd
1181.1Scgd	return cc;
1191.1Scgd}
1201.1Scgd
1211.1Scgdvoid
1221.4Sdslcfenet_init(struct iodesc *desc, void *machdep_hint)
1231.1Scgd{
1241.1Scgd	u_int8_t eaddr[6];
1251.1Scgd	int res;
1261.1Scgd
1271.1Scgd	res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0);
1281.1Scgd
1291.1Scgd	if (res < 0) {
1301.1Scgd	    printf("boot: boot device name does not contain ethernet address.\n");
1311.1Scgd	    goto punt;
1321.1Scgd	    }
1331.1Scgd
1341.5Scegger	memcpy(desc->myea, eaddr,6);
1351.1Scgd
1361.1Scgd	printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
1371.1Scgd	return;
1381.1Scgd
1391.1Scgdpunt:
1401.1Scgd	halt();
1411.1Scgd
1421.1Scgd}
1431.1Scgd
1441.1Scgdvoid
1451.4Sdslcfenet_end(struct netif *nif)
1461.1Scgd{
1471.1Scgd
1481.1Scgd	/* nothing to do */
1491.1Scgd}
150