ne2000.c revision 1.4 1 /* $NetBSD: ne2000.c,v 1.4 1997/10/29 07:57:53 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 /*
290 * Generic probe routine for testing for the existance of a DS8390.
291 * Must be performed after the NIC has just been reset. This
292 * works by looking at certain register values that are guaranteed
293 * to be initialized a certain way after power-up or reset.
294 *
295 * Specifically:
296 *
297 * Register reset bits set bits
298 * -------- ---------- --------
299 * CR TXP, STA RD2, STP
300 * ISR RST
301 * IMR <all>
302 * DCR LAS
303 * TCR LB1, LB0
304 *
305 * We only look at CR and ISR, however, since looking at the others
306 * would require changing register pages, which would be intrusive
307 * if this isn't an 8390.
308 */
309
310 tmp = bus_space_read_1(nict, nich, ED_P0_CR);
311 if ((tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
312 (ED_CR_RD2 | ED_CR_STP))
313 goto out;
314
315 tmp = bus_space_read_1(nict, nich, ED_P0_ISR);
316 if ((tmp & ED_ISR_RST) != ED_ISR_RST)
317 goto out;
318
319 bus_space_write_1(nict, nich,
320 ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
321
322 for (i = 0; i < 100; i++) {
323 if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
324 ED_ISR_RST) {
325 /* Ack the reset bit. */
326 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
327 break;
328 }
329 delay(100);
330 }
331
332 #if 0
333 /* XXX */
334 if (i == 100)
335 goto out;
336 #endif
337
338 /*
339 * Test the ability to read and write to the NIC memory. This has
340 * the side effect of determining if this is an NE1000 or an NE2000.
341 */
342
343 /*
344 * This prevents packets from being stored in the NIC memory when
345 * the readmem routine turns on the start bit in the CR.
346 */
347 bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
348
349 /* Temporarily initialize DCR for byte operations. */
350 bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
351
352 bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT);
353 bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT);
354
355 /*
356 * Write a test pattern in byte mode. If this fails, then there
357 * probably isn't any memory at 8k - which likely means that the
358 * board is an NE2000.
359 */
360 ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192,
361 sizeof(test_pattern), 0);
362 ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer,
363 sizeof(test_buffer), 0);
364
365 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
366 /* not an NE1000 - try NE2000 */
367 bus_space_write_1(nict, nich, ED_P0_DCR,
368 ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
369 bus_space_write_1(nict, nich, ED_P0_PSTART,
370 16384 >> ED_PAGE_SHIFT);
371 bus_space_write_1(nict, nich, ED_P0_PSTOP,
372 32768 >> ED_PAGE_SHIFT);
373
374 /*
375 * Write the test pattern in word mode. If this also fails,
376 * then we don't know what this board is.
377 */
378 ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384,
379 sizeof(test_pattern), 1);
380 ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer,
381 sizeof(test_buffer), 1);
382
383 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)))
384 goto out; /* not an NE2000 either */
385
386 rv = NE2000_TYPE_NE2000;
387 } else {
388 /* We're an NE1000. */
389 rv = NE2000_TYPE_NE1000;
390 }
391
392 /* Clear any pending interrupts that might have occurred above. */
393 bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
394
395 out:
396 return (rv);
397 }
398
399 /*
400 * Write an mbuf chain to the destination NIC memory address using programmed
401 * I/O.
402 */
403 int
404 ne2000_write_mbuf(sc, m, buf)
405 struct dp8390_softc *sc;
406 struct mbuf *m;
407 int buf;
408 {
409 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
410 bus_space_tag_t nict = sc->sc_regt;
411 bus_space_handle_t nich = sc->sc_regh;
412 bus_space_tag_t asict = nsc->sc_asict;
413 bus_space_handle_t asich = nsc->sc_asich;
414 int savelen;
415 int maxwait = 100; /* about 120us */
416
417 savelen = m->m_pkthdr.len;
418
419 /* Select page 0 registers. */
420 bus_space_write_1(nict, nich, ED_P0_CR,
421 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
422
423 /* Reset remote DMA complete flag. */
424 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
425
426 /* Set up DMA byte count. */
427 bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen);
428 bus_space_write_1(nict, nich, ED_P0_RBCR1, savelen >> 8);
429
430 /* Set up destination address in NIC mem. */
431 bus_space_write_1(nict, nich, ED_P0_RSAR0, buf);
432 bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8);
433
434 /* Set remote DMA write. */
435 bus_space_write_1(nict, nich,
436 ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
437
438 /*
439 * Transfer the mbuf chain to the NIC memory. NE2000 cards
440 * require that data be transferred as words, and only words,
441 * so that case requires some extra code to patch over odd-length
442 * mbufs.
443 */
444 if (nsc->sc_type == NE2000_TYPE_NE1000) {
445 /* NE1000s are easy. */
446 for (; m != 0; m = m->m_next) {
447 if (m->m_len) {
448 bus_space_write_multi_1(asict, asich,
449 NE2000_ASIC_DATA, mtod(m, u_int8_t *),
450 m->m_len);
451 }
452 }
453 } else {
454 /* NE2000s are a bit trickier. */
455 u_int8_t *data, savebyte[2];
456 int l, wantbyte;
457
458 wantbyte = 0;
459 for (; m != 0; m = m->m_next) {
460 l = m->m_len;
461 if (l == 0)
462 continue;
463 data = mtod(m, u_int8_t *);
464 /* Finish the last word. */
465 if (wantbyte) {
466 savebyte[1] = *data;
467 bus_space_write_2(asict, asich,
468 NE2000_ASIC_DATA, *(u_int16_t *)savebyte);
469 data++;
470 l--;
471 wantbyte = 0;
472 }
473 /* Output contiguous words. */
474 if (l > 1) {
475 bus_space_write_multi_2(asict, asich,
476 NE2000_ASIC_DATA, (u_int16_t *)data,
477 l >> 1);
478 }
479 /* Save last byte, if necessary. */
480 if (l & 1) {
481 data += l & ~1;
482 savebyte[0] = *data;
483 wantbyte = 1;
484 }
485 }
486
487 if (wantbyte) {
488 savebyte[1] = 0;
489 bus_space_write_2(asict, asich, NE2000_ASIC_DATA,
490 *(u_int16_t *)savebyte);
491 }
492 }
493
494 /*
495 * Wait for remote DMA to complete. This is necessary because on the
496 * transmit side, data is handled internally by the NIC in bursts, and
497 * we can't start another remote DMA until this one completes. Not
498 * waiting causes really bad things to happen - like the NIC wedging
499 * the bus.
500 */
501 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
502 ED_ISR_RDC) && --maxwait);
503
504 if (maxwait == 0) {
505 log(LOG_WARNING,
506 "%s: remote transmit DMA failed to complete\n",
507 sc->sc_dev.dv_xname);
508 dp8390_reset(sc);
509 }
510
511 return (savelen);
512 }
513
514 /*
515 * Given a source and destination address, copy 'amout' of a packet from
516 * the ring buffer into a linear destination buffer. Takes into account
517 * ring-wrap.
518 */
519 int
520 ne2000_ring_copy(sc, src, dst, amount)
521 struct dp8390_softc *sc;
522 int src;
523 caddr_t dst;
524 u_short amount;
525 {
526 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
527 bus_space_tag_t nict = sc->sc_regt;
528 bus_space_handle_t nich = sc->sc_regh;
529 bus_space_tag_t asict = nsc->sc_asict;
530 bus_space_handle_t asich = nsc->sc_asich;
531 u_short tmp_amount;
532 int useword = (nsc->sc_type == NE2000_TYPE_NE2000);
533
534 /* Does copy wrap to lower addr in ring buffer? */
535 if (src + amount > sc->mem_end) {
536 tmp_amount = sc->mem_end - src;
537
538 /* Copy amount up to end of NIC memory. */
539 ne2000_readmem(nict, nich, asict, asich, src,
540 (u_int8_t *)dst, tmp_amount, useword);
541
542 amount -= tmp_amount;
543 src = sc->mem_ring;
544 dst += tmp_amount;
545 }
546
547 ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst,
548 amount, useword);
549
550 return (src + amount);
551 }
552
553 void
554 ne2000_read_hdr(sc, buf, hdr)
555 struct dp8390_softc *sc;
556 int buf;
557 struct dp8390_ring *hdr;
558 {
559 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
560
561 ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich,
562 buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring),
563 (nsc->sc_type == NE2000_TYPE_NE2000));
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