1 /* $NetBSD: ne2000.c,v 1.3 1997/10/15 01:15:51 enami 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 bus_space_write_1(nict, nich, ED_P0_CR, 396 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 397 398 /* Reset remote DMA complete flag. */ 399 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC); 400 401 /* Set up DMA byte count. */ 402 bus_space_write_1(nict, nich, ED_P0_RBCR0, savelen); 403 bus_space_write_1(nict, nich, ED_P0_RBCR1, savelen >> 8); 404 405 /* Set up destination address in NIC mem. */ 406 bus_space_write_1(nict, nich, ED_P0_RSAR0, buf); 407 bus_space_write_1(nict, nich, ED_P0_RSAR1, buf >> 8); 408 409 /* Set remote DMA write. */ 410 bus_space_write_1(nict, nich, 411 ED_P0_CR, ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA); 412 413 /* 414 * Transfer the mbuf chain to the NIC memory. NE2000 cards 415 * require that data be transferred as words, and only words, 416 * so that case requires some extra code to patch over odd-length 417 * mbufs. 418 */ 419 if (nsc->sc_type == NE2000_TYPE_NE1000) { 420 /* NE1000s are easy. */ 421 for (; m != 0; m = m->m_next) { 422 if (m->m_len) { 423 bus_space_write_multi_1(asict, asich, 424 NE2000_ASIC_DATA, mtod(m, u_int8_t *), 425 m->m_len); 426 } 427 } 428 } else { 429 /* NE2000s are a bit trickier. */ 430 u_int8_t *data, savebyte[2]; 431 int l, wantbyte; 432 433 wantbyte = 0; 434 for (; m != 0; m = m->m_next) { 435 l = m->m_len; 436 if (l == 0) 437 continue; 438 data = mtod(m, u_int8_t *); 439 /* Finish the last word. */ 440 if (wantbyte) { 441 savebyte[1] = *data; 442 bus_space_write_2(asict, asich, 443 NE2000_ASIC_DATA, *(u_int16_t *)savebyte); 444 data++; 445 l--; 446 wantbyte = 0; 447 } 448 /* Output contiguous words. */ 449 if (l > 1) { 450 bus_space_write_multi_2(asict, asich, 451 NE2000_ASIC_DATA, (u_int16_t *)data, 452 l >> 1); 453 } 454 /* Save last byte, if necessary. */ 455 if (l & 1) { 456 data += l & ~1; 457 savebyte[0] = *data; 458 wantbyte = 1; 459 } 460 } 461 462 if (wantbyte) { 463 savebyte[1] = 0; 464 bus_space_write_2(asict, asich, NE2000_ASIC_DATA, 465 *(u_int16_t *)savebyte); 466 } 467 } 468 469 /* 470 * Wait for remote DMA to complete. This is necessary because on the 471 * transmit side, data is handled internally by the NIC in bursts, and 472 * we can't start another remote DMA until this one completes. Not 473 * waiting causes really bad things to happen - like the NIC wedging 474 * the bus. 475 */ 476 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) != 477 ED_ISR_RDC) && --maxwait); 478 479 if (maxwait == 0) { 480 log(LOG_WARNING, 481 "%s: remote transmit DMA failed to complete\n", 482 sc->sc_dev.dv_xname); 483 dp8390_reset(sc); 484 } 485 486 return (savelen); 487 } 488 489 /* 490 * Given a source and destination address, copy 'amout' of a packet from 491 * the ring buffer into a linear destination buffer. Takes into account 492 * ring-wrap. 493 */ 494 int 495 ne2000_ring_copy(sc, src, dst, amount) 496 struct dp8390_softc *sc; 497 int src; 498 caddr_t dst; 499 u_short amount; 500 { 501 struct ne2000_softc *nsc = (struct ne2000_softc *)sc; 502 bus_space_tag_t nict = sc->sc_regt; 503 bus_space_handle_t nich = sc->sc_regh; 504 bus_space_tag_t asict = nsc->sc_asict; 505 bus_space_handle_t asich = nsc->sc_asich; 506 u_short tmp_amount; 507 int useword = (nsc->sc_type == NE2000_TYPE_NE2000); 508 509 /* Does copy wrap to lower addr in ring buffer? */ 510 if (src + amount > sc->mem_end) { 511 tmp_amount = sc->mem_end - src; 512 513 /* Copy amount up to end of NIC memory. */ 514 ne2000_readmem(nict, nich, asict, asich, src, 515 (u_int8_t *)dst, tmp_amount, useword); 516 517 amount -= tmp_amount; 518 src = sc->mem_ring; 519 dst += tmp_amount; 520 } 521 522 ne2000_readmem(nict, nich, asict, asich, src, (u_int8_t *)dst, 523 amount, useword); 524 525 return (src + amount); 526 } 527 528 void 529 ne2000_read_hdr(sc, buf, hdr) 530 struct dp8390_softc *sc; 531 int buf; 532 struct dp8390_ring *hdr; 533 { 534 struct ne2000_softc *nsc = (struct ne2000_softc *)sc; 535 536 ne2000_readmem(sc->sc_regt, sc->sc_regh, nsc->sc_asict, nsc->sc_asich, 537 buf, (u_int8_t *)hdr, sizeof(struct dp8390_ring), 538 (nsc->sc_type == NE2000_TYPE_NE2000)); 539 } 540 541 int 542 ne2000_test_mem(sc) 543 struct dp8390_softc *sc; 544 { 545 546 /* Noop. */ 547 return (0); 548 } 549 550 /* 551 * Given a NIC memory source address and a host memory destination address, 552 * copy 'amount' from NIC to host using programmed i/o. The 'amount' is 553 * rounded up to a word - ok as long as mbufs are word sized. 554 */ 555 void 556 ne2000_readmem(nict, nich, asict, asich, src, dst, amount, useword) 557 bus_space_tag_t nict; 558 bus_space_handle_t nich; 559 bus_space_tag_t asict; 560 bus_space_handle_t asich; 561 int src; 562 u_int8_t *dst; 563 size_t amount; 564 int useword; 565 { 566 567 /* Select page 0 registers. */ 568 bus_space_write_1(nict, nich, ED_P0_CR, 569 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 570 571 /* Round up to a word. */ 572 if (amount & 1) 573 ++amount; 574 575 /* Set up DMA byte count. */ 576 bus_space_write_1(nict, nich, ED_P0_RBCR0, amount); 577 bus_space_write_1(nict, nich, ED_P0_RBCR1, amount >> 8); 578 579 /* Set up source address in NIC mem. */ 580 bus_space_write_1(nict, nich, ED_P0_RSAR0, src); 581 bus_space_write_1(nict, nich, ED_P0_RSAR1, src >> 8); 582 583 bus_space_write_1(nict, nich, ED_P0_CR, 584 ED_CR_RD0 | ED_CR_PAGE_0 | ED_CR_STA); 585 586 if (useword) 587 bus_space_read_multi_2(asict, asich, NE2000_ASIC_DATA, 588 (u_int16_t *)dst, amount >> 1); 589 else 590 bus_space_read_multi_1(asict, asich, NE2000_ASIC_DATA, 591 dst, amount); 592 } 593 594 /* 595 * Stripped down routine for writing a linear buffer to NIC memory. Only 596 * used in the probe routine to test the memory. 'len' must be even. 597 */ 598 void 599 ne2000_writemem(nict, nich, asict, asich, src, dst, len, useword) 600 bus_space_tag_t nict; 601 bus_space_handle_t nich; 602 bus_space_tag_t asict; 603 bus_space_handle_t asich; 604 u_int8_t *src; 605 int dst; 606 size_t len; 607 int useword; 608 { 609 int maxwait = 100; /* about 120us */ 610 611 /* Select page 0 registers. */ 612 bus_space_write_1(nict, nich, ED_P0_CR, 613 ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA); 614 615 /* Reset remote DMA complete flag. */ 616 bus_space_write_1(nict, nich, ED_P0_ISR, ED_ISR_RDC); 617 618 /* Set up DMA byte count. */ 619 bus_space_write_1(nict, nich, ED_P0_RBCR0, len); 620 bus_space_write_1(nict, nich, ED_P0_RBCR1, len >> 8); 621 622 /* Set up destination address in NIC mem. */ 623 bus_space_write_1(nict, nich, ED_P0_RSAR0, dst); 624 bus_space_write_1(nict, nich, ED_P0_RSAR1, dst >> 8); 625 626 /* Set remote DMA write. */ 627 bus_space_write_1(nict, nich, ED_P0_CR, 628 ED_CR_RD1 | ED_CR_PAGE_0 | ED_CR_STA); 629 630 if (useword) 631 bus_space_write_multi_2(asict, asich, NE2000_ASIC_DATA, 632 (u_int16_t *)src, len >> 1); 633 else 634 bus_space_write_multi_1(asict, asich, NE2000_ASIC_DATA, 635 src, len); 636 637 /* 638 * Wait for remote DMA to complete. This is necessary because on the 639 * transmit side, data is handled internally by the NIC in bursts, and 640 * we can't start another remote DMA until this one completes. Not 641 * waiting causes really bad things to happen - like the NIC wedging 642 * the bus. 643 */ 644 while (((bus_space_read_1(nict, nich, ED_P0_ISR) & ED_ISR_RDC) != 645 ED_ISR_RDC) && --maxwait); 646 647 if (maxwait == 0) 648 printf("ne2000_writemem: failed to complete\n"); 649 } 650