ne2000.c revision 1.8 1 /* $NetBSD: ne2000.c,v 1.8 1998/01/26 20:30:09 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 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 #include <net/if_media.h>
68
69 #include <net/if_ether.h>
70
71 #include <machine/bus.h>
72
73 #include <dev/ic/dp8390reg.h>
74 #include <dev/ic/dp8390var.h>
75
76 #include <dev/ic/ne2000reg.h>
77 #include <dev/ic/ne2000var.h>
78
79 int ne2000_write_mbuf __P((struct dp8390_softc *, struct mbuf *, int));
80 int ne2000_ring_copy __P((struct dp8390_softc *, int, caddr_t, u_short));
81 void ne2000_read_hdr __P((struct dp8390_softc *, int, struct dp8390_ring *));
82 int ne2000_test_mem __P((struct dp8390_softc *));
83
84 void ne2000_writemem __P((bus_space_tag_t, bus_space_handle_t,
85 bus_space_tag_t, bus_space_handle_t, u_int8_t *, int, size_t, int));
86 void ne2000_readmem __P((bus_space_tag_t, bus_space_handle_t,
87 bus_space_tag_t, bus_space_handle_t, int, u_int8_t *, size_t, int));
88
89 void
90 ne2000_attach(nsc, myea)
91 struct ne2000_softc *nsc;
92 u_int8_t *myea;
93 {
94 struct dp8390_softc *dsc = &nsc->sc_dp8390;
95 bus_space_tag_t nict = dsc->sc_regt;
96 bus_space_handle_t nich = dsc->sc_regh;
97 bus_space_tag_t asict = nsc->sc_asict;
98 bus_space_handle_t asich = nsc->sc_asich;
99 u_int8_t romdata[16];
100 int memsize, i, useword;
101
102 /*
103 * Detect it again; this gives us the memory size.
104 */
105 nsc->sc_type = ne2000_detect(nict, nich, asict, asich);
106 if (nsc->sc_type == 0) {
107 printf("%s: where did the card go?\n", dsc->sc_dev.dv_xname);
108 return;
109 }
110
111 useword = (nsc->sc_type == NE2000_TYPE_NE2000);
112
113 dsc->cr_proto = ED_CR_RD2;
114
115 /*
116 * DCR gets:
117 *
118 * FIFO threshold to 8, No auto-init Remote DMA,
119 * byte order=80x86.
120 *
121 * NE1000 gets byte-wide DMA, NE2000 gets word-wide DMA.
122 */
123 dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
124 (nsc->sc_type == NE2000_TYPE_NE2000 ? ED_DCR_WTS : 0);
125
126 dsc->test_mem = ne2000_test_mem;
127 dsc->ring_copy = ne2000_ring_copy;
128 dsc->write_mbuf = ne2000_write_mbuf;
129 dsc->read_hdr = ne2000_read_hdr;
130
131 /* Registers are linear. */
132 for (i = 0; i < 16; i++)
133 dsc->sc_reg_map[i] = i;
134
135 /*
136 * 8k of memory plus an additional 8k if an NE2000.
137 */
138 memsize = 8192 + (nsc->sc_type == NE2000_TYPE_NE2000 ? 8192 : 0);
139
140 /*
141 * NIC memory doens't start at zero on an NE board.
142 * The start address is tied to the bus width.
143 * (It happens to be computed the same way as mem size.)
144 */
145 dsc->mem_start = memsize;
146
147 #ifdef GWETHER
148 {
149 int x, mstart = 0;
150 int8_t pbuf0[ED_PAGE_SIZE], pbuf[ED_PAGE_SIZE],
151 tbuf[ED_PAGE_SIZE];
152
153 for (i = 0; i < ED_PAGE_SIZE; i++)
154 pbuf0[i] = 0;
155
156 /* Search for the start of RAM. */
157 for (x = 1; x < 256; x++) {
158 ne2000_writemem(nict, nich, asict, asich, pbuf0,
159 x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword);
160 ne2000_readmem(nict, nich, asict, asich,
161 x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
162 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
163 for (i = 0; i < ED_PAGE_SIZE; i++)
164 pbuf[i] = 255 - x;
165 ne2000_writemem(nict, nich, asict, asich,
166 pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
167 useword);
168 ne2000_readmem(nict, nich, asict, asich,
169 x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE,
170 useword);
171 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0) {
172 mstart = x << ED_PAGE_SHIFT;
173 memsize = ED_PAGE_SIZE;
174 break;
175 }
176 }
177 }
178
179 if (mstart == 0) {
180 printf("%s: cannot find start of RAM\n",
181 dsc->sc_dev.dv_xname);
182 return;
183 }
184
185 /* Search for the end of RAM. */
186 for (++x; x < 256; x++) {
187 ne2000_writemem(nict, nich, asict, asich, pbuf0,
188 x << ED_PAGE_SHIFT, ED_PAGE_SIZE, useword);
189 ne2000_readmem(nict, nich, asict, asich,
190 x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE, useword);
191 if (bcmp(pbuf0, tbuf, ED_PAGE_SIZE) == 0) {
192 for (i = 0; i < ED_PAGE_SIZE; i++)
193 pbuf[i] = 255 - x;
194 ne2000_writemem(nict, nich, asict, asich,
195 pbuf, x << ED_PAGE_SHIFT, ED_PAGE_SIZE,
196 useword);
197 ne2000_readmem(nict, nich, asict, asich,
198 x << ED_PAGE_SHIFT, tbuf, ED_PAGE_SIZE
199 useword);
200 if (bcmp(pbuf, tbuf, ED_PAGE_SIZE) == 0)
201 memsize += ED_PAGE_SIZE;
202 else
203 break;
204 } else
205 break;
206 }
207
208 printf("%s: RAM start 0x%x, size %d\n",
209 dsc->sc_dev.dv_xname, mstart, msize);
210
211 dsc->mem_start = mstart;
212 }
213 #endif /* GWETHER */
214
215 dsc->mem_size = memsize;
216
217 if (myea == NULL) {
218 /* Read the station address. */
219 ne2000_readmem(nict, nich, asict, asich, 0, romdata,
220 sizeof(romdata), useword);
221 for (i = 0; i < ETHER_ADDR_LEN; i++)
222 dsc->sc_enaddr[i] = romdata[i * (useword ? 2 : 1)];
223 } else
224 bcopy(myea, dsc->sc_enaddr, sizeof(dsc->sc_enaddr));
225
226 /* Clear any pending interrupts that might have occurred above. */
227 bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
228
229 if (dp8390_config(dsc, NULL, 0, 0)) {
230 printf("%s: setup failed\n", dsc->sc_dev.dv_xname);
231 return;
232 }
233
234 /*
235 * We need to compute mem_ring a bit differently; override the
236 * value set up in dp8390_config().
237 */
238 dsc->mem_ring =
239 dsc->mem_start + ((dsc->txb_cnt * ED_TXBUF_SIZE) << ED_PAGE_SHIFT);
240 }
241
242 /*
243 * Detect an NE-2000 or compatible. Returns a model code.
244 */
245 int
246 ne2000_detect(nict, nich, asict, asich)
247 bus_space_tag_t nict;
248 bus_space_handle_t nich;
249 bus_space_tag_t asict;
250 bus_space_handle_t asich;
251 {
252 static u_int8_t test_pattern[32] = "THIS is A memory TEST pattern";
253 u_int8_t test_buffer[32], tmp;
254 int i, rv = 0;
255
256 /* Reset the board. */
257 #ifdef GWETHER
258 bus_space_write_1(asict, asich, NE2000_ASIC_RESET, 0);
259 delay(200);
260 #endif /* GWETHER */
261 tmp = bus_space_read_1(asict, asich, NE2000_ASIC_RESET);
262 delay(10000);
263
264 /*
265 * I don't know if this is necessary; probably cruft leftover from
266 * Clarkson packet driver code. Doesn't do a thing on the boards I've
267 * tested. -DG [note that a outb(0x84, 0) seems to work here, and is
268 * non-invasive...but some boards don't seem to reset and I don't have
269 * complete documentation on what the 'right' thing to do is...so we do
270 * the invasive thing for now. Yuck.]
271 */
272 bus_space_write_1(asict, asich, NE2000_ASIC_RESET, tmp);
273 delay(5000);
274
275 /*
276 * This is needed because some NE clones apparently don't reset the
277 * NIC properly (or the NIC chip doesn't reset fully on power-up).
278 * XXX - this makes the probe invasive! Done against my better
279 * judgement. -DLG
280 */
281 bus_space_write_1(nict, nich, ED_P0_CR,
282 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STP);
283
284 delay(5000);
285
286 /*
287 * Generic probe routine for testing for the existance of a DS8390.
288 * Must be performed after the NIC has just been reset. This
289 * works by looking at certain register values that are guaranteed
290 * to be initialized a certain way after power-up or reset.
291 *
292 * Specifically:
293 *
294 * Register reset bits set bits
295 * -------- ---------- --------
296 * CR TXP, STA RD2, STP
297 * ISR RST
298 * IMR <all>
299 * DCR LAS
300 * TCR LB1, LB0
301 *
302 * We only look at CR and ISR, however, since looking at the others
303 * would require changing register pages, which would be intrusive
304 * if this isn't an 8390.
305 */
306
307 tmp = bus_space_read_1(nict, nich, ED_P0_CR);
308 if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
309 (ED_CR_RD2 | ED_CR_STP))
310 goto out;
311
312 tmp = bus_space_read_1(nict, nich, ED_P0_ISR);
313 if ((tmp & ED_ISR_RST) != ED_ISR_RST)
314 goto out;
315
316 bus_space_write_1(nict, nich,
317 ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
318
319 for (i = 0; i < 100; i++) {
320 if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
321 ED_ISR_RST) {
322 /* Ack the reset bit. */
323 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
324 break;
325 }
326 delay(100);
327 }
328
329 #if 0
330 /* XXX */
331 if (i == 100)
332 goto out;
333 #endif
334
335 /*
336 * Test the ability to read and write to the NIC memory. This has
337 * the side effect of determining if this is an NE1000 or an NE2000.
338 */
339
340 /*
341 * This prevents packets from being stored in the NIC memory when
342 * the readmem routine turns on the start bit in the CR.
343 */
344 bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
345
346 /* Temporarily initialize DCR for byte operations. */
347 bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
348
349 bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT);
350 bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT);
351
352 /*
353 * Write a test pattern in byte mode. If this fails, then there
354 * probably isn't any memory at 8k - which likely means that the
355 * board is an NE2000.
356 */
357 ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192,
358 sizeof(test_pattern), 0);
359 ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer,
360 sizeof(test_buffer), 0);
361
362 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
363 /* not an NE1000 - try NE2000 */
364 bus_space_write_1(nict, nich, ED_P0_DCR,
365 ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
366 bus_space_write_1(nict, nich, ED_P0_PSTART,
367 16384 >> ED_PAGE_SHIFT);
368 bus_space_write_1(nict, nich, ED_P0_PSTOP,
369 32768 >> ED_PAGE_SHIFT);
370
371 /*
372 * Write the test pattern in word mode. If this also fails,
373 * then we don't know what this board is.
374 */
375 ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384,
376 sizeof(test_pattern), 1);
377 ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer,
378 sizeof(test_buffer), 1);
379
380 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)))
381 goto out; /* not an NE2000 either */
382
383 rv = NE2000_TYPE_NE2000;
384 } else {
385 /* We're an NE1000. */
386 rv = NE2000_TYPE_NE1000;
387 }
388
389 /* Clear any pending interrupts that might have occurred above. */
390 bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
391
392 out:
393 return (rv);
394 }
395
396 /*
397 * Write an mbuf chain to the destination NIC memory address using programmed
398 * I/O.
399 */
400 int
401 ne2000_write_mbuf(sc, m, buf)
402 struct dp8390_softc *sc;
403 struct mbuf *m;
404 int buf;
405 {
406 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
407 bus_space_tag_t nict = sc->sc_regt;
408 bus_space_handle_t nich = sc->sc_regh;
409 bus_space_tag_t asict = nsc->sc_asict;
410 bus_space_handle_t asich = nsc->sc_asich;
411 int savelen;
412 int maxwait = 100; /* about 120us */
413
414 savelen = m->m_pkthdr.len;
415
416 /* Select page 0 registers. */
417 bus_space_write_1(nict, nich, ED_P0_CR,
418 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
419
420 /* Reset remote DMA complete flag. */
421 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
422
423 /* Set up DMA byte count. */
424 bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen);
425 bus_space_write_1(nict, nich, ED_P0_RBCR1, savelen >> 8);
426
427 /* Set up destination address in NIC mem. */
428 bus_space_write_1(nict, nich, ED_P0_RSAR0, buf);
429 bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8);
430
431 /* Set remote DMA write. */
432 bus_space_write_1(nict, nich,
433 ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
434
435 /*
436 * Transfer the mbuf chain to the NIC memory. NE2000 cards
437 * require that data be transferred as words, and only words,
438 * so that case requires some extra code to patch over odd-length
439 * mbufs.
440 */
441 if (nsc->sc_type == NE2000_TYPE_NE1000) {
442 /* NE1000s are easy. */
443 for (; m != 0; m = m->m_next) {
444 if (m->m_len) {
445 bus_space_write_multi_1(asict, asich,
446 NE2000_ASIC_DATA, mtod(m, u_int8_t *),
447 m->m_len);
448 }
449 }
450 } else {
451 /* NE2000s are a bit trickier. */
452 u_int8_t *data, savebyte[2];
453 int l, wantbyte;
454
455 wantbyte = 0;
456 for (; m != 0; m = m->m_next) {
457 l = m->m_len;
458 if (l == 0)
459 continue;
460 data = mtod(m, u_int8_t *);
461 /* Finish the last word. */
462 if (wantbyte) {
463 savebyte[1] = *data;
464 bus_space_write_2(asict, asich,
465 NE2000_ASIC_DATA, *(u_int16_t *)savebyte);
466 data++;
467 l--;
468 wantbyte = 0;
469 }
470 /* Output contiguous words. */
471 if (l > 1) {
472 bus_space_write_multi_2(asict, asich,
473 NE2000_ASIC_DATA, (u_int16_t *)data,
474 l >> 1);
475 }
476 /* Save last byte, if necessary. */
477 if (l & 1) {
478 data += l & ~1;
479 savebyte[0] = *data;
480 wantbyte = 1;
481 }
482 }
483
484 if (wantbyte) {
485 savebyte[1] = 0;
486 bus_space_write_2(asict, asich, NE2000_ASIC_DATA,
487 *(u_int16_t *)savebyte);
488 }
489 }
490
491 /*
492 * Wait for remote DMA to complete. This is necessary because on the
493 * transmit side, data is handled internally by the NIC in bursts, and
494 * we can't start another remote DMA until this one completes. Not
495 * waiting causes really bad things to happen - like the NIC wedging
496 * the bus.
497 */
498 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
499 ED_ISR_RDC) && --maxwait);
500
501 if (maxwait == 0) {
502 log(LOG_WARNING,
503 "%s: remote transmit DMA failed to complete\n",
504 sc->sc_dev.dv_xname);
505 dp8390_reset(sc);
506 }
507
508 return (savelen);
509 }
510
511 /*
512 * Given a source and destination address, copy 'amout' of a packet from
513 * the ring buffer into a linear destination buffer. Takes into account
514 * ring-wrap.
515 */
516 int
517 ne2000_ring_copy(sc, src, dst, amount)
518 struct dp8390_softc *sc;
519 int src;
520 caddr_t dst;
521 u_short amount;
522 {
523 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
524 bus_space_tag_t nict = sc->sc_regt;
525 bus_space_handle_t nich = sc->sc_regh;
526 bus_space_tag_t asict = nsc->sc_asict;
527 bus_space_handle_t asich = nsc->sc_asich;
528 u_short tmp_amount;
529 int useword = (nsc->sc_type == NE2000_TYPE_NE2000);
530
531 /* Does copy wrap to lower addr in ring buffer? */
532 if (src + amount > sc->mem_end) {
533 tmp_amount = sc->mem_end - src;
534
535 /* Copy amount up to end of NIC memory. */
536 ne2000_readmem(nict, nich, asict, asich, src,
537 (u_int8_t *)dst, tmp_amount, useword);
538
539 amount -= tmp_amount;
540 src = sc->mem_ring;
541 dst += tmp_amount;
542 }
543
544 ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst,
545 amount, useword);
546
547 return (src + amount);
548 }
549
550 void
551 ne2000_read_hdr(sc, buf, hdr)
552 struct dp8390_softc *sc;
553 int buf;
554 struct dp8390_ring *hdr;
555 {
556 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
557
558 ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich,
559 buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring),
560 (nsc->sc_type == NE2000_TYPE_NE2000));
561 #if BYTE_ORDER == BIG_ENDIAN
562 hdr->count = bswap16(hdr->count);
563 #endif
564 }
565
566 int
567 ne2000_test_mem(sc)
568 struct dp8390_softc *sc;
569 {
570
571 /* Noop. */
572 return (0);
573 }
574
575 /*
576 * Given a NIC memory source address and a host memory destination address,
577 * copy 'amount' from NIC to host using programmed i/o. The 'amount' is
578 * rounded up to a word - ok as long as mbufs are word sized.
579 */
580 void
581 ne2000_readmem(nict, nich, asict, asich, src, dst, amount, useword)
582 bus_space_tag_t nict;
583 bus_space_handle_t nich;
584 bus_space_tag_t asict;
585 bus_space_handle_t asich;
586 int src;
587 u_int8_t *dst;
588 size_t amount;
589 int useword;
590 {
591
592 /* Select page 0 registers. */
593 bus_space_write_1(nict, nich, ED_P0_CR,
594 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
595
596 /* Round up to a word. */
597 if (amount & 1)
598 ++amount;
599
600 /* Set up DMA byte count. */
601 bus_space_write_1(nict, nich, ED_P0_RBCR0, amount);
602 bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8);
603
604 /* Set up source address in NIC mem. */
605 bus_space_write_1(nict, nich, ED_P0_RSAR0, src);
606 bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8);
607
608 bus_space_write_1(nict, nich, ED_P0_CR,
609 ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA);
610
611 if (useword)
612 bus_space_read_multi_2(asict, asich, NE2000_ASIC_DATA,
613 (u_int16_t *)dst, amount >> 1);
614 else
615 bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA,
616 dst, amount);
617 }
618
619 /*
620 * Stripped down routine for writing a linear buffer to NIC memory. Only
621 * used in the probe routine to test the memory. 'len' must be even.
622 */
623 void
624 ne2000_writemem(nict, nich, asict, asich, src, dst, len, useword)
625 bus_space_tag_t nict;
626 bus_space_handle_t nich;
627 bus_space_tag_t asict;
628 bus_space_handle_t asich;
629 u_int8_t *src;
630 int dst;
631 size_t len;
632 int useword;
633 {
634 int maxwait = 100; /* about 120us */
635
636 /* Select page 0 registers. */
637 bus_space_write_1(nict, nich, ED_P0_CR,
638 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
639
640 /* Reset remote DMA complete flag. */
641 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
642
643 /* Set up DMA byte count. */
644 bus_space_write_1(nict, nich, ED_P0_RBCR0, len);
645 bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8);
646
647 /* Set up destination address in NIC mem. */
648 bus_space_write_1(nict, nich, ED_P0_RSAR0, dst);
649 bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8);
650
651 /* Set remote DMA write. */
652 bus_space_write_1(nict, nich, ED_P0_CR,
653 ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
654
655 if (useword)
656 bus_space_write_multi_2(asict, asich, NE2000_ASIC_DATA,
657 (u_int16_t *)src, len >> 1);
658 else
659 bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA,
660 src, len);
661
662 /*
663 * Wait for remote DMA to complete. This is necessary because on the
664 * transmit side, data is handled internally by the NIC in bursts, and
665 * we can't start another remote DMA until this one completes. Not
666 * waiting causes really bad things to happen - like the NIC wedging
667 * the bus.
668 */
669 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
670 ED_ISR_RDC) && --maxwait);
671
672 if (maxwait == 0)
673 printf("ne2000_writemem: failed to complete\n");
674 }
675