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