en.c revision 1.5 1 1.5 mycroft /* $NetBSD: en.c,v 1.5 2002/09/11 01:46:36 mycroft Exp $ */
2 1.1 dbj /*
3 1.1 dbj * Copyright (c) 1996 Rolf Grossmann
4 1.1 dbj * All rights reserved.
5 1.1 dbj *
6 1.1 dbj * Redistribution and use in source and binary forms, with or without
7 1.1 dbj * modification, are permitted provided that the following conditions
8 1.1 dbj * are met:
9 1.1 dbj * 1. Redistributions of source code must retain the above copyright
10 1.1 dbj * notice, this list of conditions and the following disclaimer.
11 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 dbj * notice, this list of conditions and the following disclaimer in the
13 1.1 dbj * documentation and/or other materials provided with the distribution.
14 1.1 dbj * 3. All advertising materials mentioning features or use of this software
15 1.1 dbj * must display the following acknowledgement:
16 1.1 dbj * This product includes software developed by Rolf Grossmann.
17 1.1 dbj * 4. The name of the author may not be used to endorse or promote products
18 1.1 dbj * derived from this software without specific prior written permission
19 1.1 dbj *
20 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 dbj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 dbj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 dbj * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 dbj * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 dbj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 dbj * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 dbj * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 dbj * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 dbj * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 dbj */
31 1.1 dbj
32 1.1 dbj #include <sys/param.h>
33 1.1 dbj #include <sys/types.h>
34 1.1 dbj #include <netinet/in.h>
35 1.1 dbj #include <netinet/in_systm.h>
36 1.1 dbj #include <next68k/dev/enreg.h>
37 1.1 dbj #include <next68k/next68k/nextrom.h>
38 1.1 dbj #include "enreg.h"
39 1.1 dbj #include "dmareg.h"
40 1.1 dbj
41 1.1 dbj #include <stand.h>
42 1.1 dbj #include <netif.h>
43 1.1 dbj #include <net.h>
44 1.1 dbj #include <nfs.h>
45 1.3 drochner
46 1.3 drochner #include <lib/libkern/libkern.h>
47 1.1 dbj
48 1.1 dbj extern char *mg;
49 1.1 dbj #define MON(type, off) (*(type *)((u_int) (mg) + off))
50 1.1 dbj
51 1.5 mycroft #define PRINTF(x) printf x;
52 1.1 dbj #ifdef EN_DEBUG
53 1.1 dbj #define DPRINTF(x) printf x;
54 1.1 dbj #else
55 1.1 dbj #define DPRINTF(x)
56 1.1 dbj #endif
57 1.1 dbj
58 1.1 dbj #define EN_TIMEOUT 2000000
59 1.1 dbj #define EN_RETRIES 10
60 1.1 dbj
61 1.1 dbj int en_match __P((struct netif *nif, void *machdep_hint));
62 1.1 dbj int en_probe __P((struct netif *nif, void *machdep_hint));
63 1.1 dbj void en_init __P((struct iodesc *desc, void *machdep_hint));
64 1.1 dbj int en_get __P((struct iodesc *a, void *b, size_t c, time_t d));
65 1.1 dbj int en_put __P((struct iodesc *a, void *b, size_t c));
66 1.1 dbj void en_end __P((struct netif *a));
67 1.1 dbj
68 1.1 dbj /* ### static int mountroot __P((int sock)); */
69 1.1 dbj static int en_wait_for_intr __P((int flag));
70 1.1 dbj
71 1.1 dbj struct netif_stats en_stats;
72 1.1 dbj
73 1.1 dbj struct netif_dif en_ifs[] = {
74 1.1 dbj /* dif_unit dif_nsel dif_stats dif_private */
75 1.1 dbj { 0, 1, &en_stats, NULL, },
76 1.1 dbj };
77 1.1 dbj
78 1.1 dbj struct netif_driver en_driver = {
79 1.1 dbj "en",
80 1.1 dbj en_match, en_probe, en_init, en_get, en_put, en_end,
81 1.1 dbj en_ifs, NENTS(en_ifs)
82 1.1 dbj };
83 1.1 dbj
84 1.5 mycroft int turbo = 1;
85 1.5 mycroft
86 1.1 dbj /* ### int netdev_sock;
87 1.1 dbj static int open_count; */
88 1.1 dbj
89 1.1 dbj char dma_buffer1[MAX_DMASIZE+DMA_ENDALIGNMENT],
90 1.1 dbj dma_buffer2[MAX_DMASIZE+DMA_ENDALIGNMENT],
91 1.1 dbj *dma_buffers[2];
92 1.1 dbj int next_dma_buffer;
93 1.1 dbj
94 1.1 dbj
95 1.1 dbj int
96 1.1 dbj en_match(struct netif *nif, void *machdep_hint)
97 1.1 dbj {
98 1.1 dbj /* we always match, because every NeXT has an ethernet interface
99 1.1 dbj * and we've checked the unit numbers before we even started this
100 1.1 dbj * search.
101 1.1 dbj * ### now that open is generic, we should check the params!
102 1.1 dbj */
103 1.1 dbj return 1;
104 1.1 dbj }
105 1.1 dbj
106 1.1 dbj int
107 1.1 dbj en_probe(struct netif *nif, void *machdep_hint)
108 1.1 dbj {
109 1.1 dbj /* we also always probe ok, see en_match. */
110 1.1 dbj return 0;
111 1.1 dbj }
112 1.1 dbj
113 1.1 dbj void
114 1.1 dbj en_init(struct iodesc *desc, void *machdep_hint)
115 1.1 dbj {
116 1.1 dbj volatile struct en_regs *er;
117 1.1 dbj volatile u_int *bmap_chip;
118 1.1 dbj int i;
119 1.1 dbj
120 1.1 dbj DPRINTF(("en_init\n"));
121 1.1 dbj
122 1.1 dbj er = (struct en_regs *)P_ENET;
123 1.1 dbj bmap_chip = (u_int *)P_BMAP;
124 1.1 dbj
125 1.1 dbj dma_buffers[0] = DMA_ALIGN(char *, dma_buffer1);
126 1.1 dbj dma_buffers[1] = DMA_ALIGN(char *, dma_buffer2);
127 1.1 dbj
128 1.1 dbj er->reset = EN_RST_RESET;
129 1.5 mycroft /* if (turbo) */
130 1.5 mycroft /* er->reset = 0; */
131 1.1 dbj
132 1.5 mycroft er->txmask = 0;
133 1.5 mycroft er->txstat = 0xff;
134 1.5 mycroft if (turbo)
135 1.5 mycroft er->txmode = 0 | EN_TMD_COLLSHIFT;
136 1.5 mycroft else
137 1.5 mycroft er->txmode = EN_TMD_LB_DISABLE;
138 1.5 mycroft
139 1.5 mycroft /* setup for bnc/tp */
140 1.5 mycroft if (turbo) {
141 1.5 mycroft
142 1.5 mycroft } else {
143 1.5 mycroft DPRINTF (("en_media: %s\n",
144 1.5 mycroft (bmap_chip[13] & 0x20000000) ? "BNC" : "TP"));
145 1.5 mycroft if (!(bmap_chip[13] & 0x20000000)) {
146 1.5 mycroft bmap_chip[12] |= 0x90000000;
147 1.5 mycroft bmap_chip[13] |= (0x80000000|0x10000000); /* TP */
148 1.5 mycroft }
149 1.4 christos }
150 1.1 dbj
151 1.5 mycroft /* if (turbo) { */
152 1.5 mycroft /* er->txmode |= EN_TMD_COLLSHIFT; */
153 1.5 mycroft /* } else { */
154 1.5 mycroft /* er->txmode &= ~EN_TMD_LB_DISABLE; /\* ZZZ *\/ */
155 1.5 mycroft /* } */
156 1.5 mycroft
157 1.1 dbj er->rxmask = 0;
158 1.1 dbj er->rxstat = 0xff;
159 1.5 mycroft if (turbo) {
160 1.5 mycroft er->rxmode = EN_RMD_TEST;
161 1.5 mycroft } else {
162 1.5 mycroft er->rxmode = EN_RMD_RECV_NORMAL;
163 1.5 mycroft }
164 1.1 dbj for (i=0; i<6; i++)
165 1.1 dbj er->addr[i] = desc->myea[i] = MON(char *,MG_clientetheraddr)[i];
166 1.1 dbj
167 1.1 dbj DPRINTF(("ethernet addr (%x:%x:%x:%x:%x:%x)\n",
168 1.1 dbj desc->myea[0],desc->myea[1],desc->myea[2],
169 1.1 dbj desc->myea[3],desc->myea[4],desc->myea[5]));
170 1.1 dbj
171 1.5 mycroft /* if (!turbo) */
172 1.5 mycroft er->reset = 0;
173 1.1 dbj }
174 1.1 dbj
175 1.2 dbj #if 0
176 1.1 dbj /* ### remove this when things work! */
177 1.1 dbj #define XCHR(x) "0123456789abcdef"[(x) & 0xf]
178 1.1 dbj void
179 1.1 dbj dump_pkt(unsigned char *pkt, size_t len)
180 1.1 dbj {
181 1.1 dbj size_t i, j;
182 1.1 dbj
183 1.1 dbj printf("0000: ");
184 1.1 dbj for(i=0; i<len; i++) {
185 1.1 dbj printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i]));
186 1.1 dbj if ((i+1) % 16 == 0) {
187 1.1 dbj printf(" %c", '"');
188 1.1 dbj for(j=0; j<16; j++)
189 1.1 dbj printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.');
190 1.1 dbj printf("%c\n%c%c%c%c: ", '"', XCHR((i+1)>>12),
191 1.1 dbj XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1));
192 1.1 dbj }
193 1.1 dbj }
194 1.1 dbj printf("\n");
195 1.1 dbj }
196 1.2 dbj #endif
197 1.1 dbj
198 1.1 dbj int
199 1.1 dbj en_put(struct iodesc *desc, void *pkt, size_t len)
200 1.1 dbj {
201 1.1 dbj volatile struct en_regs *er;
202 1.1 dbj volatile struct dma_dev *txdma;
203 1.1 dbj int state, txs;
204 1.1 dbj int retries;
205 1.1 dbj
206 1.1 dbj DPRINTF(("en_put: %d bytes at 0x%lx\n", len, (unsigned long)pkt));
207 1.1 dbj #if 0
208 1.1 dbj dump_pkt(pkt,len);
209 1.1 dbj #endif
210 1.1 dbj
211 1.1 dbj er = (struct en_regs *)P_ENET;
212 1.1 dbj txdma = (struct dma_dev *)P_ENETX_CSR;
213 1.1 dbj
214 1.1 dbj DPRINTF(("en_put: txdma->dd_csr = %x\n",txdma->dd_csr));
215 1.1 dbj
216 1.1 dbj if (len > 1600) {
217 1.1 dbj errno = EINVAL;
218 1.1 dbj return -1;
219 1.1 dbj }
220 1.1 dbj
221 1.5 mycroft if (!turbo) {
222 1.5 mycroft while ((er->txstat & EN_TXS_READY) == 0)
223 1.5 mycroft printf("en: tx not ready\n");
224 1.5 mycroft }
225 1.1 dbj
226 1.1 dbj for (retries = 0; retries < EN_RETRIES; retries++) {
227 1.1 dbj er->txstat = 0xff;
228 1.1 dbj bcopy(pkt, dma_buffers[0], len);
229 1.5 mycroft txdma->dd_csr = (turbo ? DMACSR_INITBUFTURBO : DMACSR_INITBUF) |
230 1.5 mycroft DMACSR_RESET | DMACSR_WRITE;
231 1.1 dbj txdma->dd_csr = 0;
232 1.5 mycroft txdma->dd_next/* _initbuf */ = dma_buffers[0];
233 1.5 mycroft txdma->dd_start = (turbo ? dma_buffers[0] : 0);
234 1.1 dbj txdma->dd_limit = ENDMA_ENDALIGN(char *, dma_buffers[0]+len);
235 1.1 dbj txdma->dd_stop = 0;
236 1.1 dbj txdma->dd_csr = DMACSR_SETENABLE;
237 1.5 mycroft if (turbo)
238 1.5 mycroft er->txmode |= 0x80;
239 1.5 mycroft
240 1.1 dbj while(1) {
241 1.1 dbj if (en_wait_for_intr(ENETX_DMA_INTR)) {
242 1.1 dbj errno = EIO;
243 1.1 dbj return -1;
244 1.1 dbj }
245 1.1 dbj
246 1.1 dbj state = txdma->dd_csr &
247 1.1 dbj (DMACSR_BUSEXC | DMACSR_COMPLETE
248 1.1 dbj | DMACSR_SUPDATE | DMACSR_ENABLE);
249 1.1 dbj
250 1.5 mycroft #if 01
251 1.1 dbj DPRINTF(("en_put: dma state = 0x%x.\n", state));
252 1.1 dbj #endif
253 1.1 dbj if (state & (DMACSR_COMPLETE|DMACSR_BUSEXC))
254 1.1 dbj txdma->dd_csr = DMACSR_RESET | DMACSR_CLRCOMPLETE;
255 1.1 dbj break;
256 1.1 dbj }
257 1.1 dbj
258 1.1 dbj txs = er->txstat;
259 1.1 dbj
260 1.5 mycroft #if 01
261 1.1 dbj DPRINTF(("en_put: done txstat=%x.\n", txs));
262 1.1 dbj #endif
263 1.1 dbj
264 1.1 dbj #define EN_TXS_ERROR (EN_TXS_SHORTED | EN_TXS_UNDERFLOW | EN_TXS_PARERR)
265 1.1 dbj if ((state & DMACSR_COMPLETE) == 0 ||
266 1.1 dbj (txs & EN_TXS_ERROR) != 0) {
267 1.1 dbj errno = EIO;
268 1.1 dbj return -1;
269 1.1 dbj }
270 1.1 dbj if ((txs & EN_TXS_COLLERR) == 0)
271 1.1 dbj return len; /* success */
272 1.1 dbj }
273 1.1 dbj
274 1.1 dbj errno = EIO; /* too many retries */
275 1.1 dbj return -1;
276 1.1 dbj }
277 1.1 dbj
278 1.1 dbj int
279 1.1 dbj en_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
280 1.1 dbj {
281 1.1 dbj volatile struct en_regs *er;
282 1.1 dbj volatile struct dma_dev *rxdma;
283 1.5 mycroft volatile struct dma_dev *txdma;
284 1.1 dbj int state, rxs;
285 1.1 dbj size_t rlen;
286 1.1 dbj char *gotpkt;
287 1.1 dbj
288 1.1 dbj rxdma = (struct dma_dev *)P_ENETR_CSR;
289 1.5 mycroft txdma = (struct dma_dev *)P_ENETX_CSR;
290 1.1 dbj er = (struct en_regs *)P_ENET;
291 1.1 dbj
292 1.5 mycroft DPRINTF(("en_get: rxdma->dd_csr = %x\n",rxdma->dd_csr));
293 1.5 mycroft
294 1.1 dbj er->rxstat = 0xff;
295 1.1 dbj
296 1.1 dbj /* this is mouse's code now ... still doesn't work :( */
297 1.1 dbj /* The previous comment is now a lie, this does work
298 1.1 dbj * Darrin B Jewell <jewell (at) mit.edu> Sat Jan 24 21:44:56 1998
299 1.1 dbj */
300 1.1 dbj
301 1.1 dbj rxdma->dd_csr = 0;
302 1.5 mycroft rxdma->dd_csr = (turbo ? DMACSR_INITBUFTURBO : DMACSR_INITBUF) |
303 1.5 mycroft DMACSR_READ | DMACSR_RESET;
304 1.1 dbj
305 1.5 mycroft if (!turbo) {
306 1.5 mycroft rxdma->dd_saved_next = 0;
307 1.5 mycroft rxdma->dd_saved_limit = 0;
308 1.5 mycroft rxdma->dd_saved_start = 0;
309 1.5 mycroft rxdma->dd_saved_stop = 0;
310 1.5 mycroft } else {
311 1.5 mycroft rxdma->dd_saved_next = dma_buffers[0];
312 1.5 mycroft }
313 1.1 dbj
314 1.1 dbj rxdma->dd_next = dma_buffers[0];
315 1.1 dbj rxdma->dd_limit = DMA_ENDALIGN(char *, dma_buffers[0]+MAX_DMASIZE);
316 1.5 mycroft #if 0
317 1.5 mycroft if (turbo) {
318 1.5 mycroft /* !!! not a typo: txdma */
319 1.5 mycroft txdma->dd_stop = dma_buffers[0];
320 1.5 mycroft }
321 1.5 mycroft #endif
322 1.1 dbj rxdma->dd_start = 0;
323 1.1 dbj rxdma->dd_stop = 0;
324 1.5 mycroft rxdma->dd_csr = DMACSR_SETENABLE | DMACSR_READ;
325 1.5 mycroft if (turbo) {
326 1.5 mycroft er->rxmode = EN_RMD_TEST | EN_RMD_RECV_MULTI;
327 1.5 mycroft } else {
328 1.5 mycroft er->rxmode = EN_RMD_RECV_NORMAL;
329 1.5 mycroft }
330 1.1 dbj
331 1.5 mycroft #if 01
332 1.1 dbj DPRINTF(("en_get: blocking on rcv dma\n"));
333 1.1 dbj #endif
334 1.1 dbj
335 1.1 dbj while(1) {
336 1.1 dbj if (en_wait_for_intr(ENETR_DMA_INTR)) { /* ### use timeout? */
337 1.1 dbj errno = EIO;
338 1.1 dbj return -1;
339 1.1 dbj }
340 1.1 dbj
341 1.1 dbj state = rxdma->dd_csr &
342 1.1 dbj (DMACSR_BUSEXC | DMACSR_COMPLETE
343 1.1 dbj | DMACSR_SUPDATE | DMACSR_ENABLE);
344 1.1 dbj DPRINTF(("en_get: dma state = 0x%x.\n", state));
345 1.1 dbj if ((state & DMACSR_ENABLE) == 0) {
346 1.1 dbj rxdma->dd_csr = DMACSR_RESET | DMACSR_CLRCOMPLETE;
347 1.1 dbj break;
348 1.1 dbj }
349 1.1 dbj
350 1.1 dbj if (state & DMACSR_COMPLETE) {
351 1.5 mycroft PRINTF(("en_get: ending dma sequence\n"));
352 1.1 dbj rxdma->dd_csr = DMACSR_CLRCOMPLETE;
353 1.1 dbj }
354 1.1 dbj
355 1.1 dbj }
356 1.1 dbj
357 1.1 dbj rxs = er->rxstat;
358 1.1 dbj
359 1.1 dbj if ((state & DMACSR_COMPLETE) == 0 ||
360 1.1 dbj (rxs & EN_RX_OK) == 0) {
361 1.1 dbj errno = EIO;
362 1.1 dbj return -1; /* receive failed */
363 1.1 dbj }
364 1.1 dbj
365 1.5 mycroft if (turbo) {
366 1.5 mycroft gotpkt = rxdma->dd_saved_next;
367 1.5 mycroft rlen = rxdma->dd_next - rxdma->dd_saved_next;
368 1.5 mycroft } else {
369 1.5 mycroft gotpkt = rxdma->dd_saved_next;
370 1.5 mycroft rlen = rxdma->dd_next - rxdma->dd_saved_next;
371 1.5 mycroft }
372 1.1 dbj
373 1.1 dbj if (gotpkt != dma_buffers[0]) {
374 1.1 dbj printf("Unexpected received packet location\n");
375 1.1 dbj printf("DEBUG: rxstat=%x.\n", rxs);
376 1.1 dbj printf("DEBUG: gotpkt = 0x%lx, rlen = %d, len = %d\n",(u_long)gotpkt,rlen,len);
377 1.1 dbj printf("DEBUG: rxdma->dd_csr = 0x%lx\n",(u_long)rxdma->dd_csr);
378 1.1 dbj printf("DEBUG: rxdma->dd_saved_next = 0x%lx\n",(u_long)rxdma->dd_saved_next);
379 1.1 dbj printf("DEBUG: rxdma->dd_saved_limit = 0x%lx\n",(u_long)rxdma->dd_saved_limit);
380 1.1 dbj printf("DEBUG: rxdma->dd_saved_start = 0x%lx\n",(u_long)rxdma->dd_saved_start);
381 1.1 dbj printf("DEBUG: rxdma->dd_saved_stop = 0x%lx\n",(u_long)rxdma->dd_saved_stop);
382 1.1 dbj printf("DEBUG: rxdma->dd_next = 0x%lx\n",(u_long)rxdma->dd_next);
383 1.1 dbj printf("DEBUG: rxdma->dd_limit = 0x%lx\n",(u_long)rxdma->dd_limit);
384 1.1 dbj printf("DEBUG: rxdma->dd_start = 0x%lx\n",(u_long)rxdma->dd_start);
385 1.1 dbj printf("DEBUG: rxdma->dd_stop = 0x%lx\n",(u_long)rxdma->dd_stop);
386 1.1 dbj printf("DEBUG: rxdma->dd_next_initbuf = 0x%lx\n",(u_long)rxdma->dd_next_initbuf);
387 1.1 dbj }
388 1.1 dbj
389 1.1 dbj #if 0
390 1.1 dbj dump_pkt(gotpkt, rlen < 255 ? rlen : 128);
391 1.1 dbj #endif
392 1.1 dbj
393 1.1 dbj DPRINTF(("en_get: done rxstat=%x.\n", rxs));
394 1.1 dbj
395 1.1 dbj if (rlen > len) {
396 1.1 dbj DPRINTF(("en_get: buffer too small. want %d, got %d\n",
397 1.1 dbj len, rlen));
398 1.1 dbj rlen = len;
399 1.1 dbj }
400 1.1 dbj
401 1.1 dbj
402 1.1 dbj bcopy(gotpkt, pkt, rlen);
403 1.1 dbj
404 1.1 dbj #if 0
405 1.1 dbj printf("DEBUG: gotpkt = 0x%lx, pkt = 0x%lx, rlen = %d\n",
406 1.1 dbj (u_long)gotpkt,(u_long)pkt,rlen);
407 1.1 dbj dump_pkt(gotpkt, rlen < 255 ? rlen : 128);
408 1.1 dbj dump_pkt(pkt, rlen < 255 ? rlen : 128);
409 1.1 dbj #endif
410 1.1 dbj
411 1.1 dbj return rlen;
412 1.1 dbj }
413 1.1 dbj
414 1.1 dbj
415 1.1 dbj void
416 1.1 dbj en_end(struct netif *a)
417 1.1 dbj {
418 1.1 dbj DPRINTF(("en_end: WARNING not doing anything\n"));
419 1.1 dbj }
420 1.1 dbj
421 1.1 dbj #if 0
422 1.1 dbj
423 1.1 dbj #define MKPANIC(ret,name,args) \
424 1.1 dbj ret name args { panic(#name ## ": not implemented.\n"); }
425 1.1 dbj
426 1.1 dbj MKPANIC(void, en_end, (struct netif *a));
427 1.1 dbj
428 1.1 dbj /* device functions */
429 1.1 dbj
430 1.1 dbj int
431 1.1 dbj enopen(struct open_file *f, char count, char lun, char part)
432 1.1 dbj {
433 1.1 dbj int error;
434 1.1 dbj
435 1.1 dbj DPRINTF(("open: en(%d,%d,%d)\n", count, lun, part));
436 1.1 dbj
437 1.1 dbj if (count != 0 || lun != 0 || part != 0)
438 1.1 dbj return EUNIT; /* there can be exactly one ethernet */
439 1.1 dbj
440 1.1 dbj if (open_count == 0) {
441 1.1 dbj /* Find network interface. */
442 1.1 dbj if ((netdev_sock = netif_open(NULL)) < 0)
443 1.1 dbj return errno;
444 1.1 dbj if ((error = mountroot(netdev_sock)) != 0) {
445 1.1 dbj if (open_count == 0)
446 1.1 dbj netif_close(netdev_sock);
447 1.1 dbj return error;
448 1.1 dbj }
449 1.1 dbj }
450 1.1 dbj open_count++;
451 1.1 dbj f->f_devdata = NULL; /* ### nfs_root_node ?! */
452 1.1 dbj return 0;
453 1.1 dbj }
454 1.1 dbj
455 1.1 dbj int
456 1.1 dbj enclose(struct open_file *f)
457 1.1 dbj {
458 1.1 dbj if (open_count > 0)
459 1.1 dbj if (--open_count == 0)
460 1.1 dbj netif_close(netdev_sock);
461 1.1 dbj f->f_devdata = NULL;
462 1.1 dbj return 0;
463 1.1 dbj }
464 1.1 dbj
465 1.1 dbj int
466 1.1 dbj enstrategy(void *devdata, int rw, daddr_t dblk,
467 1.1 dbj size_t size, void *buf, size_t *rsize)
468 1.1 dbj {
469 1.1 dbj return ENXIO; /* wrong access method */
470 1.1 dbj }
471 1.1 dbj
472 1.1 dbj /* private function */
473 1.1 dbj
474 1.1 dbj static int
475 1.1 dbj mountroot(int sock)
476 1.1 dbj {
477 1.1 dbj /* Mount the root directory from a boot server */
478 1.1 dbj #if 0
479 1.1 dbj struct in_addr in = {
480 1.1 dbj 0xc2793418
481 1.1 dbj };
482 1.1 dbj u_char *res;
483 1.1 dbj
484 1.1 dbj res = arpwhohas(socktodesc(sock), in);
485 1.1 dbj panic("arpwhohas returned %s", res);
486 1.1 dbj #endif
487 1.1 dbj /* 1. use bootp. This does most of the work for us. */
488 1.1 dbj bootp(sock);
489 1.1 dbj
490 1.1 dbj if (myip.s_addr == 0 || rootip.s_addr == 0 || rootpath[0] == '\0')
491 1.1 dbj return ETIMEDOUT;
492 1.1 dbj
493 1.1 dbj printf("Using IP address: %s\n", inet_ntoa(myip));
494 1.1 dbj printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
495 1.1 dbj
496 1.1 dbj /* 2. mount. */
497 1.1 dbj if (nfs_mount(sock, rootip, rootpath) < 0)
498 1.1 dbj return errno;
499 1.1 dbj
500 1.1 dbj return 0;
501 1.1 dbj }
502 1.1 dbj #endif
503 1.1 dbj
504 1.1 dbj static int
505 1.1 dbj en_wait_for_intr(int flag)
506 1.1 dbj {
507 1.1 dbj volatile int *intrstat = MON(volatile int *,MG_intrstat);
508 1.1 dbj
509 1.1 dbj int count;
510 1.1 dbj
511 1.1 dbj for(count = 0; count < EN_TIMEOUT; count++)
512 1.1 dbj if (*intrstat & flag)
513 1.1 dbj return 0;
514 1.1 dbj
515 1.1 dbj printf("enintr: timed out.\n");
516 1.1 dbj return -1;
517 1.1 dbj }
518