Home | History | Annotate | Line # | Download | only in ic
ne2000.c revision 1.2
      1 /*	$NetBSD: ne2000.c,v 1.2 1997/10/14 22:54:09 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
     42  * adapters.
     43  *
     44  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
     45  *
     46  * Copyright (C) 1993, David Greenman.  This software may be used, modified,
     47  * copied, distributed, and sold, in both source and binary form provided that
     48  * the above copyright and these terms are retained.  Under no circumstances is
     49  * the author responsible for the proper functioning of this software, nor does
     50  * the author assume any responsibility for damages incurred with its use.
     51  */
     52 
     53 /*
     54  * Common code shared by all NE2000-compatible Ethernet interfaces.
     55  */
     56 
     57 #include <sys/param.h>
     58 #include <sys/systm.h>
     59 #include <sys/device.h>
     60 #include <sys/socket.h>
     61 #include <sys/mbuf.h>
     62 #include <sys/syslog.h>
     63 
     64 #include <net/if.h>
     65 #include <net/if_dl.h>
     66 #include <net/if_types.h>
     67 
     68 #include <net/if_ether.h>
     69 
     70 #include <machine/bus.h>
     71 
     72 #include <dev/ic/dp8390reg.h>
     73 #include <dev/ic/dp8390var.h>
     74 
     75 #include <dev/ic/ne2000reg.h>
     76 #include <dev/ic/ne2000var.h>
     77 
     78 struct cfdriver ne_cd = {
     79 	NULL, "ne", DV_IFNET
     80 };
     81 
     82 int	ne2000_write_mbuf __P((struct dp8390_softc *, struct mbuf *, int));
     83 int	ne2000_ring_copy __P((struct dp8390_softc *, int, caddr_t, u_short));
     84 void	ne2000_read_hdr __P((struct dp8390_softc *, int, struct dp8390_ring *));
     85 int	ne2000_test_mem __P((struct dp8390_softc *));
     86 
     87 void	ne2000_writemem __P((bus_space_tag_t, bus_space_handle_t,
     88 	    bus_space_tag_t, bus_space_handle_t, u_int8_t *, int, size_t, int));
     89 void	ne2000_readmem __P((bus_space_tag_t, bus_space_handle_t,
     90 	    bus_space_tag_t, bus_space_handle_t, int, u_int8_t *, size_t, int));
     91 
     92 void
     93 ne2000_attach(nsc, myea)
     94 	struct ne2000_softc *nsc;
     95 	u_int8_t *myea;
     96 {
     97 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
     98 	bus_space_tag_t nict = dsc->sc_regt;
     99 	bus_space_handle_t nich = dsc->sc_regh;
    100 	bus_space_tag_t asict = nsc->sc_asict;
    101 	bus_space_handle_t asich = nsc->sc_asich;
    102 	u_int8_t romdata[16];
    103 	int memsize, i, useword;
    104 
    105 	/*
    106 	 * Detect it again; this gives us the memory size.
    107 	 */
    108 	nsc->sc_type = ne2000_detect(nict, nich, asict, asich);
    109 	if (nsc->sc_type == 0) {
    110 		printf("%s: where did the card go?\n", dsc->sc_dev.dv_xname);
    111 		return;
    112 	}
    113 
    114 	useword = (nsc->sc_type == NE2000_TYPE_NE2000);
    115 
    116 	dsc->cr_proto = ED_CR_RD2;
    117 
    118 	/*
    119 	 * DCR gets:
    120 	 *
    121 	 *	FIFO threshold to 8, No auto-init Remote DMA,
    122 	 *	byte order=80x86.
    123 	 *
    124 	 * NE1000 gets byte-wide DMA, NE2000 gets word-wide DMA.
    125 	 */
    126 	dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
    127 	    (nsc->sc_type == NE2000_TYPE_NE2000 ? ED_DCR_WTS : 0);
    128 
    129 	dsc->test_mem = ne2000_test_mem;
    130 	dsc->ring_copy = ne2000_ring_copy;
    131 	dsc->write_mbuf = ne2000_write_mbuf;
    132 	dsc->read_hdr = ne2000_read_hdr;
    133 
    134 	/* Registers are linear. */
    135 	for (i = 0; i < 16; i++)
    136 		dsc->sc_reg_map[i] = i;
    137 
    138 	/*
    139 	 * 8k of memory plus an additional 8k if an NE2000.
    140 	 */
    141 	memsize = 8192 + (nsc->sc_type == NE2000_TYPE_NE2000 ? 8192 : 0);
    142 
    143 	/*
    144 	 * NIC memory doens't start at zero on an NE board.
    145 	 * The start address is tied to the bus width.
    146 	 * (It happens to be computed the same way as mem size.)
    147 	 */
    148 	dsc->mem_start = memsize;
    149 
    150 #ifdef GWETHER
    151 	{
    152 		int x, mstart = 0;
    153 		int8_t pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE],
    154 		    tbuf[ED_PAGE_SIZE];
    155 
    156 		for (i = 0; i < ED_PAGE_SIZE; i++)
    157 			pbuf0[i] = 0;
    158 
    159 		/* Search for the start of RAM. */
    160 		for (x = 1; x < 256; x++) {
    161 			ne2000_writemem(nict, nich, asict, asich, pbuf0,
    162 			    x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword);
    163 			ne2000_readmem(nict, nich, asict, asich,
    164 			    x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
    165 			if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
    166 				for (i = 0; i < ED_PAGE_SIZE; i++)
    167 					pbuf[i] = 255 - x;
    168 				ne2000_writemem(nict, nich, asict, asich,
    169 				    pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
    170 				    useword);
    171 				ne2000_readmem(nict, nich, asict, asich,
    172 				    x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE,
    173 				    useword);
    174 				if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
    175 					mstart = x << ED_PAGE_SHIFT;
    176 					memsize = ED_PAGE_SIZE;
    177 					break;
    178 				}
    179 			}
    180 		}
    181 
    182 		if (mstart == 0) {
    183 			printf("%s: cannot find start of RAM\n",
    184 			    dsc->sc_dev.dv_xname);
    185 			return;
    186 		}
    187 
    188 		/* Search for the end of RAM. */
    189 		for (++x; x < 256; x++) {
    190 			ne2000_writemem(nict, nich, asict, asich, pbuf0,
    191 			    x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword);
    192 			ne2000_readmem(nict, nich, asict, asich,
    193 			    x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
    194 			if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
    195 				for (i = 0; i < ED_PAGE_SIZE; i++)
    196 					pbuf[i] = 255 - x;
    197 				ne2000_writemem(nict, nich, asict, asich,
    198 				    pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
    199 				    useword);
    200 				ne2000_readmem(nict, nich, asict, asich,
    201 				    x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE
    202 				    useword);
    203 				if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
    204 					memsize += ED_PAGE_SIZE;
    205 				else
    206 					break;
    207 			} else
    208 				break;
    209 		}
    210 
    211 		printf("%s: RAM start 0x%x, size %d\n",
    212 		    dsc->sc_dev.dv_xname, mstart, msize);
    213 
    214 		dsc->mem_start = mstart;
    215 	}
    216 #endif /* GWETHER */
    217 
    218 	dsc->mem_size = memsize;
    219 
    220 	if (myea == NULL) {
    221 		/* Read the station address. */
    222 		ne2000_readmem(nict, nich, asict, asich, 0, romdata,
    223 		    sizeof(romdata), useword);
    224 		for (i = 0; i < ETHER_ADDR_LEN; i++)
    225 			dsc->sc_enaddr[i] = romdata[i * (useword ? 2 : 1)];
    226 	} else
    227 		bcopy(myea, dsc->sc_enaddr, sizeof(dsc->sc_enaddr));
    228 
    229 	/* Clear any pending interrupts that might have occurred above. */
    230 	bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
    231 
    232 	if (dp8390_config(dsc)) {
    233 		printf("%s: setup failed\n", dsc->sc_dev.dv_xname);
    234 		return;
    235 	}
    236 
    237 	/*
    238 	 * We need to compute mem_ring a bit differently; override the
    239 	 * value set up in dp8390_config().
    240 	 */
    241 	dsc->mem_ring =
    242 	    dsc->mem_start + ((dsc->txb_cnt * ED_TXBUF_SIZE) << ED_PAGE_SHIFT);
    243 }
    244 
    245 /*
    246  * Detect an NE-2000 or compatible.  Returns a model code.
    247  */
    248 int
    249 ne2000_detect(nict, nich, asict, asich)
    250 	bus_space_tag_t nict;
    251 	bus_space_handle_t nich;
    252 	bus_space_tag_t asict;
    253 	bus_space_handle_t asich;
    254 {
    255 	static u_int8_t test_pattern[32] = "THIS is A memory TEST pattern";
    256 	u_int8_t test_buffer[32], tmp;
    257 	int i, rv = 0;
    258 
    259 	/* Reset the board. */
    260 #ifdef GWETHER
    261 	bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0);
    262 	delay(200);
    263 #endif /* GWETHER */
    264 	tmp = bus_space_read_1(asict, asich, NE2000_ASIC_RESET);
    265 	delay(10000);
    266 
    267 	/*
    268 	 * I don't know if this is necessary; probably cruft leftover from
    269 	 * Clarkson packet driver code. Doesn't do a thing on the boards I've
    270 	 * tested. -DG [note that a outb(0x84, 0) seems to work here, and is
    271 	 * non-invasive...but some boards don't seem to reset and I don't have
    272 	 * complete documentation on what the 'right' thing to do is...so we do
    273 	 * the invasive thing for now.  Yuck.]
    274 	 */
    275 	bus_space_write_1(asict, asich, NE2000_ASIC_RESET, tmp);
    276 	delay(5000);
    277 
    278 	/*
    279 	 * This is needed because some NE clones apparently don't reset the
    280 	 * NIC properly (or the NIC chip doesn't reset fully on power-up).
    281 	 * XXX - this makes the probe invasive!  Done against my better
    282 	 * judgement.  -DLG
    283 	 */
    284 	bus_space_write_1(nict, nich, ED_P0_CR,
    285 	    ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
    286 
    287 	delay(5000);
    288 
    289 	tmp = bus_space_read_1(nict, nich, ED_P0_CR);
    290 	if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
    291 	    (ED_CR_RD2 | ED_CR_STP))
    292 		goto out;
    293 
    294 	bus_space_write_1(nict, nich,
    295 	    ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
    296 
    297 	for (i = 0; i < 100; i++) {
    298 		if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
    299 		    ED_ISR_RST) {
    300 			/* Ack the reset bit. */
    301 			bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
    302 			break;
    303 		}
    304 		delay(100);
    305 	}
    306 
    307 #if 0
    308 	/* XXX */
    309 	if (i == 100)
    310 		goto out;
    311 #endif
    312 
    313 	/*
    314 	 * Test the ability to read and write to the NIC memory.  This has
    315 	 * the side effect of determining if this is an NE1000 or an NE2000.
    316 	 */
    317 
    318 	/*
    319 	 * This prevents packets from being stored in the NIC memory when
    320 	 * the readmem routine turns on the start bit in the CR.
    321 	 */
    322 	bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
    323 
    324 	/* Temporarily initialize DCR for byte operations. */
    325 	bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
    326 
    327 	bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT);
    328 	bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT);
    329 
    330 	/*
    331 	 * Write a test pattern in byte mode.  If this fails, then there
    332 	 * probably isn't any memory at 8k - which likely means that the
    333 	 * board is an NE2000.
    334 	 */
    335 	ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192,
    336 	    sizeof(test_pattern), 0);
    337 	ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer,
    338 	    sizeof(test_buffer), 0);
    339 
    340 	if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
    341 		/* not an NE1000 - try NE2000 */
    342 		bus_space_write_1(nict, nich, ED_P0_DCR,
    343 		    ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
    344 		bus_space_write_1(nict, nich, ED_P0_PSTART,
    345 		    16384 >> ED_PAGE_SHIFT);
    346 		bus_space_write_1(nict, nich, ED_P0_PSTOP,
    347 		    32768 >> ED_PAGE_SHIFT);
    348 
    349 		/*
    350 		 * Write the test pattern in word mode.  If this also fails,
    351 		 * then we don't know what this board is.
    352 		 */
    353 		ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384,
    354 		    sizeof(test_pattern), 1);
    355 		ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer,
    356 		    sizeof(test_buffer), 1);
    357 
    358 		if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)))
    359 			goto out;	/* not an NE2000 either */
    360 
    361 		rv = NE2000_TYPE_NE2000;
    362 	} else {
    363 		/* We're an NE1000. */
    364 		rv = NE2000_TYPE_NE1000;
    365 	}
    366 
    367 	/* Clear any pending interrupts that might have occurred above. */
    368 	bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
    369 
    370  out:
    371 	return (rv);
    372 }
    373 
    374 /*
    375  * Write an mbuf chain to the destination NIC memory address using programmed
    376  * I/O.
    377  */
    378 int
    379 ne2000_write_mbuf(sc, m, buf)
    380 	struct dp8390_softc *sc;
    381 	struct mbuf *m;
    382 	int buf;
    383 {
    384 	struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
    385 	bus_space_tag_t nict = sc->sc_regt;
    386 	bus_space_handle_t nich = sc->sc_regh;
    387 	bus_space_tag_t asict = nsc->sc_asict;
    388 	bus_space_handle_t asich = nsc->sc_asich;
    389 	int savelen;
    390 	int maxwait = 100;	/* about 120us */
    391 
    392 	savelen = m->m_pkthdr.len;
    393 
    394 	/* Select page 0 registers. */
    395 	NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
    396 
    397 	/* Reset remote DMA complete flag. */
    398 	NIC_PUT(nict, nich, ED_P0_ISR, ED_ISR_RDC);
    399 
    400 	/* Set up DMA byte count. */
    401 	NIC_PUT(nict, nich, ED_P0_RBCR0, savelen);
    402 	NIC_PUT(nict, nich, ED_P0_RBCR1, savelen >> 8);
    403 
    404 	/* Set up destination address in NIC mem. */
    405 	NIC_PUT(nict, nich, ED_P0_RSAR0, buf);
    406 	NIC_PUT(nict, nich, ED_P0_RSAR1, buf >> 8);
    407 
    408 	/* Set remote DMA write. */
    409 	NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
    410 
    411 	/*
    412 	 * Transfer the mbuf chain to the NIC memory.  NE2000 cards
    413 	 * require that data be transferred as words, and only words,
    414 	 * so that case requires some extra code to patch over odd-length
    415 	 * mbufs.
    416 	 */
    417 	if (nsc->sc_type == NE2000_TYPE_NE1000) {
    418 		/* NE1000s are easy. */
    419 		for (; m != 0; m = m->m_next) {
    420 			if (m->m_len) {
    421 				bus_space_write_multi_1(asict, asich,
    422 				    NE2000_ASIC_DATA, mtod(m, u_int8_t *),
    423 				    m->m_len);
    424 			}
    425 		}
    426 	} else {
    427 		/* NE2000s are a bit trickier. */
    428 		u_int8_t *data, savebyte[2];
    429 		int l, wantbyte;
    430 
    431 		wantbyte = 0;
    432 		for (; m != 0; m = m->m_next) {
    433 			l = m->m_len;
    434 			if (l == 0)
    435 				continue;
    436 			data = mtod(m, u_int8_t *);
    437 			/* Finish the last word. */
    438 			if (wantbyte) {
    439 				savebyte[1] = *data;
    440 				bus_space_write_2(asict, asich,
    441 				    NE2000_ASIC_DATA, *(u_int16_t *)savebyte);
    442 				data++;
    443 				l--;
    444 				wantbyte = 0;
    445 			}
    446 			/* Output contiguous words. */
    447 			if (l > 1) {
    448 				bus_space_write_multi_2(asict, asich,
    449 				    NE2000_ASIC_DATA, (u_int16_t *)data,
    450 				    l >> 1);
    451 			}
    452 			/* Save last byte, if necessary. */
    453 			if (l & 1) {
    454 				data += l & ~1;
    455 				savebyte[0] = *data;
    456 				wantbyte = 1;
    457 			}
    458 		}
    459 
    460 		if (wantbyte) {
    461 			savebyte[1] = 0;
    462 			bus_space_write_2(asict, asich, NE2000_ASIC_DATA,
    463 			    *(u_int16_t *)savebyte);
    464 		}
    465 	}
    466 
    467 	/*
    468 	 * Wait for remote DMA to complete.  This is necessary because on the
    469 	 * transmit side, data is handled internally by the NIC in bursts, and
    470 	 * we can't start another remote DMA until this one completes.  Not
    471 	 * waiting causes really bad things to happen - like the NIC wedging
    472 	 * the bus.
    473 	 */
    474 	while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
    475 	    ED_ISR_RDC) && --maxwait);
    476 
    477 	if (maxwait == 0) {
    478 		log(LOG_WARNING,
    479 		    "%s: remote transmit DMA failed to complete\n",
    480 		    sc->sc_dev.dv_xname);
    481 		dp8390_reset(sc);
    482 	}
    483 
    484 	return (savelen);
    485 }
    486 
    487 /*
    488  * Given a source and destination address, copy 'amout' of a packet from
    489  * the ring buffer into a linear destination buffer.  Takes into account
    490  * ring-wrap.
    491  */
    492 int
    493 ne2000_ring_copy(sc, src, dst, amount)
    494 	struct dp8390_softc *sc;
    495 	int src;
    496 	caddr_t dst;
    497 	u_short amount;
    498 {
    499 	struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
    500 	bus_space_tag_t nict = sc->sc_regt;
    501 	bus_space_handle_t nich = sc->sc_regh;
    502 	bus_space_tag_t asict = nsc->sc_asict;
    503 	bus_space_handle_t asich = nsc->sc_asich;
    504 	u_short tmp_amount;
    505 	int useword = (nsc->sc_type == NE2000_TYPE_NE2000);
    506 
    507 	/* Does copy wrap to lower addr in ring buffer? */
    508 	if (src + amount > sc->mem_end) {
    509 		tmp_amount = sc->mem_end - src;
    510 
    511 		/* Copy amount up to end of NIC memory. */
    512 		ne2000_readmem(nict, nich, asict, asich, src,
    513 		    (u_int8_t *)dst, tmp_amount, useword);
    514 
    515 		amount -= tmp_amount;
    516 		src = sc->mem_ring;
    517 		dst += tmp_amount;
    518 	}
    519 
    520 	ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst,
    521 	    amount, useword);
    522 
    523 	return (src + amount);
    524 }
    525 
    526 void
    527 ne2000_read_hdr(sc, buf, hdr)
    528 	struct dp8390_softc *sc;
    529 	int buf;
    530 	struct dp8390_ring *hdr;
    531 {
    532 	struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
    533 
    534 	ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich,
    535 	    buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring),
    536 	    (nsc->sc_type == NE2000_TYPE_NE2000));
    537 }
    538 
    539 int
    540 ne2000_test_mem(sc)
    541 	struct dp8390_softc *sc;
    542 {
    543 
    544 	/* Noop. */
    545 	return (0);
    546 }
    547 
    548 /*
    549  * Given a NIC memory source address and a host memory destination address,
    550  * copy 'amount' from NIC to host using programmed i/o.  The 'amount' is
    551  * rounded up to a word - ok as long as mbufs are word sized.
    552  */
    553 void
    554 ne2000_readmem(nict, nich, asict, asich, src, dst, amount, useword)
    555 	bus_space_tag_t nict;
    556 	bus_space_handle_t nich;
    557 	bus_space_tag_t asict;
    558 	bus_space_handle_t asich;
    559 	int src;
    560 	u_int8_t *dst;
    561 	size_t amount;
    562 	int useword;
    563 {
    564 
    565 	/* Select page 0 registers. */
    566 	bus_space_write_1(nict, nich, ED_P0_CR,
    567 	    ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
    568 
    569 	/* Round up to a word. */
    570 	if (amount & 1)
    571 		++amount;
    572 
    573 	/* Set up DMA byte count. */
    574 	bus_space_write_1(nict, nich, ED_P0_RBCR0, amount);
    575 	bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8);
    576 
    577 	/* Set up source address in NIC mem. */
    578 	bus_space_write_1(nict, nich, ED_P0_RSAR0, src);
    579 	bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8);
    580 
    581 	bus_space_write_1(nict, nich, ED_P0_CR,
    582 	    ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA);
    583 
    584 	if (useword)
    585 		bus_space_read_multi_2(asict, asich, NE2000_ASIC_DATA,
    586 		    (u_int16_t *)dst, amount >> 1);
    587 	else
    588 		bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA,
    589 		    dst, amount);
    590 }
    591 
    592 /*
    593  * Stripped down routine for writing a linear buffer to NIC memory.  Only
    594  * used in the probe routine to test the memory.  'len' must be even.
    595  */
    596 void
    597 ne2000_writemem(nict, nich, asict, asich, src, dst, len, useword)
    598 	bus_space_tag_t nict;
    599 	bus_space_handle_t nich;
    600 	bus_space_tag_t asict;
    601 	bus_space_handle_t asich;
    602 	u_int8_t *src;
    603 	int dst;
    604 	size_t len;
    605 	int useword;
    606 {
    607 	int maxwait = 100;	/* about 120us */
    608 
    609 	/* Select page 0 registers. */
    610 	bus_space_write_1(nict, nich, ED_P0_CR,
    611 	    ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
    612 
    613 	/* Reset remote DMA complete flag. */
    614 	bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
    615 
    616 	/* Set up DMA byte count. */
    617 	bus_space_write_1(nict, nich, ED_P0_RBCR0, len);
    618 	bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8);
    619 
    620 	/* Set up destination address in NIC mem. */
    621 	bus_space_write_1(nict, nich, ED_P0_RSAR0, dst);
    622 	bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8);
    623 
    624 	/* Set remote DMA write. */
    625 	bus_space_write_1(nict, nich, ED_P0_CR,
    626 	    ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
    627 
    628 	if (useword)
    629 		bus_space_write_multi_2(asict, asich, NE2000_ASIC_DATA,
    630 		    (u_int16_t *)src, len >> 1);
    631 	else
    632 		bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA,
    633 		    src, len);
    634 
    635 	/*
    636 	 * Wait for remote DMA to complete.  This is necessary because on the
    637 	 * transmit side, data is handled internally by the NIC in bursts, and
    638 	 * we can't start another remote DMA until this one completes.  Not
    639 	 * waiting causes really bad things to happen - like the NIC wedging
    640 	 * the bus.
    641 	 */
    642 	while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
    643 	    ED_ISR_RDC) && --maxwait);
    644 
    645 	if (maxwait == 0)
    646 		printf("ne2000_writemem: failed to complete\n");
    647 }
    648