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