netif_sun.c revision 1.1.8.2 1 1.1.8.2 nathanw /* $NetBSD: netif_sun.c,v 1.1.8.2 2002/10/18 02:40:27 nathanw Exp $ */
2 1.1.8.2 nathanw
3 1.1.8.2 nathanw /*-
4 1.1.8.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1.8.2 nathanw * All rights reserved.
6 1.1.8.2 nathanw *
7 1.1.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.8.2 nathanw * by Gordon W. Ross.
9 1.1.8.2 nathanw *
10 1.1.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.8.2 nathanw * are met:
13 1.1.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.8.2 nathanw * must display the following acknowledgement:
20 1.1.8.2 nathanw * This product includes software developed by the NetBSD
21 1.1.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.8.2 nathanw * from this software without specific prior written permission.
25 1.1.8.2 nathanw *
26 1.1.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.8.2 nathanw */
38 1.1.8.2 nathanw
39 1.1.8.2 nathanw /*
40 1.1.8.2 nathanw * The Sun PROM has a fairly general set of network drivers,
41 1.1.8.2 nathanw * so it is easiest to just replace the netif module with
42 1.1.8.2 nathanw * this adaptation to the PROM network interface.
43 1.1.8.2 nathanw */
44 1.1.8.2 nathanw
45 1.1.8.2 nathanw #include <sys/param.h>
46 1.1.8.2 nathanw #include <sys/socket.h>
47 1.1.8.2 nathanw
48 1.1.8.2 nathanw #include <net/if.h>
49 1.1.8.2 nathanw #include <net/if_ether.h>
50 1.1.8.2 nathanw
51 1.1.8.2 nathanw #include <netinet/in.h>
52 1.1.8.2 nathanw #include <netinet/in_systm.h>
53 1.1.8.2 nathanw
54 1.1.8.2 nathanw #include <machine/idprom.h>
55 1.1.8.2 nathanw #include <machine/mon.h>
56 1.1.8.2 nathanw
57 1.1.8.2 nathanw #include <stand.h>
58 1.1.8.2 nathanw #include <net.h>
59 1.1.8.2 nathanw
60 1.1.8.2 nathanw #include "libsa.h"
61 1.1.8.2 nathanw #include "dvma.h"
62 1.1.8.2 nathanw #include "saio.h"
63 1.1.8.2 nathanw #include "netif.h"
64 1.1.8.2 nathanw
65 1.1.8.2 nathanw #define PKT_BUF_SIZE 2048
66 1.1.8.2 nathanw
67 1.1.8.2 nathanw int errno;
68 1.1.8.2 nathanw
69 1.1.8.2 nathanw struct iodesc sockets[SOPEN_MAX];
70 1.1.8.2 nathanw
71 1.1.8.2 nathanw struct netif prom_netif;
72 1.1.8.2 nathanw struct devdata {
73 1.1.8.2 nathanw struct saioreq dd_si;
74 1.1.8.2 nathanw int rbuf_len;
75 1.1.8.2 nathanw char *rbuf;
76 1.1.8.2 nathanw int tbuf_len;
77 1.1.8.2 nathanw char *tbuf;
78 1.1.8.2 nathanw u_short dd_opens;
79 1.1.8.2 nathanw u_char dd_myea[6];
80 1.1.8.2 nathanw } netif_devdata;
81 1.1.8.2 nathanw
82 1.1.8.2 nathanw void netif_getether(struct saif *, u_char *);
83 1.1.8.2 nathanw
84 1.1.8.2 nathanw
85 1.1.8.2 nathanw /*
86 1.1.8.2 nathanw * Open the PROM device.
87 1.1.8.2 nathanw * Return netif ptr on success.
88 1.1.8.2 nathanw */
89 1.1.8.2 nathanw struct devdata *
90 1.1.8.2 nathanw netif_init(aux)
91 1.1.8.2 nathanw void *aux;
92 1.1.8.2 nathanw {
93 1.1.8.2 nathanw struct devdata *dd = &netif_devdata;
94 1.1.8.2 nathanw struct saioreq *si;
95 1.1.8.2 nathanw struct bootparam *bp;
96 1.1.8.2 nathanw int error;
97 1.1.8.2 nathanw
98 1.1.8.2 nathanw /*
99 1.1.8.2 nathanw * Setup our part of the saioreq.
100 1.1.8.2 nathanw * (determines what gets opened)
101 1.1.8.2 nathanw */
102 1.1.8.2 nathanw si = &dd->dd_si;
103 1.1.8.2 nathanw bzero((caddr_t)si, sizeof(*si));
104 1.1.8.2 nathanw bp = *romVectorPtr->bootParam;
105 1.1.8.2 nathanw si->si_boottab = bp->bootDevice;
106 1.1.8.2 nathanw si->si_ctlr = bp->ctlrNum;
107 1.1.8.2 nathanw si->si_unit = bp->unitNum;
108 1.1.8.2 nathanw si->si_boff = bp->partNum;
109 1.1.8.2 nathanw
110 1.1.8.2 nathanw #ifdef NETIF_DEBUG
111 1.1.8.2 nathanw if (debug)
112 1.1.8.2 nathanw printf("netif_init: calling prom_iopen\n");
113 1.1.8.2 nathanw #endif
114 1.1.8.2 nathanw
115 1.1.8.2 nathanw /*
116 1.1.8.2 nathanw * Note: Sun PROMs will do RARP on open, but does not tell
117 1.1.8.2 nathanw * you the IP address it gets, so it is just noise to us...
118 1.1.8.2 nathanw */
119 1.1.8.2 nathanw if ((error = prom_iopen(si)) != 0) {
120 1.1.8.2 nathanw printf("netif_init: prom_iopen, error=%d\n", error);
121 1.1.8.2 nathanw return (NULL);
122 1.1.8.2 nathanw }
123 1.1.8.2 nathanw
124 1.1.8.2 nathanw if (si->si_sif == NULL) {
125 1.1.8.2 nathanw printf("netif_init: not a network device\n");
126 1.1.8.2 nathanw prom_iclose(si);
127 1.1.8.2 nathanw return (NULL);
128 1.1.8.2 nathanw }
129 1.1.8.2 nathanw
130 1.1.8.2 nathanw /* Allocate the transmit/receive buffers. */
131 1.1.8.2 nathanw if (dd->rbuf == NULL) {
132 1.1.8.2 nathanw dd->rbuf_len = PKT_BUF_SIZE;
133 1.1.8.2 nathanw dd->rbuf = dvma_alloc(dd->rbuf_len);
134 1.1.8.2 nathanw }
135 1.1.8.2 nathanw if (dd->tbuf == NULL) {
136 1.1.8.2 nathanw dd->tbuf_len = PKT_BUF_SIZE;
137 1.1.8.2 nathanw dd->tbuf = dvma_alloc(dd->tbuf_len);
138 1.1.8.2 nathanw }
139 1.1.8.2 nathanw if ((dd->rbuf == NULL) ||
140 1.1.8.2 nathanw (dd->tbuf == NULL))
141 1.1.8.2 nathanw panic("netif_init: malloc failed");
142 1.1.8.2 nathanw
143 1.1.8.2 nathanw #ifdef NETIF_DEBUG
144 1.1.8.2 nathanw if (debug)
145 1.1.8.2 nathanw printf("netif_init: rbuf=0x%x, tbuf=0x%x\n",
146 1.1.8.2 nathanw dd->rbuf, dd->tbuf);
147 1.1.8.2 nathanw #endif
148 1.1.8.2 nathanw
149 1.1.8.2 nathanw /* Record our ethernet address. */
150 1.1.8.2 nathanw netif_getether(si->si_sif, dd->dd_myea);
151 1.1.8.2 nathanw
152 1.1.8.2 nathanw dd->dd_opens = 0;
153 1.1.8.2 nathanw
154 1.1.8.2 nathanw return(dd);
155 1.1.8.2 nathanw }
156 1.1.8.2 nathanw
157 1.1.8.2 nathanw void
158 1.1.8.2 nathanw netif_fini(dd)
159 1.1.8.2 nathanw struct devdata *dd;
160 1.1.8.2 nathanw {
161 1.1.8.2 nathanw struct saioreq *si;
162 1.1.8.2 nathanw
163 1.1.8.2 nathanw si = &dd->dd_si;
164 1.1.8.2 nathanw
165 1.1.8.2 nathanw #ifdef NETIF_DEBUG
166 1.1.8.2 nathanw if (debug)
167 1.1.8.2 nathanw printf("netif_fini: calling prom_iclose\n");
168 1.1.8.2 nathanw #endif
169 1.1.8.2 nathanw
170 1.1.8.2 nathanw prom_iclose(si);
171 1.1.8.2 nathanw /* Dellocate the transmit/receive buffers. */
172 1.1.8.2 nathanw if (dd->rbuf) {
173 1.1.8.2 nathanw dvma_free(dd->rbuf, dd->rbuf_len);
174 1.1.8.2 nathanw dd->rbuf = NULL;
175 1.1.8.2 nathanw }
176 1.1.8.2 nathanw if (dd->tbuf) {
177 1.1.8.2 nathanw dvma_free(dd->tbuf, dd->tbuf_len);
178 1.1.8.2 nathanw dd->tbuf = NULL;
179 1.1.8.2 nathanw }
180 1.1.8.2 nathanw }
181 1.1.8.2 nathanw
182 1.1.8.2 nathanw int
183 1.1.8.2 nathanw netif_attach(nif, s, aux)
184 1.1.8.2 nathanw struct netif *nif;
185 1.1.8.2 nathanw struct iodesc *s;
186 1.1.8.2 nathanw void *aux;
187 1.1.8.2 nathanw {
188 1.1.8.2 nathanw struct devdata *dd;
189 1.1.8.2 nathanw
190 1.1.8.2 nathanw dd = nif->nif_devdata;
191 1.1.8.2 nathanw if (dd == NULL) {
192 1.1.8.2 nathanw dd = netif_init(aux);
193 1.1.8.2 nathanw if (dd == NULL)
194 1.1.8.2 nathanw return (ENXIO);
195 1.1.8.2 nathanw nif->nif_devdata = dd;
196 1.1.8.2 nathanw }
197 1.1.8.2 nathanw dd->dd_opens++;
198 1.1.8.2 nathanw MACPY(dd->dd_myea, s->myea);
199 1.1.8.2 nathanw s->io_netif = nif;
200 1.1.8.2 nathanw return(0);
201 1.1.8.2 nathanw }
202 1.1.8.2 nathanw
203 1.1.8.2 nathanw void
204 1.1.8.2 nathanw netif_detach(nif)
205 1.1.8.2 nathanw struct netif *nif;
206 1.1.8.2 nathanw {
207 1.1.8.2 nathanw struct devdata *dd;
208 1.1.8.2 nathanw
209 1.1.8.2 nathanw dd = nif->nif_devdata;
210 1.1.8.2 nathanw if (dd == NULL)
211 1.1.8.2 nathanw return;
212 1.1.8.2 nathanw dd->dd_opens--;
213 1.1.8.2 nathanw if (dd->dd_opens > 0)
214 1.1.8.2 nathanw return;
215 1.1.8.2 nathanw netif_fini(dd);
216 1.1.8.2 nathanw nif->nif_devdata = NULL;
217 1.1.8.2 nathanw }
218 1.1.8.2 nathanw
219 1.1.8.2 nathanw int
220 1.1.8.2 nathanw netif_open(aux)
221 1.1.8.2 nathanw void *aux;
222 1.1.8.2 nathanw {
223 1.1.8.2 nathanw struct netif *nif;
224 1.1.8.2 nathanw struct iodesc *s;
225 1.1.8.2 nathanw int fd, error;
226 1.1.8.2 nathanw
227 1.1.8.2 nathanw /* find a free socket */
228 1.1.8.2 nathanw for (fd = 0, s = sockets; fd < SOPEN_MAX; fd++, s++)
229 1.1.8.2 nathanw if (s->io_netif == NULL)
230 1.1.8.2 nathanw goto found;
231 1.1.8.2 nathanw errno = EMFILE;
232 1.1.8.2 nathanw return (-1);
233 1.1.8.2 nathanw
234 1.1.8.2 nathanw found:
235 1.1.8.2 nathanw bzero(s, sizeof(*s));
236 1.1.8.2 nathanw nif = &prom_netif;
237 1.1.8.2 nathanw error = netif_attach(nif, s);
238 1.1.8.2 nathanw if (error != 0) {
239 1.1.8.2 nathanw errno = error;
240 1.1.8.2 nathanw return (-1);
241 1.1.8.2 nathanw }
242 1.1.8.2 nathanw return (fd);
243 1.1.8.2 nathanw }
244 1.1.8.2 nathanw
245 1.1.8.2 nathanw int
246 1.1.8.2 nathanw netif_close(fd)
247 1.1.8.2 nathanw int fd;
248 1.1.8.2 nathanw {
249 1.1.8.2 nathanw struct iodesc *s;
250 1.1.8.2 nathanw struct netif *nif;
251 1.1.8.2 nathanw
252 1.1.8.2 nathanw if (fd < 0 || fd >= SOPEN_MAX) {
253 1.1.8.2 nathanw errno = EBADF;
254 1.1.8.2 nathanw return(-1);
255 1.1.8.2 nathanw }
256 1.1.8.2 nathanw s = &sockets[fd];
257 1.1.8.2 nathanw nif = s->io_netif;
258 1.1.8.2 nathanw /* Already closed? */
259 1.1.8.2 nathanw if (nif == NULL)
260 1.1.8.2 nathanw return(0);
261 1.1.8.2 nathanw netif_detach(nif);
262 1.1.8.2 nathanw s->io_netif = NULL;
263 1.1.8.2 nathanw return(0);
264 1.1.8.2 nathanw }
265 1.1.8.2 nathanw
266 1.1.8.2 nathanw
267 1.1.8.2 nathanw struct iodesc *
268 1.1.8.2 nathanw socktodesc(fd)
269 1.1.8.2 nathanw int fd;
270 1.1.8.2 nathanw {
271 1.1.8.2 nathanw if (fd < 0 || fd >= SOPEN_MAX) {
272 1.1.8.2 nathanw errno = EBADF;
273 1.1.8.2 nathanw return (NULL);
274 1.1.8.2 nathanw }
275 1.1.8.2 nathanw return (&sockets[fd]);
276 1.1.8.2 nathanw }
277 1.1.8.2 nathanw
278 1.1.8.2 nathanw
279 1.1.8.2 nathanw /*
280 1.1.8.2 nathanw * Send a packet. The ether header is already there.
281 1.1.8.2 nathanw * Return the length sent (or -1 on error).
282 1.1.8.2 nathanw */
283 1.1.8.2 nathanw int
284 1.1.8.2 nathanw netif_put(desc, pkt, len)
285 1.1.8.2 nathanw struct iodesc *desc;
286 1.1.8.2 nathanw void *pkt;
287 1.1.8.2 nathanw size_t len;
288 1.1.8.2 nathanw {
289 1.1.8.2 nathanw struct netif *nif;
290 1.1.8.2 nathanw struct devdata *dd;
291 1.1.8.2 nathanw struct saioreq *si;
292 1.1.8.2 nathanw struct saif *sif;
293 1.1.8.2 nathanw char *dmabuf;
294 1.1.8.2 nathanw int rv, slen;
295 1.1.8.2 nathanw
296 1.1.8.2 nathanw #ifdef NETIF_DEBUG
297 1.1.8.2 nathanw if (debug > 1) {
298 1.1.8.2 nathanw struct ether_header *eh;
299 1.1.8.2 nathanw
300 1.1.8.2 nathanw printf("netif_put: desc=0x%x pkt=0x%x len=%d\n",
301 1.1.8.2 nathanw desc, pkt, len);
302 1.1.8.2 nathanw eh = pkt;
303 1.1.8.2 nathanw printf("dst: %s ", ether_sprintf(eh->ether_dhost));
304 1.1.8.2 nathanw printf("src: %s ", ether_sprintf(eh->ether_shost));
305 1.1.8.2 nathanw printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
306 1.1.8.2 nathanw }
307 1.1.8.2 nathanw #endif
308 1.1.8.2 nathanw
309 1.1.8.2 nathanw nif = desc->io_netif;
310 1.1.8.2 nathanw dd = nif->nif_devdata;
311 1.1.8.2 nathanw si = &dd->dd_si;
312 1.1.8.2 nathanw sif = si->si_sif;
313 1.1.8.2 nathanw slen = len;
314 1.1.8.2 nathanw
315 1.1.8.2 nathanw #ifdef PARANOID
316 1.1.8.2 nathanw if (sif == NULL)
317 1.1.8.2 nathanw panic("netif_put: no saif ptr");
318 1.1.8.2 nathanw #endif
319 1.1.8.2 nathanw
320 1.1.8.2 nathanw /*
321 1.1.8.2 nathanw * Copy into our transmit buffer because the PROM
322 1.1.8.2 nathanw * network driver might continue using the packet
323 1.1.8.2 nathanw * after the sif_xmit call returns. We never send
324 1.1.8.2 nathanw * very much data anyway, so the copy is fine.
325 1.1.8.2 nathanw */
326 1.1.8.2 nathanw if (slen > dd->tbuf_len)
327 1.1.8.2 nathanw panic("netif_put: slen=%d", slen);
328 1.1.8.2 nathanw bcopy(pkt, dd->tbuf, slen);
329 1.1.8.2 nathanw
330 1.1.8.2 nathanw if (slen < 60) {
331 1.1.8.2 nathanw slen = 60;
332 1.1.8.2 nathanw }
333 1.1.8.2 nathanw
334 1.1.8.2 nathanw rv = (*sif->sif_xmit)(si->si_devdata, dd->tbuf, slen);
335 1.1.8.2 nathanw
336 1.1.8.2 nathanw #ifdef NETIF_DEBUG
337 1.1.8.2 nathanw if (debug > 1)
338 1.1.8.2 nathanw printf("netif_put: xmit returned %d\n", rv);
339 1.1.8.2 nathanw #endif
340 1.1.8.2 nathanw /*
341 1.1.8.2 nathanw * Just ignore the return value. If the PROM transmit
342 1.1.8.2 nathanw * function fails, it will make some noise, such as:
343 1.1.8.2 nathanw * le: No Carrier
344 1.1.8.2 nathanw */
345 1.1.8.2 nathanw
346 1.1.8.2 nathanw return len;
347 1.1.8.2 nathanw }
348 1.1.8.2 nathanw
349 1.1.8.2 nathanw /*
350 1.1.8.2 nathanw * Receive a packet, including the ether header.
351 1.1.8.2 nathanw * Return the total length received (or -1 on error).
352 1.1.8.2 nathanw */
353 1.1.8.2 nathanw int
354 1.1.8.2 nathanw netif_get(desc, pkt, maxlen, timo)
355 1.1.8.2 nathanw struct iodesc *desc;
356 1.1.8.2 nathanw void *pkt;
357 1.1.8.2 nathanw size_t maxlen;
358 1.1.8.2 nathanw time_t timo; /* seconds */
359 1.1.8.2 nathanw {
360 1.1.8.2 nathanw struct netif *nif;
361 1.1.8.2 nathanw struct devdata *dd;
362 1.1.8.2 nathanw struct saioreq *si;
363 1.1.8.2 nathanw struct saif *sif;
364 1.1.8.2 nathanw int tick0, tmo_ticks;
365 1.1.8.2 nathanw int rlen = 0;
366 1.1.8.2 nathanw
367 1.1.8.2 nathanw #ifdef NETIF_DEBUG
368 1.1.8.2 nathanw if (debug > 1)
369 1.1.8.2 nathanw printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
370 1.1.8.2 nathanw pkt, maxlen, timo);
371 1.1.8.2 nathanw #endif
372 1.1.8.2 nathanw
373 1.1.8.2 nathanw nif = desc->io_netif;
374 1.1.8.2 nathanw dd = nif->nif_devdata;
375 1.1.8.2 nathanw si = &dd->dd_si;
376 1.1.8.2 nathanw sif = si->si_sif;
377 1.1.8.2 nathanw
378 1.1.8.2 nathanw tmo_ticks = timo * hz;
379 1.1.8.2 nathanw
380 1.1.8.2 nathanw /* Have to receive into our own buffer and copy. */
381 1.1.8.2 nathanw do {
382 1.1.8.2 nathanw tick0 = getticks();
383 1.1.8.2 nathanw do {
384 1.1.8.2 nathanw rlen = (*sif->sif_poll)(si->si_devdata, dd->rbuf);
385 1.1.8.2 nathanw if (rlen != 0)
386 1.1.8.2 nathanw goto break2;
387 1.1.8.2 nathanw } while (getticks() == tick0);
388 1.1.8.2 nathanw } while (--tmo_ticks > 0);
389 1.1.8.2 nathanw
390 1.1.8.2 nathanw #if 0
391 1.1.8.2 nathanw /* No packet arrived. Better reset the interface. */
392 1.1.8.2 nathanw printf("netif_get: timeout; resetting\n");
393 1.1.8.2 nathanw (*sif->sif_reset)(si->si_devdata, si);
394 1.1.8.2 nathanw #endif
395 1.1.8.2 nathanw
396 1.1.8.2 nathanw break2:
397 1.1.8.2 nathanw
398 1.1.8.2 nathanw #ifdef NETIF_DEBUG
399 1.1.8.2 nathanw if (debug > 1)
400 1.1.8.2 nathanw printf("netif_get: received rlen=%d\n", rlen);
401 1.1.8.2 nathanw #endif
402 1.1.8.2 nathanw
403 1.1.8.2 nathanw /* Need at least a valid Ethernet header. */
404 1.1.8.2 nathanw if (rlen < 12)
405 1.1.8.2 nathanw return -1;
406 1.1.8.2 nathanw
407 1.1.8.2 nathanw /* If we went beyond our buffer, were dead! */
408 1.1.8.2 nathanw if (rlen > dd->rbuf_len)
409 1.1.8.2 nathanw panic("netif_get: rlen=%d", rlen);
410 1.1.8.2 nathanw
411 1.1.8.2 nathanw /* The caller's buffer may be smaller... */
412 1.1.8.2 nathanw if (rlen > maxlen)
413 1.1.8.2 nathanw rlen = maxlen;
414 1.1.8.2 nathanw
415 1.1.8.2 nathanw bcopy(dd->rbuf, pkt, rlen);
416 1.1.8.2 nathanw
417 1.1.8.2 nathanw #ifdef NETIF_DEBUG
418 1.1.8.2 nathanw if (debug > 1) {
419 1.1.8.2 nathanw struct ether_header *eh = pkt;
420 1.1.8.2 nathanw
421 1.1.8.2 nathanw printf("dst: %s ", ether_sprintf(eh->ether_dhost));
422 1.1.8.2 nathanw printf("src: %s ", ether_sprintf(eh->ether_shost));
423 1.1.8.2 nathanw printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
424 1.1.8.2 nathanw }
425 1.1.8.2 nathanw #endif
426 1.1.8.2 nathanw
427 1.1.8.2 nathanw return rlen;
428 1.1.8.2 nathanw }
429 1.1.8.2 nathanw
430 1.1.8.2 nathanw /*
431 1.1.8.2 nathanw * Copy our Ethernet address into the passed array.
432 1.1.8.2 nathanw */
433 1.1.8.2 nathanw void
434 1.1.8.2 nathanw netif_getether(sif, ea)
435 1.1.8.2 nathanw struct saif *sif;
436 1.1.8.2 nathanw u_char *ea;
437 1.1.8.2 nathanw {
438 1.1.8.2 nathanw char *rev;
439 1.1.8.2 nathanw
440 1.1.8.2 nathanw if (_is3x == 0) {
441 1.1.8.2 nathanw /*
442 1.1.8.2 nathanw * Sun3: These usually have old PROMs
443 1.1.8.2 nathanw * without the sif_macaddr function, but
444 1.1.8.2 nathanw * reading the IDPROM on these machines is
445 1.1.8.2 nathanw * very easy, so just always do that.
446 1.1.8.2 nathanw */
447 1.1.8.2 nathanw idprom_etheraddr(ea);
448 1.1.8.2 nathanw return;
449 1.1.8.2 nathanw }
450 1.1.8.2 nathanw
451 1.1.8.2 nathanw /*
452 1.1.8.2 nathanw * Sun3X: Want to use sif->sif_macaddr(), but
453 1.1.8.2 nathanw * it's only in PROM revisions 3.0 and later,
454 1.1.8.2 nathanw * so we have to check the PROM rev first.
455 1.1.8.2 nathanw * Note that old PROMs prefix the rev string
456 1.1.8.2 nathanw * with "Rev " (i.e. "Rev 2.6").
457 1.1.8.2 nathanw */
458 1.1.8.2 nathanw rev = romVectorPtr->monId;
459 1.1.8.2 nathanw if (!strncmp(rev, "Rev ", 4))
460 1.1.8.2 nathanw rev += 4;
461 1.1.8.2 nathanw if (!strncmp(rev, "3.", 2)) {
462 1.1.8.2 nathanw /* Great! We can call the PROM. */
463 1.1.8.2 nathanw (*sif->sif_macaddr)(ea);
464 1.1.8.2 nathanw return;
465 1.1.8.2 nathanw }
466 1.1.8.2 nathanw
467 1.1.8.2 nathanw /*
468 1.1.8.2 nathanw * Sun3X with PROM rev < 3.0.
469 1.1.8.2 nathanw * Finding the IDPROM is a pain, but
470 1.1.8.2 nathanw * we have no choice. Warn the user.
471 1.1.8.2 nathanw */
472 1.1.8.2 nathanw printf("netboot: Old PROM Rev (%s)\n", rev);
473 1.1.8.2 nathanw idprom_etheraddr(ea);
474 1.1.8.2 nathanw }
475