if_prom.c revision 1.1 1 /* $NetBSD: if_prom.c,v 1.1 1996/09/18 20:03:10 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1993 Adam Glass
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Adam Glass.
18 * 4. The name of the Author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/types.h>
36
37 #include <netinet/in.h>
38 #include <netinet/in_systm.h>
39
40 #include "netif.h"
41 #include "include/prom.h"
42 #include "lib/libkern/libkern.h"
43
44 int prom_probe();
45 int prom_match();
46 void prom_init();
47 int prom_get();
48 int prom_put();
49 void prom_end();
50
51 extern struct netif_stats prom_stats[];
52
53 struct netif_dif prom_ifs[] = {
54 /* dif_unit dif_nsel dif_stats dif_private */
55 { 0, 1, &prom_stats[0], 0, },
56 };
57
58 struct netif_stats prom_stats[NENTS(prom_ifs)];
59
60 struct netif_driver prom_netif_driver = {
61 "prom", /* netif_bname */
62 prom_match, /* netif_match */
63 prom_probe, /* netif_probe */
64 prom_init, /* netif_init */
65 prom_get, /* netif_get */
66 prom_put, /* netif_put */
67 prom_end, /* netif_end */
68 prom_ifs, /* netif_ifs */
69 NENTS(prom_ifs) /* netif_nifs */
70 };
71
72 int netfd;
73
74 int
75 prom_match(nif, machdep_hint)
76 struct netif *nif;
77 void *machdep_hint;
78 {
79
80 printf("prom_match(0x%lx, 0x%lx)\n", nif, machdep_hint);
81 return (1);
82 }
83
84 int
85 prom_probe(nif, machdep_hint)
86 struct netif *nif;
87 void *machdep_hint;
88 {
89
90 printf("prom_probe(0x%lx, 0x%lx)\n", nif, machdep_hint);
91 return 0;
92 }
93
94 int
95 prom_put(desc, pkt, len)
96 struct iodesc *desc;
97 void *pkt;
98 int len;
99 {
100
101 /* printf("prom_put(0x%lx, 0x%lx, %d)\n", desc, pkt, len); */
102 prom_write(netfd, len, pkt, 0);
103
104 return len;
105 }
106
107
108 int
109 prom_get(desc, pkt, len, timeout)
110 struct iodesc *desc;
111 void *pkt;
112 int len;
113 time_t timeout;
114 {
115 prom_return_t ret;
116 time_t t;
117 int cc;
118 char hate[2000];
119
120 #if 0
121 printf("prom_get(0x%lx, 0x%lx, %d, %d)\n", desc, pkt, len, timeout);
122 #endif
123
124 t = getsecs();
125 cc = 0;
126 while (((getsecs() - t) < timeout) && !cc) {
127 #if 1 /* TC machines' firmware */
128 ret.bits = prom_read(netfd, 0, hate, 0);
129 #else
130 ret.bits = prom_read(netfd, sizeof hate, hate, 0);
131 #endif
132 if (ret.u.status == 0)
133 cc += ret.u.retval;
134 }
135
136 #if 0
137 printf("got %d\n", cc);
138
139 if (cc != len)
140 printf("prom_get: cc = %d, len = %d\n", cc, len);
141 #endif
142
143 #if 1 /* TC machines' firmware */
144 cc = min(cc, len);
145 #else
146 cc = len;
147 #endif
148 bcopy(hate, pkt, cc);
149
150 return cc;
151 }
152
153 void
154 prom_init(desc, machdep_hint)
155 struct iodesc *desc;
156 void *machdep_hint;
157 {
158
159 prom_return_t ret;
160 char devname[64], tmpbuf[14];
161 int devlen;
162
163 printf("prom_init(0x%lx, 0x%lx)\n", desc, machdep_hint);
164
165 ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
166 devlen = ret.u.retval;
167 printf("devlen = %d\n", devlen);
168 printf("booted_dev was: %s\n", devname);
169 ret.bits = prom_open(devname, devlen + 1);
170 if (ret.u.status) {
171 printf("open failed: %d\n", ret.u.status);
172 return;
173 }
174 netfd = ret.u.retval;
175
176 bzero(tmpbuf, sizeof(tmpbuf));
177 prom_write(netfd, sizeof(tmpbuf), tmpbuf, 0);
178
179 /* PLUG YOUR ENET ADDR IN HERE. */
180 #if 1
181 #if 1
182 desc->myea[0] = 0x08;
183 desc->myea[1] = 0x00;
184 desc->myea[2] = 0x2b;
185 desc->myea[3] = 0xbd;
186 desc->myea[4] = 0x5d;
187 desc->myea[5] = 0xfd;
188 #else
189 desc->myea[0] = 0x08;
190 desc->myea[1] = 0x00;
191 desc->myea[2] = 0x2b;
192 desc->myea[3] = 0x39;
193 desc->myea[4] = 0x98;
194 desc->myea[5] = 0x3d;
195 #endif
196 #else
197 desc->myea[0] = 0x00;
198 desc->myea[1] = 0x00;
199 desc->myea[2] = 0xf8;
200 desc->myea[3] = 0x21;
201 desc->myea[4] = 0xa6;
202 desc->myea[5] = 0x81;
203 #endif
204 }
205
206 void
207 prom_end(nif)
208 struct netif *nif;
209 {
210
211 printf("prom_end(0x%lx)\n", nif);
212 prom_close(netfd);
213 }
214