ne2000.c revision 1.1.2.1 1 /* $NetBSD: ne2000.c,v 1.1.2.1 1997/10/14 01:01: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 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 printf("ne2000_detect: 0x%x (0x%x) != 0x%x\n",
293 (tmp & (ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)), tmp,
294 (ED_CR_RD2 | ED_CR_STP));
295 goto out;
296 }
297
298 bus_space_write_1(nict, nich,
299 ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
300
301 for (i = 0; i < 100; i++) {
302 if ((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RST) ==
303 ED_ISR_RST) {
304 /* Ack the reset bit. */
305 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RST);
306 break;
307 }
308 delay(100);
309 }
310
311 #if 0
312 /* XXX */
313 if (i == 100)
314 goto out;
315 #endif
316
317 /*
318 * Test the ability to read and write to the NIC memory. This has
319 * the side effect of determining if this is an NE1000 or an NE2000.
320 */
321
322 /*
323 * This prevents packets from being stored in the NIC memory when
324 * the readmem routine turns on the start bit in the CR.
325 */
326 bus_space_write_1(nict, nich, ED_P0_RCR, ED_RCR_MON);
327
328 /* Temporarily initialize DCR for byte operations. */
329 bus_space_write_1(nict, nich, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
330
331 bus_space_write_1(nict, nich, ED_P0_PSTART, 8192 >> ED_PAGE_SHIFT);
332 bus_space_write_1(nict, nich, ED_P0_PSTOP, 16384 >> ED_PAGE_SHIFT);
333
334 /*
335 * Write a test pattern in byte mode. If this fails, then there
336 * probably isn't any memory at 8k - which likely means that the
337 * board is an NE2000.
338 */
339 ne2000_writemem(nict, nich, asict, asich, test_pattern, 8192,
340 sizeof(test_pattern), 0);
341 ne2000_readmem(nict, nich, asict, asich, 8192, test_buffer,
342 sizeof(test_buffer), 0);
343
344 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern))) {
345 /* not an NE1000 - try NE2000 */
346 bus_space_write_1(nict, nich, ED_P0_DCR,
347 ED_DCR_WTS | ED_DCR_FT1 | ED_DCR_LS);
348 bus_space_write_1(nict, nich, ED_P0_PSTART,
349 16384 >> ED_PAGE_SHIFT);
350 bus_space_write_1(nict, nich, ED_P0_PSTOP,
351 32768 >> ED_PAGE_SHIFT);
352
353 /*
354 * Write the test pattern in word mode. If this also fails,
355 * then we don't know what this board is.
356 */
357 ne2000_writemem(nict, nich, asict, asich, test_pattern, 16384,
358 sizeof(test_pattern), 1);
359 ne2000_readmem(nict, nich, asict, asich, 16384, test_buffer,
360 sizeof(test_buffer), 1);
361
362 if (bcmp(test_pattern, test_buffer, sizeof(test_pattern)))
363 goto out; /* not an NE2000 either */
364
365 rv = NE2000_TYPE_NE2000;
366 } else {
367 /* We're an NE1000. */
368 rv = NE2000_TYPE_NE1000;
369 }
370
371 /* Clear any pending interrupts that might have occurred above. */
372 bus_space_write_1(nict, nich, ED_P0_ISR, 0xff);
373
374 out:
375 return (rv);
376 }
377
378 /*
379 * Write an mbuf chain to the destination NIC memory address using programmed
380 * I/O.
381 */
382 int
383 ne2000_write_mbuf(sc, m, buf)
384 struct dp8390_softc *sc;
385 struct mbuf *m;
386 int buf;
387 {
388 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
389 bus_space_tag_t nict = sc->sc_regt;
390 bus_space_handle_t nich = sc->sc_regh;
391 bus_space_tag_t asict = nsc->sc_asict;
392 bus_space_handle_t asich = nsc->sc_asich;
393 int savelen;
394 int maxwait = 100; /* about 120us */
395
396 savelen = m->m_pkthdr.len;
397
398 /* Select page 0 registers. */
399 NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
400
401 /* Reset remote DMA complete flag. */
402 NIC_PUT(nict, nich, ED_P0_ISR, ED_ISR_RDC);
403
404 /* Set up DMA byte count. */
405 NIC_PUT(nict, nich, ED_P0_RBCR0, savelen);
406 NIC_PUT(nict, nich, ED_P0_RBCR1, savelen >> 8);
407
408 /* Set up destination address in NIC mem. */
409 NIC_PUT(nict, nich, ED_P0_RSAR0, buf);
410 NIC_PUT(nict, nich, ED_P0_RSAR1, buf >> 8);
411
412 /* Set remote DMA write. */
413 NIC_PUT(nict, nich, ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
414
415 /*
416 * Transfer the mbuf chain to the NIC memory. NE2000 cards
417 * require that data be transferred as words, and only words,
418 * so that case requires some extra code to patch over odd-length
419 * mbufs.
420 */
421 if (nsc->sc_type == NE2000_TYPE_NE1000) {
422 /* NE1000s are easy. */
423 for (; m != 0; m = m->m_next) {
424 if (m->m_len) {
425 bus_space_write_multi_1(asict, asich,
426 NE2000_ASIC_DATA, mtod(m, u_int8_t *),
427 m->m_len);
428 }
429 }
430 } else {
431 /* NE2000s are a bit trickier. */
432 u_int8_t *data, savebyte[2];
433 int l, wantbyte;
434
435 wantbyte = 0;
436 for (; m != 0; m = m->m_next) {
437 l = m->m_len;
438 if (l == 0)
439 continue;
440 data = mtod(m, u_int8_t *);
441 /* Finish the last word. */
442 if (wantbyte) {
443 savebyte[1] = *data;
444 bus_space_write_2(asict, asich,
445 NE2000_ASIC_DATA, *(u_int16_t *)savebyte);
446 data++;
447 l--;
448 wantbyte = 0;
449 }
450 /* Output contiguous words. */
451 if (l > 1) {
452 bus_space_write_multi_2(asict, asich,
453 NE2000_ASIC_DATA, (u_int16_t *)data,
454 l >> 1);
455 }
456 /* Save last byte, if necessary. */
457 if (l & 1) {
458 data += l & ~1;
459 savebyte[0] = *data;
460 wantbyte = 1;
461 }
462 }
463
464 if (wantbyte) {
465 savebyte[1] = 0;
466 bus_space_write_2(asict, asich, NE2000_ASIC_DATA,
467 *(u_int16_t *)savebyte);
468 }
469 }
470
471 /*
472 * Wait for remote DMA to complete. This is necessary because on the
473 * transmit side, data is handled internally by the NIC in bursts, and
474 * we can't start another remote DMA until this one completes. Not
475 * waiting causes really bad things to happen - like the NIC wedging
476 * the bus.
477 */
478 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
479 ED_ISR_RDC) && --maxwait);
480
481 if (maxwait == 0) {
482 log(LOG_WARNING,
483 "%s: remote transmit DMA failed to complete\n",
484 sc->sc_dev.dv_xname);
485 dp8390_reset(sc);
486 }
487
488 return (savelen);
489 }
490
491 /*
492 * Given a source and destination address, copy 'amout' of a packet from
493 * the ring buffer into a linear destination buffer. Takes into account
494 * ring-wrap.
495 */
496 int
497 ne2000_ring_copy(sc, src, dst, amount)
498 struct dp8390_softc *sc;
499 int src;
500 caddr_t dst;
501 u_short amount;
502 {
503 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
504 bus_space_tag_t nict = sc->sc_regt;
505 bus_space_handle_t nich = sc->sc_regh;
506 bus_space_tag_t asict = nsc->sc_asict;
507 bus_space_handle_t asich = nsc->sc_asich;
508 u_short tmp_amount;
509 int useword = (nsc->sc_type == NE2000_TYPE_NE2000);
510
511 /* Does copy wrap to lower addr in ring buffer? */
512 if (src + amount > sc->mem_end) {
513 tmp_amount = sc->mem_end - src;
514
515 /* Copy amount up to end of NIC memory. */
516 ne2000_readmem(nict, nich, asict, asich, src,
517 (u_int8_t *)dst, tmp_amount, useword);
518
519 amount -= tmp_amount;
520 src = sc->mem_ring;
521 dst += tmp_amount;
522 }
523
524 ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst,
525 amount, useword);
526
527 return (src + amount);
528 }
529
530 void
531 ne2000_read_hdr(sc, buf, hdr)
532 struct dp8390_softc *sc;
533 int buf;
534 struct dp8390_ring *hdr;
535 {
536 struct ne2000_softc *nsc = (struct ne2000_softc *)sc;
537
538 ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich,
539 buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring),
540 (nsc->sc_type == NE2000_TYPE_NE2000));
541 }
542
543 int
544 ne2000_test_mem(sc)
545 struct dp8390_softc *sc;
546 {
547
548 /* Noop. */
549 return (0);
550 }
551
552 /*
553 * Given a NIC memory source address and a host memory destination address,
554 * copy 'amount' from NIC to host using programmed i/o. The 'amount' is
555 * rounded up to a word - ok as long as mbufs are word sized.
556 */
557 void
558 ne2000_readmem(nict, nich, asict, asich, src, dst, amount, useword)
559 bus_space_tag_t nict;
560 bus_space_handle_t nich;
561 bus_space_tag_t asict;
562 bus_space_handle_t asich;
563 int src;
564 u_int8_t *dst;
565 size_t amount;
566 int useword;
567 {
568
569 /* Select page 0 registers. */
570 bus_space_write_1(nict, nich, ED_P0_CR,
571 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
572
573 /* Round up to a word. */
574 if (amount & 1)
575 ++amount;
576
577 /* Set up DMA byte count. */
578 bus_space_write_1(nict, nich, ED_P0_RBCR0, amount);
579 bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8);
580
581 /* Set up source address in NIC mem. */
582 bus_space_write_1(nict, nich, ED_P0_RSAR0, src);
583 bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8);
584
585 bus_space_write_1(nict, nich, ED_P0_CR,
586 ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA);
587
588 if (useword)
589 bus_space_read_multi_2(asict, asich, NE2000_ASIC_DATA,
590 (u_int16_t *)dst, amount >> 1);
591 else
592 bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA,
593 dst, amount);
594 }
595
596 /*
597 * Stripped down routine for writing a linear buffer to NIC memory. Only
598 * used in the probe routine to test the memory. 'len' must be even.
599 */
600 void
601 ne2000_writemem(nict, nich, asict, asich, src, dst, len, useword)
602 bus_space_tag_t nict;
603 bus_space_handle_t nich;
604 bus_space_tag_t asict;
605 bus_space_handle_t asich;
606 u_int8_t *src;
607 int dst;
608 size_t len;
609 int useword;
610 {
611 int maxwait = 100; /* about 120us */
612
613 /* Select page 0 registers. */
614 bus_space_write_1(nict, nich, ED_P0_CR,
615 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
616
617 /* Reset remote DMA complete flag. */
618 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC);
619
620 /* Set up DMA byte count. */
621 bus_space_write_1(nict, nich, ED_P0_RBCR0, len);
622 bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8);
623
624 /* Set up destination address in NIC mem. */
625 bus_space_write_1(nict, nich, ED_P0_RSAR0, dst);
626 bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8);
627
628 /* Set remote DMA write. */
629 bus_space_write_1(nict, nich, ED_P0_CR,
630 ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA);
631
632 if (useword)
633 bus_space_write_multi_2(asict, asich, NE2000_ASIC_DATA,
634 (u_int16_t *)src, len >> 1);
635 else
636 bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA,
637 src, len);
638
639 /*
640 * Wait for remote DMA to complete. This is necessary because on the
641 * transmit side, data is handled internally by the NIC in bursts, and
642 * we can't start another remote DMA until this one completes. Not
643 * waiting causes really bad things to happen - like the NIC wedging
644 * the bus.
645 */
646 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) !=
647 ED_ISR_RDC) && --maxwait);
648
649 if (maxwait == 0)
650 printf("ne2000_writemem: failed to complete\n");
651 }
652