en.c revision 1.7 1 1.7 mycroft /* $NetBSD: en.c,v 1.7 2002/09/11 06:32:07 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.6 mycroft extern int turbo;
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.6 mycroft if (!turbo) {
141 1.5 mycroft DPRINTF (("en_media: %s\n",
142 1.5 mycroft (bmap_chip[13] & 0x20000000) ? "BNC" : "TP"));
143 1.5 mycroft if (!(bmap_chip[13] & 0x20000000)) {
144 1.5 mycroft bmap_chip[12] |= 0x90000000;
145 1.5 mycroft bmap_chip[13] |= (0x80000000|0x10000000); /* TP */
146 1.5 mycroft }
147 1.4 christos }
148 1.1 dbj
149 1.5 mycroft /* if (turbo) { */
150 1.5 mycroft /* er->txmode |= EN_TMD_COLLSHIFT; */
151 1.5 mycroft /* } else { */
152 1.5 mycroft /* er->txmode &= ~EN_TMD_LB_DISABLE; /\* ZZZ *\/ */
153 1.5 mycroft /* } */
154 1.5 mycroft
155 1.1 dbj er->rxmask = 0;
156 1.1 dbj er->rxstat = 0xff;
157 1.5 mycroft if (turbo) {
158 1.5 mycroft er->rxmode = EN_RMD_TEST;
159 1.5 mycroft } else {
160 1.5 mycroft er->rxmode = EN_RMD_RECV_NORMAL;
161 1.5 mycroft }
162 1.1 dbj for (i=0; i<6; i++)
163 1.1 dbj er->addr[i] = desc->myea[i] = MON(char *,MG_clientetheraddr)[i];
164 1.1 dbj
165 1.1 dbj DPRINTF(("ethernet addr (%x:%x:%x:%x:%x:%x)\n",
166 1.1 dbj desc->myea[0],desc->myea[1],desc->myea[2],
167 1.1 dbj desc->myea[3],desc->myea[4],desc->myea[5]));
168 1.1 dbj
169 1.5 mycroft /* if (!turbo) */
170 1.5 mycroft er->reset = 0;
171 1.1 dbj }
172 1.1 dbj
173 1.2 dbj #if 0
174 1.1 dbj /* ### remove this when things work! */
175 1.1 dbj #define XCHR(x) "0123456789abcdef"[(x) & 0xf]
176 1.1 dbj void
177 1.1 dbj dump_pkt(unsigned char *pkt, size_t len)
178 1.1 dbj {
179 1.1 dbj size_t i, j;
180 1.1 dbj
181 1.1 dbj printf("0000: ");
182 1.1 dbj for(i=0; i<len; i++) {
183 1.1 dbj printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i]));
184 1.1 dbj if ((i+1) % 16 == 0) {
185 1.1 dbj printf(" %c", '"');
186 1.1 dbj for(j=0; j<16; j++)
187 1.1 dbj printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.');
188 1.1 dbj printf("%c\n%c%c%c%c: ", '"', XCHR((i+1)>>12),
189 1.1 dbj XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1));
190 1.1 dbj }
191 1.1 dbj }
192 1.1 dbj printf("\n");
193 1.1 dbj }
194 1.2 dbj #endif
195 1.1 dbj
196 1.1 dbj int
197 1.1 dbj en_put(struct iodesc *desc, void *pkt, size_t len)
198 1.1 dbj {
199 1.1 dbj volatile struct en_regs *er;
200 1.1 dbj volatile struct dma_dev *txdma;
201 1.1 dbj int state, txs;
202 1.1 dbj int retries;
203 1.1 dbj
204 1.1 dbj DPRINTF(("en_put: %d bytes at 0x%lx\n", len, (unsigned long)pkt));
205 1.1 dbj #if 0
206 1.1 dbj dump_pkt(pkt,len);
207 1.1 dbj #endif
208 1.1 dbj
209 1.1 dbj er = (struct en_regs *)P_ENET;
210 1.1 dbj txdma = (struct dma_dev *)P_ENETX_CSR;
211 1.1 dbj
212 1.1 dbj DPRINTF(("en_put: txdma->dd_csr = %x\n",txdma->dd_csr));
213 1.1 dbj
214 1.1 dbj if (len > 1600) {
215 1.1 dbj errno = EINVAL;
216 1.1 dbj return -1;
217 1.1 dbj }
218 1.1 dbj
219 1.5 mycroft if (!turbo) {
220 1.5 mycroft while ((er->txstat & EN_TXS_READY) == 0)
221 1.5 mycroft printf("en: tx not ready\n");
222 1.5 mycroft }
223 1.1 dbj
224 1.1 dbj for (retries = 0; retries < EN_RETRIES; retries++) {
225 1.1 dbj er->txstat = 0xff;
226 1.1 dbj bcopy(pkt, dma_buffers[0], len);
227 1.5 mycroft txdma->dd_csr = (turbo ? DMACSR_INITBUFTURBO : DMACSR_INITBUF) |
228 1.5 mycroft DMACSR_RESET | DMACSR_WRITE;
229 1.1 dbj txdma->dd_csr = 0;
230 1.5 mycroft txdma->dd_next/* _initbuf */ = dma_buffers[0];
231 1.5 mycroft txdma->dd_start = (turbo ? dma_buffers[0] : 0);
232 1.1 dbj txdma->dd_limit = ENDMA_ENDALIGN(char *, dma_buffers[0]+len);
233 1.1 dbj txdma->dd_stop = 0;
234 1.1 dbj txdma->dd_csr = DMACSR_SETENABLE;
235 1.5 mycroft if (turbo)
236 1.5 mycroft er->txmode |= 0x80;
237 1.5 mycroft
238 1.1 dbj while(1) {
239 1.1 dbj if (en_wait_for_intr(ENETX_DMA_INTR)) {
240 1.7 mycroft printf("en_put: timed out\n");
241 1.1 dbj errno = EIO;
242 1.1 dbj return -1;
243 1.1 dbj }
244 1.1 dbj
245 1.1 dbj state = txdma->dd_csr &
246 1.1 dbj (DMACSR_BUSEXC | DMACSR_COMPLETE
247 1.1 dbj | DMACSR_SUPDATE | DMACSR_ENABLE);
248 1.1 dbj
249 1.5 mycroft #if 01
250 1.1 dbj DPRINTF(("en_put: dma state = 0x%x.\n", state));
251 1.1 dbj #endif
252 1.1 dbj if (state & (DMACSR_COMPLETE|DMACSR_BUSEXC))
253 1.1 dbj txdma->dd_csr = DMACSR_RESET | DMACSR_CLRCOMPLETE;
254 1.1 dbj break;
255 1.1 dbj }
256 1.1 dbj
257 1.1 dbj txs = er->txstat;
258 1.1 dbj
259 1.5 mycroft #if 01
260 1.1 dbj DPRINTF(("en_put: done txstat=%x.\n", txs));
261 1.1 dbj #endif
262 1.1 dbj
263 1.1 dbj #define EN_TXS_ERROR (EN_TXS_SHORTED | EN_TXS_UNDERFLOW | EN_TXS_PARERR)
264 1.1 dbj if ((state & DMACSR_COMPLETE) == 0 ||
265 1.1 dbj (txs & EN_TXS_ERROR) != 0) {
266 1.1 dbj errno = EIO;
267 1.1 dbj return -1;
268 1.1 dbj }
269 1.1 dbj if ((txs & EN_TXS_COLLERR) == 0)
270 1.1 dbj return len; /* success */
271 1.1 dbj }
272 1.1 dbj
273 1.1 dbj errno = EIO; /* too many retries */
274 1.1 dbj return -1;
275 1.1 dbj }
276 1.1 dbj
277 1.1 dbj int
278 1.1 dbj en_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
279 1.1 dbj {
280 1.1 dbj volatile struct en_regs *er;
281 1.1 dbj volatile struct dma_dev *rxdma;
282 1.5 mycroft volatile struct dma_dev *txdma;
283 1.1 dbj int state, rxs;
284 1.1 dbj size_t rlen;
285 1.1 dbj char *gotpkt;
286 1.1 dbj
287 1.1 dbj rxdma = (struct dma_dev *)P_ENETR_CSR;
288 1.5 mycroft txdma = (struct dma_dev *)P_ENETX_CSR;
289 1.1 dbj er = (struct en_regs *)P_ENET;
290 1.1 dbj
291 1.5 mycroft DPRINTF(("en_get: rxdma->dd_csr = %x\n",rxdma->dd_csr));
292 1.5 mycroft
293 1.1 dbj er->rxstat = 0xff;
294 1.1 dbj
295 1.1 dbj /* this is mouse's code now ... still doesn't work :( */
296 1.1 dbj /* The previous comment is now a lie, this does work
297 1.1 dbj * Darrin B Jewell <jewell (at) mit.edu> Sat Jan 24 21:44:56 1998
298 1.1 dbj */
299 1.1 dbj
300 1.1 dbj rxdma->dd_csr = 0;
301 1.5 mycroft rxdma->dd_csr = (turbo ? DMACSR_INITBUFTURBO : DMACSR_INITBUF) |
302 1.5 mycroft DMACSR_READ | DMACSR_RESET;
303 1.1 dbj
304 1.5 mycroft if (!turbo) {
305 1.5 mycroft rxdma->dd_saved_next = 0;
306 1.5 mycroft rxdma->dd_saved_limit = 0;
307 1.5 mycroft rxdma->dd_saved_start = 0;
308 1.5 mycroft rxdma->dd_saved_stop = 0;
309 1.5 mycroft } else {
310 1.5 mycroft rxdma->dd_saved_next = dma_buffers[0];
311 1.5 mycroft }
312 1.1 dbj
313 1.1 dbj rxdma->dd_next = dma_buffers[0];
314 1.1 dbj rxdma->dd_limit = DMA_ENDALIGN(char *, dma_buffers[0]+MAX_DMASIZE);
315 1.5 mycroft #if 0
316 1.5 mycroft if (turbo) {
317 1.5 mycroft /* !!! not a typo: txdma */
318 1.5 mycroft txdma->dd_stop = dma_buffers[0];
319 1.5 mycroft }
320 1.5 mycroft #endif
321 1.1 dbj rxdma->dd_start = 0;
322 1.1 dbj rxdma->dd_stop = 0;
323 1.5 mycroft rxdma->dd_csr = DMACSR_SETENABLE | DMACSR_READ;
324 1.5 mycroft if (turbo) {
325 1.5 mycroft er->rxmode = EN_RMD_TEST | EN_RMD_RECV_MULTI;
326 1.5 mycroft } else {
327 1.5 mycroft er->rxmode = EN_RMD_RECV_NORMAL;
328 1.5 mycroft }
329 1.1 dbj
330 1.5 mycroft #if 01
331 1.1 dbj DPRINTF(("en_get: blocking on rcv dma\n"));
332 1.1 dbj #endif
333 1.1 dbj
334 1.1 dbj while(1) {
335 1.7 mycroft if (en_wait_for_intr(ENETR_DMA_INTR)) /* ### use timeout? */
336 1.7 mycroft return 0;
337 1.1 dbj
338 1.1 dbj state = rxdma->dd_csr &
339 1.1 dbj (DMACSR_BUSEXC | DMACSR_COMPLETE
340 1.1 dbj | DMACSR_SUPDATE | DMACSR_ENABLE);
341 1.1 dbj DPRINTF(("en_get: dma state = 0x%x.\n", state));
342 1.1 dbj if ((state & DMACSR_ENABLE) == 0) {
343 1.1 dbj rxdma->dd_csr = DMACSR_RESET | DMACSR_CLRCOMPLETE;
344 1.1 dbj break;
345 1.1 dbj }
346 1.1 dbj
347 1.1 dbj if (state & DMACSR_COMPLETE) {
348 1.5 mycroft PRINTF(("en_get: ending dma sequence\n"));
349 1.1 dbj rxdma->dd_csr = DMACSR_CLRCOMPLETE;
350 1.1 dbj }
351 1.1 dbj
352 1.1 dbj }
353 1.1 dbj
354 1.1 dbj rxs = er->rxstat;
355 1.1 dbj
356 1.1 dbj if ((state & DMACSR_COMPLETE) == 0 ||
357 1.1 dbj (rxs & EN_RX_OK) == 0) {
358 1.1 dbj errno = EIO;
359 1.1 dbj return -1; /* receive failed */
360 1.1 dbj }
361 1.1 dbj
362 1.5 mycroft if (turbo) {
363 1.5 mycroft gotpkt = rxdma->dd_saved_next;
364 1.5 mycroft rlen = rxdma->dd_next - rxdma->dd_saved_next;
365 1.5 mycroft } else {
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 }
369 1.1 dbj
370 1.1 dbj if (gotpkt != dma_buffers[0]) {
371 1.1 dbj printf("Unexpected received packet location\n");
372 1.1 dbj printf("DEBUG: rxstat=%x.\n", rxs);
373 1.1 dbj printf("DEBUG: gotpkt = 0x%lx, rlen = %d, len = %d\n",(u_long)gotpkt,rlen,len);
374 1.1 dbj printf("DEBUG: rxdma->dd_csr = 0x%lx\n",(u_long)rxdma->dd_csr);
375 1.1 dbj printf("DEBUG: rxdma->dd_saved_next = 0x%lx\n",(u_long)rxdma->dd_saved_next);
376 1.1 dbj printf("DEBUG: rxdma->dd_saved_limit = 0x%lx\n",(u_long)rxdma->dd_saved_limit);
377 1.1 dbj printf("DEBUG: rxdma->dd_saved_start = 0x%lx\n",(u_long)rxdma->dd_saved_start);
378 1.1 dbj printf("DEBUG: rxdma->dd_saved_stop = 0x%lx\n",(u_long)rxdma->dd_saved_stop);
379 1.1 dbj printf("DEBUG: rxdma->dd_next = 0x%lx\n",(u_long)rxdma->dd_next);
380 1.1 dbj printf("DEBUG: rxdma->dd_limit = 0x%lx\n",(u_long)rxdma->dd_limit);
381 1.1 dbj printf("DEBUG: rxdma->dd_start = 0x%lx\n",(u_long)rxdma->dd_start);
382 1.1 dbj printf("DEBUG: rxdma->dd_stop = 0x%lx\n",(u_long)rxdma->dd_stop);
383 1.1 dbj printf("DEBUG: rxdma->dd_next_initbuf = 0x%lx\n",(u_long)rxdma->dd_next_initbuf);
384 1.1 dbj }
385 1.1 dbj
386 1.1 dbj #if 0
387 1.1 dbj dump_pkt(gotpkt, rlen < 255 ? rlen : 128);
388 1.1 dbj #endif
389 1.1 dbj
390 1.1 dbj DPRINTF(("en_get: done rxstat=%x.\n", rxs));
391 1.1 dbj
392 1.1 dbj if (rlen > len) {
393 1.1 dbj DPRINTF(("en_get: buffer too small. want %d, got %d\n",
394 1.1 dbj len, rlen));
395 1.1 dbj rlen = len;
396 1.1 dbj }
397 1.1 dbj
398 1.1 dbj
399 1.1 dbj bcopy(gotpkt, pkt, rlen);
400 1.1 dbj
401 1.1 dbj #if 0
402 1.1 dbj printf("DEBUG: gotpkt = 0x%lx, pkt = 0x%lx, rlen = %d\n",
403 1.1 dbj (u_long)gotpkt,(u_long)pkt,rlen);
404 1.1 dbj dump_pkt(gotpkt, rlen < 255 ? rlen : 128);
405 1.1 dbj dump_pkt(pkt, rlen < 255 ? rlen : 128);
406 1.1 dbj #endif
407 1.1 dbj
408 1.1 dbj return rlen;
409 1.1 dbj }
410 1.1 dbj
411 1.1 dbj
412 1.1 dbj void
413 1.1 dbj en_end(struct netif *a)
414 1.1 dbj {
415 1.1 dbj DPRINTF(("en_end: WARNING not doing anything\n"));
416 1.1 dbj }
417 1.1 dbj
418 1.1 dbj #if 0
419 1.1 dbj
420 1.1 dbj #define MKPANIC(ret,name,args) \
421 1.1 dbj ret name args { panic(#name ## ": not implemented.\n"); }
422 1.1 dbj
423 1.1 dbj MKPANIC(void, en_end, (struct netif *a));
424 1.1 dbj
425 1.1 dbj /* device functions */
426 1.1 dbj
427 1.1 dbj int
428 1.1 dbj enopen(struct open_file *f, char count, char lun, char part)
429 1.1 dbj {
430 1.1 dbj int error;
431 1.1 dbj
432 1.1 dbj DPRINTF(("open: en(%d,%d,%d)\n", count, lun, part));
433 1.1 dbj
434 1.1 dbj if (count != 0 || lun != 0 || part != 0)
435 1.1 dbj return EUNIT; /* there can be exactly one ethernet */
436 1.1 dbj
437 1.1 dbj if (open_count == 0) {
438 1.1 dbj /* Find network interface. */
439 1.1 dbj if ((netdev_sock = netif_open(NULL)) < 0)
440 1.1 dbj return errno;
441 1.1 dbj if ((error = mountroot(netdev_sock)) != 0) {
442 1.1 dbj if (open_count == 0)
443 1.1 dbj netif_close(netdev_sock);
444 1.1 dbj return error;
445 1.1 dbj }
446 1.1 dbj }
447 1.1 dbj open_count++;
448 1.1 dbj f->f_devdata = NULL; /* ### nfs_root_node ?! */
449 1.1 dbj return 0;
450 1.1 dbj }
451 1.1 dbj
452 1.1 dbj int
453 1.1 dbj enclose(struct open_file *f)
454 1.1 dbj {
455 1.1 dbj if (open_count > 0)
456 1.1 dbj if (--open_count == 0)
457 1.1 dbj netif_close(netdev_sock);
458 1.1 dbj f->f_devdata = NULL;
459 1.1 dbj return 0;
460 1.1 dbj }
461 1.1 dbj
462 1.1 dbj int
463 1.1 dbj enstrategy(void *devdata, int rw, daddr_t dblk,
464 1.1 dbj size_t size, void *buf, size_t *rsize)
465 1.1 dbj {
466 1.1 dbj return ENXIO; /* wrong access method */
467 1.1 dbj }
468 1.1 dbj
469 1.1 dbj /* private function */
470 1.1 dbj
471 1.1 dbj static int
472 1.1 dbj mountroot(int sock)
473 1.1 dbj {
474 1.1 dbj /* Mount the root directory from a boot server */
475 1.1 dbj #if 0
476 1.1 dbj struct in_addr in = {
477 1.1 dbj 0xc2793418
478 1.1 dbj };
479 1.1 dbj u_char *res;
480 1.1 dbj
481 1.1 dbj res = arpwhohas(socktodesc(sock), in);
482 1.1 dbj panic("arpwhohas returned %s", res);
483 1.1 dbj #endif
484 1.1 dbj /* 1. use bootp. This does most of the work for us. */
485 1.1 dbj bootp(sock);
486 1.1 dbj
487 1.1 dbj if (myip.s_addr == 0 || rootip.s_addr == 0 || rootpath[0] == '\0')
488 1.1 dbj return ETIMEDOUT;
489 1.1 dbj
490 1.1 dbj printf("Using IP address: %s\n", inet_ntoa(myip));
491 1.1 dbj printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
492 1.1 dbj
493 1.1 dbj /* 2. mount. */
494 1.1 dbj if (nfs_mount(sock, rootip, rootpath) < 0)
495 1.1 dbj return errno;
496 1.1 dbj
497 1.1 dbj return 0;
498 1.1 dbj }
499 1.1 dbj #endif
500 1.1 dbj
501 1.1 dbj static int
502 1.1 dbj en_wait_for_intr(int flag)
503 1.1 dbj {
504 1.1 dbj volatile int *intrstat = MON(volatile int *,MG_intrstat);
505 1.1 dbj
506 1.1 dbj int count;
507 1.1 dbj
508 1.1 dbj for(count = 0; count < EN_TIMEOUT; count++)
509 1.1 dbj if (*intrstat & flag)
510 1.1 dbj return 0;
511 1.1 dbj
512 1.1 dbj return -1;
513 1.1 dbj }
514