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