if_cfe.c revision 1.1
1/* $NetBSD: if_cfe.c,v 1.1 2002/11/09 06:20:42 cgd Exp $ */
2
3/*
4 * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
5 * Copyright (c) 1993 Adam Glass
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by Adam Glass.
19 * 4. The name of the Author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/param.h>
36#include <sys/types.h>
37
38#include <netinet/in.h>
39#include <netinet/in_systm.h>
40
41#include <lib/libsa/stand.h>
42#include <lib/libsa/net.h>
43#include <lib/libsa/netif.h>
44#include <lib/libkern/libkern.h>
45
46#include "stand/common/common.h"
47#include "stand/common/bbinfo.h"
48#include "stand/common/cfe_api.h"
49#include "stand/common/cfe_ioctl.h"
50
51int cfenet_probe(struct netif *, void *);
52int cfenet_match(struct netif *, void *);
53void cfenet_init(struct iodesc *, void *);
54int cfenet_get(struct iodesc *, void *, size_t, time_t);
55int cfenet_put(struct iodesc *, void *, size_t);
56void cfenet_end(struct netif *);
57
58extern struct netif_stats	cfenet_stats[];
59
60struct netif_dif cfenet_ifs[] = {
61/*	dif_unit	dif_nsel	dif_stats	dif_private	*/
62{	0,		1,		&cfenet_stats[0],	0,		},
63};
64
65struct netif_stats cfenet_stats[NENTS(cfenet_ifs)];
66
67struct netif_driver prom_netif_driver = {
68	"cfe",			/* netif_bname */
69	cfenet_match,		/* netif_match */
70	cfenet_probe,		/* netif_probe */
71	cfenet_init,		/* netif_init */
72	cfenet_get,		/* netif_get */
73	cfenet_put,		/* netif_put */
74	cfenet_end,		/* netif_end */
75	cfenet_ifs,		/* netif_ifs */
76	NENTS(cfenet_ifs)		/* netif_nifs */
77};
78
79int
80cfenet_match(nif, machdep_hint)
81	struct netif *nif;
82	void *machdep_hint;
83{
84
85	return (1);
86}
87
88int
89cfenet_probe(nif, machdep_hint)
90	struct netif *nif;
91	void *machdep_hint;
92{
93
94	return 0;
95}
96
97int
98cfenet_put(desc, pkt, len)
99	struct iodesc *desc;
100	void *pkt;
101	size_t len;
102{
103
104    cfe_write(booted_dev_fd,pkt,len);
105
106    return len;
107}
108
109
110int
111cfenet_get(desc, pkt, len, timeout)
112	struct iodesc *desc;
113	void *pkt;
114	size_t len;
115	time_t timeout;
116{
117	time_t t;
118	int cc;
119
120	t = getsecs();
121	cc = 0;
122	while (((getsecs() - t) < timeout) && !cc) {
123	    cc = cfe_read(booted_dev_fd,pkt,len);
124	    if (cc < 0) break;
125	    break;
126	}
127
128	return cc;
129}
130
131void
132cfenet_init(desc, machdep_hint)
133	struct iodesc *desc;
134	void *machdep_hint;
135{
136	u_int8_t eaddr[6];
137	int res;
138
139	res = cfe_ioctl(booted_dev_fd,IOCTL_ETHER_GETHWADDR,eaddr,sizeof(eaddr),NULL,0);
140
141	if (res < 0) {
142	    printf("boot: boot device name does not contain ethernet address.\n");
143	    goto punt;
144	    }
145
146	bcopy(eaddr,desc->myea,6);
147
148	printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));
149	return;
150
151punt:
152	halt();
153
154}
155
156void
157cfenet_end(nif)
158	struct netif *nif;
159{
160
161	/* nothing to do */
162}
163