if_de.c revision 3278
1/*- 2 * Copyright (c) 1994 Matt Thomas (thomas@lkg.dec.com) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. The name of the author may not be used to endorse or promote products 11 * derived from this software withough specific prior written permission 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * $Id: if_de.c,v 1.5 1994/10/01 16:10:24 thomas Exp $ 25 * 26 * $Log: if_de.c,v $ 27 * Revision 1.5 1994/10/01 16:10:24 thomas 28 * Modifications for FreeBSD 2.0 29 * 30 * Revision 1.4 1994/09/09 21:10:05 thomas 31 * mbuf debugging code 32 * transmit fifo owkraroudns 33 * 34 * Revision 1.3 1994/08/16 20:40:56 thomas 35 * New README files (one per driver) 36 * Minor updates to drivers (DEPCA support and add pass to attach 37 * output) 38 * 39 * Revision 1.2 1994/08/15 20:41:22 thomas 40 * Support AUI and TP. Autosense either. 41 * Revamp receive logic to use private kmem_alloc'ed 64K region. 42 * Some cleanup 43 * 44 * Revision 1.1 1994/08/12 21:01:18 thomas 45 * Initial revision 46 * 47 */ 48 49/* 50 * DEC DC21040 PCI Ethernet Controller 51 * 52 * Written by Matt Thomas 53 * BPF support code stolen directly from if_ec.c 54 * 55 * This driver supports the DEC DE435 or any other PCI 56 * board which support DC21040. 57 */ 58 59#include <de.h> 60#if NDE > 0 61 62#include <param.h> 63#include <systm.h> 64#include <mbuf.h> 65#include <protosw.h> 66#include <socket.h> 67#include <ioctl.h> 68#include <errno.h> 69#include <malloc.h> 70#include <syslog.h> 71 72#include <net/if.h> 73#include <net/if_types.h> 74#include <net/if_dl.h> 75#include <net/route.h> 76 77#include <bpfilter.h> 78#if NBPFILTER > 0 79#include <net/bpf.h> 80#include <net/bpfdesc.h> 81#endif 82 83 84#ifdef INET 85#include <netinet/in.h> 86#include <netinet/in_systm.h> 87#include <netinet/in_var.h> 88#include <netinet/ip.h> 89#include <netinet/if_ether.h> 90#endif 91 92#ifdef NS 93#include <netns/ns.h> 94#include <netns/ns_if.h> 95#endif 96 97#include <vm/vm.h> 98#include <vm/vm_kern.h> 99#include <vm/vm_param.h> 100 101 102#include <pci.h> 103#if NPCI > 0 104#include <i386/pci/pci.h> 105#include <i386/pci/pci_device.h> 106#endif 107#include <i386/isa/icu.h> 108#include <i386/pci/dc21040.h> 109 110/* 111 * This module supports the DEC DC21040 PCI Ethernet Controller. 112 */ 113 114typedef struct { 115 unsigned long addr; 116 unsigned long length; 117} tulip_addrvec_t; 118 119typedef struct { 120 tulip_desc_t *ri_first; 121 tulip_desc_t *ri_last; 122 tulip_desc_t *ri_nextin; 123 tulip_desc_t *ri_nextout; 124 int ri_max; 125 int ri_free; 126} tulip_ringinfo_t; 127 128typedef struct { 129 volatile tulip_uint32_t *csr_busmode; /* CSR0 */ 130 volatile tulip_uint32_t *csr_txpoll; /* CSR1 */ 131 volatile tulip_uint32_t *csr_rxpoll; /* CSR2 */ 132 volatile tulip_uint32_t *csr_rxlist; /* CSR3 */ 133 volatile tulip_uint32_t *csr_txlist; /* CSR4 */ 134 volatile tulip_uint32_t *csr_status; /* CSR5 */ 135 volatile tulip_uint32_t *csr_command; /* CSR6 */ 136 volatile tulip_uint32_t *csr_intr; /* CSR7 */ 137 volatile tulip_uint32_t *csr_missed_frame; /* CSR8 */ 138 volatile tulip_sint32_t *csr_enetrom; /* CSR9 */ 139 volatile tulip_uint32_t *csr_reserved; /* CSR10 */ 140 volatile tulip_uint32_t *csr_full_duplex; /* CSR11 */ 141 volatile tulip_uint32_t *csr_sia_status; /* CSR12 */ 142 volatile tulip_uint32_t *csr_sia_connectivity; /* CSR13 */ 143 volatile tulip_uint32_t *csr_sia_tx_rx; /* CSR14 */ 144 volatile tulip_uint32_t *csr_sia_general; /* CSR15 */ 145} tulip_regfile_t; 146 147/* 148 * The DC21040 has a stupid restriction in that the receive 149 * buffers must be longword aligned. But since Ethernet 150 * headers are not a multiple of longwords in size this forces 151 * the data to non-longword aligned. Since IP requires the 152 * data to be longword aligned, we can to copy it after it has 153 * been DMA'ed in our memory. 154 * 155 * Since we have to copy it anyways, we might as well as allocate 156 * dedicated receive space for the input. This allows to use a 157 * small receive buffer size and more ring entries to be able to 158 * better keep with a foold of tiny Ethernet packets. 159 * 160 * The receive space MUST ALWAYS be a multiple of the page size. 161 * And the number of receive descriptors multiplied by the size 162 * of the receive buffers must equal the recevive space. This 163 * is that we can manipulate the page tables so that even if a 164 * packet wraps around the end of the receive space, we can 165 * treat it as virtually contiguous. 166 */ 167#define TULIP_RXBUFSIZE 512 168#define TULIP_RXDESCS 128 169#define TULIP_RXSPACE (TULIP_RXBUFSIZE * TULIP_RXDESCS) 170#define TULIP_TXDESCS 128 171 172typedef struct { 173 struct arpcom tulip_ac; 174 tulip_regfile_t tulip_csrs; 175 vm_offset_t tulip_rxspace; 176 unsigned tulip_high_intrspins; 177 unsigned tulip_flags; 178#define TULIP_WANTSETUP 0x01 179#define TULIP_WANTHASH 0x02 180#define TULIP_DOINGSETUP 0x04 181#define TULIP_ALTPHYS 0x08 /* use AUI */ 182 unsigned char tulip_rombuf[32]; 183 tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)]; 184 tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)]; 185 tulip_uint32_t tulip_intrmask; 186 tulip_uint32_t tulip_cmdmode; 187 tulip_uint32_t tulip_revinfo; 188#if NBPFILTER > 0 189 caddr_t tulip_bpf; /* BPF context */ 190#endif 191 struct ifqueue tulip_txq; 192 tulip_ringinfo_t tulip_rxinfo; 193 tulip_ringinfo_t tulip_txinfo; 194} tulip_softc_t; 195 196#ifndef IFF_ALTPHYS 197#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */ 198#endif 199tulip_softc_t *tulips[NDE]; 200unsigned tulip_intrs[NDE]; 201 202#define tulip_if tulip_ac.ac_if 203#define tulip_unit tulip_ac.ac_if.if_unit 204#define tulip_name tulip_ac.ac_if.if_name 205#define tulip_hwaddr tulip_ac.ac_enaddr 206 207#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 208#define TULIP_CHECK_RXCRC 0 209#define TULIP_MAX_TXSEG 32 210 211#define TULIP_ADDREQUAL(a1, a2) \ 212 (((u_short *)a1)[0] == ((u_short *)a2)[0] \ 213 || ((u_short *)a1)[1] == ((u_short *)a2)[1] \ 214 || ((u_short *)a1)[2] == ((u_short *)a2)[2]) 215#define TULIP_ADDRBRDCST(a1) \ 216 (((u_short *)a1)[0] == 0xFFFFU \ 217 || ((u_short *)a1)[1] == 0xFFFFU \ 218 || ((u_short *)a1)[2] == 0xFFFFU) 219 220static void tulip_start(struct ifnet *ifp); 221static void tulip_addr_filter(tulip_softc_t *sc); 222 223#if __FreeBSD__ > 1 224#define TULIP_IFRESET_ARGS int unit 225#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit) 226#else 227#define TULIP_IFRESET_ARGS int unit, int uban 228#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit, 0) 229#endif 230 231static void 232tulip_reset( 233 TULIP_IFRESET_ARGS) 234{ 235 tulip_softc_t *sc = tulips[unit]; 236 tulip_ringinfo_t *ri; 237 tulip_desc_t *di; 238 vm_offset_t vmoff; 239 240 *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 241 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 242 33MHz that comes to two microseconds but wait a 243 bit longer anyways) */ 244 245 /* 246 * Use the 247 */ 248 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_RESET; 249 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 250 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 251 printf("%s%d: enabling Thinwire/AUI port\n", 252 sc->tulip_if.if_name, sc->tulip_if.if_unit); 253 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_AUI; 254 sc->tulip_flags |= TULIP_ALTPHYS; 255 } else { 256 if (sc->tulip_flags & TULIP_ALTPHYS) 257 printf("%s%d: enabling 10baseT/UTP port\n", 258 sc->tulip_if.if_name, sc->tulip_if.if_unit); 259 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 260 sc->tulip_flags &= ~TULIP_ALTPHYS; 261 } 262 *sc->tulip_csrs.csr_txlist = vtophys(&sc->tulip_txinfo.ri_first[0]); 263 *sc->tulip_csrs.csr_rxlist = vtophys(&sc->tulip_rxinfo.ri_first[0]); 264 *sc->tulip_csrs.csr_intr = 0; 265 *sc->tulip_csrs.csr_busmode = 0x4800; 266 267 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 268 /* 269 * Free all the mbufs that were on the transmit ring. 270 */ 271 for (;;) { 272 struct mbuf *m; 273 IF_DEQUEUE(&sc->tulip_txq, m); 274 if (m == NULL) 275 break; 276 m_freem(m); 277 } 278 279 ri = &sc->tulip_txinfo; 280 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 281 ri->ri_free = ri->ri_max; 282 for (di = ri->ri_first; di < ri->ri_last; di++) 283 di->d_status = 0; 284 285 /* 286 * We need to collect all the mbufs were on the 287 * receive ring before we reinit it either to put 288 * them back on or to know if we have to allocate 289 * more. 290 */ 291 ri = &sc->tulip_rxinfo; 292 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 293 ri->ri_free = ri->ri_max; 294 for (vmoff = vtophys(sc->tulip_rxspace), di = ri->ri_first; 295 di < ri->ri_last; di++, vmoff += TULIP_RXBUFSIZE) { 296 di->d_status |= TULIP_DSTS_OWNER; 297 di->d_length1 = TULIP_RXBUFSIZE; di->d_addr1 = vmoff; 298 di->d_length2 = 0; di->d_addr2 = 0; 299 } 300 301 sc->tulip_intrmask = TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 302 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 303 |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED; 304 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP); 305 tulip_addr_filter(sc); 306} 307 308static void 309tulip_init( 310 int unit) 311{ 312 tulip_softc_t *sc = tulips[unit]; 313 unsigned new_cmdmode; 314 315 if (sc->tulip_if.if_flags & IFF_UP) { 316 sc->tulip_if.if_flags |= IFF_RUNNING; 317 if (sc->tulip_if.if_flags & IFF_PROMISC) { 318 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 319 } else { 320 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 321 if (sc->tulip_if.if_flags & IFF_ALLMULTI) { 322 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 323 } else { 324 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 325 } 326 } 327 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 328 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 329 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 330 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 331 } else { 332 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 333 tulip_start(&sc->tulip_if); 334 } 335 tulip_cmdnode |= TULIP_CMD_THRSHLD160; 336 *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 337 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 338 } else { 339 TULIP_RESET(sc); 340 sc->tulip_if.if_flags &= ~IFF_RUNNING; 341 } 342} 343 344static struct { 345 unsigned notwhole; 346 unsigned rxerror; 347 unsigned nombufs[2]; 348 unsigned rcvs; 349#if TULIP_CHECK_RXCRC 350 unsigned badcrc; 351#endif 352 unsigned badsop; 353} tulip_rx; 354 355#if TULIP_CHECK_RXCRC 356static unsigned 357tulip_crc32( 358 u_char *addr, 359 int len) 360{ 361 unsigned int crc = 0xFFFFFFFF; 362 static unsigned int crctbl[256]; 363 int idx; 364 static int done; 365 /* 366 * initialize the multicast address CRC table 367 */ 368 for (idx = 0; !done && idx < 256; idx++) { 369 unsigned int tmp = idx; 370 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 371 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 372 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 373 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 374 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 375 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 376 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 377 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 378 crctbl[idx] = tmp; 379 } 380 done = 1; 381 382 while (len-- > 0) 383 crc = (crc >> 8) ^ crctbl[*addr++] ^ crctbl[crc & 0xFF]; 384 385 return crc; 386} 387#endif 388 389static void 390tulip_rx_intr( 391 tulip_softc_t *sc) 392{ 393 tulip_ringinfo_t *ri = &sc->tulip_rxinfo; 394 395 for (;; tulip_rx.rcvs++) { 396 tulip_desc_t *eop; 397 int total_len, ndescs; 398 caddr_t bufaddr = (caddr_t) sc->tulip_rxspace; 399 400 for (ndescs = 1, eop = ri->ri_nextin;; ndescs++) { 401 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 402 return; 403 404 if ((eop->d_status & TULIP_DSTS_RxFIRSTDESC) && eop != ri->ri_nextin) { 405 tulip_rx.badsop++; 406 } 407 if (eop->d_status & TULIP_DSTS_RxLASTDESC) 408 break; 409 if (++eop == ri->ri_last) 410 eop = ri->ri_first; 411 } 412 413 bufaddr += TULIP_RXBUFSIZE * (ri->ri_nextin - ri->ri_first); 414 total_len = ((eop->d_status >> 16) & 0x7FF) - 4; 415 416 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0) { 417 struct ether_header eh; 418 struct mbuf *m; 419 420#if TULIP_CHECK_RXCRC 421 unsigned crc = tulip_crc32(bufaddr, total_len); 422 if (~crc != *((unsigned *) &bufaddr[total_len])) { 423 printf("de0: %d: bad rx crc: %08x [rx] != %08x\n", 424 tulip_rx.rcvs, 425 *((unsigned *) &bufaddr[total_len]), ~crc); 426 goto next; 427 } 428#endif 429 eh = *(struct ether_header *) bufaddr; 430 eh.ether_type = ntohs(eh.ether_type); 431#if NBPFILTER > 0 432 if (sc->tulip_bpf != NULL) { 433 bpf_tap(sc->tulip_bpf, bufaddr, total_len); 434 if (eh.ether_type != ETHERTYPE_IP && eh.ether_type != ETHERTYPE_ARP) 435 goto next; 436 if ((eh.ether_dhost[0] & 1) == 0 && 437 !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr)) 438 goto next; 439 } else if (!TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr) 440 && !TULIP_ADDRBRDCST(eh.ether_dhost)) { 441 goto next; 442 } 443#endif 444 MGETHDR(m, M_DONTWAIT, MT_DATA); 445 if (m != NULL) { 446 total_len -= sizeof(eh); 447 if (total_len > MHLEN) { 448 MCLGET(m, M_DONTWAIT); 449 if ((m->m_flags & M_EXT) == 0) { 450 m_freem(m); 451 tulip_rx.nombufs[1]++; 452 sc->tulip_if.if_ierrors++; 453 goto next; 454 } 455 } 456 bcopy(bufaddr + sizeof(eh), mtod(m, caddr_t), total_len); 457 m->m_len = m->m_pkthdr.len = total_len; 458 ether_input(&sc->tulip_if, &eh, m); 459 } else { 460 tulip_rx.nombufs[0]++; 461 sc->tulip_if.if_ierrors++; 462 } 463 } else { 464 tulip_rx.rxerror++; 465 sc->tulip_if.if_ierrors++; 466 } 467next: 468 sc->tulip_if.if_ipackets++; 469 while (ndescs-- > 0) { 470 ri->ri_nextin->d_status |= TULIP_DSTS_OWNER; 471 if (++ri->ri_nextin == ri->ri_last) 472 ri->ri_nextin = ri->ri_first; 473 } 474 } 475} 476 477static int 478tulip_tx_intr( 479 tulip_softc_t *sc) 480{ 481 tulip_ringinfo_t *ri = &sc->tulip_txinfo; 482 struct mbuf *m; 483 int xmits = 0; 484 485 while (ri->ri_free < ri->ri_max) { 486 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 487 break; 488 489 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) { 490 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) { 491 /* 492 * We've just finished processing a setup packet. 493 * Mark that we can finished it. If there's not 494 * another pending, startup the TULIP receiver. 495 */ 496 sc->tulip_flags &= ~TULIP_DOINGSETUP; 497 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 498 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 499 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 500 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 501 *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 502 } 503 } else { 504 IF_DEQUEUE(&sc->tulip_txq, m); 505 m_freem(m); 506 sc->tulip_if.if_collisions += 507 (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK) 508 >> TULIP_DSTS_V_TxCOLLCNT; 509 if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM) 510 sc->tulip_if.if_oerrors++; 511 xmits++; 512 } 513 } 514 515 if (++ri->ri_nextin == ri->ri_last) 516 ri->ri_nextin = ri->ri_first; 517 ri->ri_free++; 518 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 519 } 520 sc->tulip_if.if_opackets += xmits; 521 return xmits; 522} 523 524static int 525tulip_txsegment( 526 tulip_softc_t *sc, 527 struct mbuf *m, 528 tulip_addrvec_t *avp, 529 size_t maxseg) 530{ 531 int segcnt; 532 533 for (segcnt = 0; m; m = m->m_next) { 534 int len = m->m_len; 535 caddr_t addr = mtod(m, caddr_t); 536 unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); 537 538 while (len > 0) { 539 unsigned slen = min(len, clsize); 540 if (segcnt < maxseg) { 541 avp->addr = vtophys(addr); 542 avp->length = slen; 543 } 544 len -= slen; 545 addr += slen; 546 clsize = CLBYTES; 547 avp++; 548 segcnt++; 549 } 550 } 551 if (segcnt >= maxseg) { 552 printf("%s%d: tulip_txsegment: extremely fragmented packet dropped (%d segments)\n", 553 sc->tulip_name, sc->tulip_unit, segcnt); 554 return -1; 555 } 556 avp->addr = 0; 557 avp->length = 0; 558 return segcnt; 559} 560 561static void 562tulip_start( 563 struct ifnet *ifp) 564{ 565 tulip_softc_t *sc = (tulip_softc_t *) ifp; 566 struct ifqueue *ifq = &ifp->if_snd; 567 tulip_ringinfo_t *ri = &sc->tulip_txinfo; 568 tulip_desc_t *sop, *eop; 569 struct mbuf *m; 570 tulip_addrvec_t addrvec[TULIP_MAX_TXSEG+1], *avp; 571 int segcnt; 572 tulip_uint32_t d_status; 573 574 if ((ifp->if_flags & IFF_RUNNING) == 0) 575 return; 576 577 for (;;) { 578 if (sc->tulip_flags & TULIP_WANTSETUP) { 579 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 580 ifp->if_flags |= IFF_OACTIVE; 581 return; 582 } 583 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 584 sizeof(sc->tulip_setupbuf)); 585 sc->tulip_flags &= ~TULIP_WANTSETUP; 586 sc->tulip_flags |= TULIP_DOINGSETUP; 587 ri->ri_free--; 588 ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 589 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 590 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 591 if (sc->tulip_flags & TULIP_WANTHASH) 592 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 593 ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf); 594 ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf); 595 ri->ri_nextout->d_length2 = 0; 596 ri->ri_nextout->d_addr2 = 0; 597 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 598 *sc->tulip_csrs.csr_txpoll = 1; 599 /* 600 * Advance the ring for the next transmit packet. 601 */ 602 if (++ri->ri_nextout == ri->ri_last) 603 ri->ri_nextout = ri->ri_first; 604 } 605 606 IF_DEQUEUE(ifq, m); 607 if (m == NULL) 608 break; 609 610 /* 611 * First find out how many and which different pages 612 * the mbuf data occupies. Then check to see if we 613 * have enough descriptor space in our transmit ring 614 * to actually send it. 615 */ 616 segcnt = tulip_txsegment(sc, m, addrvec, 617 min(ri->ri_max - 1, TULIP_MAX_TXSEG)); 618 if (segcnt < 0) { 619#if 0 620 struct mbuf *m0; 621 MGETHDR(m0, M_DONTWAIT, MT_DATA); 622 if (m0 != NULL) { 623 if (m->m_pkthdr.len > MHLEN) { 624 MCLGET(m0, M_DONTWAIT); 625 if ((m0->m_flags & M_EXT) == 0) { 626 m_freem(m); 627 continue; 628 } 629 } 630 m_copydata(m, 0, mtod(m0, caddr_t), m->m_pkthdr.len); 631 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 632 m_freem(m); 633 IF_PREPEND(ifq, m0); 634 continue; 635 } else { 636#endif 637 m_freem(m); 638 continue; 639#if 0 640 } 641#endif 642 } 643 if (ri->ri_free - 2 <= (segcnt + 1) / 2) 644 break; 645 646 ri->ri_free -= (segcnt + 1) / 2; 647 /* 648 * Now we fill in our transmit descriptors. This is 649 * a bit reminiscent of going on the Ark two by two 650 * since each descriptor for the TULIP can describe 651 * two buffers. So we advance through the address 652 * vector two entries at a time to to fill each 653 * descriptor. Clear the first and last segment bits 654 * in each descriptor (actually just clear everything 655 * but the end-of-ring or chain bits) to make sure 656 * we don't get messed up by previously sent packets. 657 */ 658 sop = ri->ri_nextout; 659 d_status = 0; 660 avp = addrvec; 661 do { 662 eop = ri->ri_nextout; 663 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 664 eop->d_status = d_status; 665 eop->d_addr1 = avp->addr; eop->d_length1 = avp->length; avp++; 666 eop->d_addr2 = avp->addr; eop->d_length2 = avp->length; avp++; 667 d_status = TULIP_DSTS_OWNER; 668 if (++ri->ri_nextout == ri->ri_last) 669 ri->ri_nextout = ri->ri_first; 670 } while ((segcnt -= 2) > 0); 671 672 /* 673 * The descriptors have been filled in. Mark the first 674 * and last segments, indicate we want a transmit complete 675 * interrupt, give the descriptors to the TULIP, and tell 676 * it to transmit! 677 */ 678 IF_ENQUEUE(&sc->tulip_txq, m); 679 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 680 sop->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 681 sop->d_status = TULIP_DSTS_OWNER; 682 683 *sc->tulip_csrs.csr_txpoll = 1; 684 } 685 if (m != NULL) { 686 ifp->if_flags |= IFF_OACTIVE; 687 IF_PREPEND(ifq, m); 688 } 689} 690 691static int 692tulip_intr( 693 int unit) 694{ 695 tulip_softc_t *sc = tulips[unit]; 696 tulip_uint32_t csr; 697 unsigned spins = 0; 698 699 tulip_intrs[unit]++; 700 701 while ((csr = *sc->tulip_csrs.csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) { 702 *sc->tulip_csrs.csr_status = csr & sc->tulip_intrmask; 703 spins++; 704 705 if (csr & TULIP_STS_SYSERROR) { 706 if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) { 707 TULIP_RESET(sc); 708 tulip_init(sc->tulip_unit); 709 return unit; 710 } 711 } 712 if (csr & TULIP_STS_RXINTR) 713 tulip_rx_intr(sc); 714 if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) { 715 tulip_tx_intr(sc); 716 tulip_start(&sc->tulip_if); 717 } 718 if (csr & TULIP_STS_ABNRMLINTR) { 719 printf("%s%d: abnormal interrupt: 0x%05x [0x%05x]\n", 720 sc->tulip_name, sc->tulip_unit, csr, csr & sc->tulip_intrmask); 721 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 722 } 723 } 724 if (spins > sc->tulip_high_intrspins) 725 sc->tulip_high_intrspins = spins; 726 return unit; 727} 728 729/* 730 * This is the standard method of reading the DEC Address ROMS. 731 */ 732static int 733tulip_read_macaddr( 734 tulip_softc_t *sc) 735{ 736 int cksum, rom_cksum, idx; 737 tulip_sint32_t csr; 738 unsigned char tmpbuf[8]; 739 static u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 740 741 *sc->tulip_csrs.csr_enetrom = 1; 742 for (idx = 0; idx < 32; idx++) { 743 int cnt = 0; 744 while ((csr = *sc->tulip_csrs.csr_enetrom) < 0 && cnt < 10000) 745 cnt++; 746 sc->tulip_rombuf[idx] = csr & 0xFF; 747 } 748 749 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) 750 return -4; 751 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 752 return -3; 753 754 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 755 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 756 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 757 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 758 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 759 return -2; 760 761 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 762 763 cksum = *(u_short *) &sc->tulip_hwaddr[0]; 764 cksum *= 2; 765 if (cksum > 65535) cksum -= 65535; 766 cksum += *(u_short *) &sc->tulip_hwaddr[2]; 767 if (cksum > 65535) cksum -= 65535; 768 cksum *= 2; 769 if (cksum > 65535) cksum -= 65535; 770 cksum += *(u_short *) &sc->tulip_hwaddr[4]; 771 if (cksum >= 65535) cksum -= 65535; 772 773 rom_cksum = *(u_short *) &sc->tulip_rombuf[6]; 774 775 if (cksum != rom_cksum) 776 return -1; 777 return 0; 778} 779 780static unsigned 781tulip_mchash( 782 unsigned char *mca) 783{ 784 u_int idx, bit, data, crc = 0xFFFFFFFFUL; 785 786#ifdef __alpha 787 for (data = *(__unaligned u_long *) mca, bit = 0; bit < 48; bit++, data >>= 7881) 789 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0); 790#else 791 for (idx = 0; idx < 6; idx++) 792 for (data = *mca++, bit = 0; bit < 8; bit++, data >>= 1) 793 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0); 794#endif 795 return crc & 0x1FF; 796} 797 798static void 799tulip_addr_filter( 800 tulip_softc_t *sc) 801{ 802 tulip_uint32_t *sp = sc->tulip_setupdata; 803 struct ether_multistep step; 804 struct ether_multi *enm; 805 int i; 806 807 sc->tulip_flags &= ~TULIP_WANTHASH; 808 sc->tulip_flags |= TULIP_WANTSETUP; 809 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 810 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 811 if (sc->tulip_ac.ac_multicnt > 14) { 812 unsigned hash; 813 /* 814 * If we have more than 14 multicasts, we have 815 * go into hash perfect mode (512 bit multicast 816 * hash and one perfect hardware). 817 */ 818 819 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 820 hash = tulip_mchash(etherbroadcastaddr); 821 sp[hash >> 4] |= 1 << (hash & 0xF); 822 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 823 while (enm != NULL) { 824 hash = tulip_mchash(enm->enm_addrlo); 825 sp[hash >> 4] |= 1 << (hash & 0xF); 826 ETHER_NEXT_MULTI(step, enm); 827 } 828 sc->tulip_cmdmode |= TULIP_WANTHASH; 829 sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 830 sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 831 sp[42] = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 832 } else { 833 /* 834 * Else can get perfect filtering for 16 addresses. 835 */ 836 i = 0; 837 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 838 for (; enm != NULL; i++) { 839 *sp++ = ((u_short *) enm->enm_addrlo)[0]; 840 *sp++ = ((u_short *) enm->enm_addrlo)[1]; 841 *sp++ = ((u_short *) enm->enm_addrlo)[2]; 842 ETHER_NEXT_MULTI(step, enm); 843 } 844 /* 845 * If an IP address is enabled, turn on broadcast 846 */ 847 if (sc->tulip_ac.ac_ipaddr.s_addr != 0) { 848 i++; 849 *sp++ = 0xFFFF; 850 *sp++ = 0xFFFF; 851 *sp++ = 0xFFFF; 852 } 853 /* 854 * Pad the rest with our hardware address 855 */ 856 for (; i < 16; i++) { 857 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 858 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 859 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 860 } 861 } 862} 863 864static int 865tulip_ioctl( 866 struct ifnet *ifp, 867 int cmd, 868 caddr_t data) 869{ 870 tulip_softc_t *sc = tulips[ifp->if_unit]; 871 int s, error = 0; 872 873 s = splimp(); 874 875 switch (cmd) { 876 case SIOCSIFADDR: { 877 struct ifaddr *ifa = (struct ifaddr *)data; 878 879 ifp->if_flags |= IFF_UP; 880 switch(ifa->ifa_addr->sa_family) { 881#ifdef INET 882 case AF_INET: { 883 ((struct arpcom *)ifp)->ac_ipaddr = IA_SIN(ifa)->sin_addr; 884 (*ifp->if_init)(ifp->if_unit); 885 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 886 break; 887 } 888#endif /* INET */ 889 890#ifdef NS 891 /* This magic copied from if_is.c; I don't use XNS, 892 * so I have no way of telling if this actually 893 * works or not. 894 */ 895 case AF_NS: { 896 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 897 if (ns_nullhost(*ina)) { 898 ina->x_host = *(union ns_host *)(sc->tulip_ac.ac_enaddr); 899 } else { 900 ifp->if_flags &= ~IFF_RUNNING; 901 bcopy((caddr_t)ina->x_host.c_host, 902 (caddr_t)sc->tulip_ac.ac_enaddr, 903 sizeof sc->tulip_ac.ac_enaddr); 904 } 905 906 (*ifp->if_init)(ifp->if_unit); 907 break; 908 } 909#endif /* NS */ 910 911 default: { 912 (*ifp->if_init)(ifp->if_unit); 913 break; 914 } 915 } 916 break; 917 } 918 919 case SIOCSIFFLAGS: { 920 /* 921 * Changing the connection forces a reset. 922 */ 923 if (sc->tulip_flags & TULIP_ALTPHYS) { 924 if ((ifp->if_flags & IFF_ALTPHYS) == 0) 925 TULIP_RESET(sc); 926 } else { 927 if (ifp->if_flags & IFF_ALTPHYS) 928 TULIP_RESET(sc); 929 } 930 (*ifp->if_init)(ifp->if_unit); 931 break; 932 } 933 934 case SIOCADDMULTI: 935 case SIOCDELMULTI: { 936 /* 937 * Update multicast listeners 938 */ 939 if (cmd == SIOCADDMULTI) 940 error = ether_addmulti((struct ifreq *)data, &sc->tulip_ac); 941 else 942 error = ether_delmulti((struct ifreq *)data, &sc->tulip_ac); 943 944 if (error == ENETRESET) { 945 tulip_addr_filter(sc); /* reset multicast filtering */ 946 (*ifp->if_init)(ifp->if_unit); 947 error = 0; 948 } 949 break; 950 } 951 952 default: { 953 error = EINVAL; 954 break; 955 } 956 } 957 958 splx(s); 959 return error; 960} 961 962static void 963tulip_attach( 964 tulip_softc_t *sc) 965{ 966 struct ifnet *ifp = &sc->tulip_if; 967 struct ifaddr *ifa = ifp->if_addrlist; 968 int cnt; 969 970 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS; 971 ifp->if_flags |= IFF_MULTICAST; 972 973 *sc->tulip_csrs.csr_sia_connectivity = 0; 974 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 975 for (cnt = 0; cnt < 240000; cnt++) { 976 if ((*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) == 0) 977 break; 978 DELAY(10); 979 } 980 if (*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) { 981 ifp->if_flags |= IFF_ALTPHYS; 982 } else { 983 sc->tulip_flags |= TULIP_ALTPHYS; 984 } 985 TULIP_RESET(sc); 986 987 ifp->if_init = tulip_init; 988 ifp->if_ioctl = tulip_ioctl; 989 ifp->if_output = ether_output; 990 ifp->if_reset = tulip_reset; 991 ifp->if_start = tulip_start; 992 ifp->if_mtu = ETHERMTU; 993 ifp->if_type = IFT_ETHER; 994 ifp->if_addrlen = 6; 995 ifp->if_hdrlen = 14; 996 997 printf("%s%d: DC21040 pass %d.%d (TULIP) ethernet address %s\n", 998 sc->tulip_name, sc->tulip_unit, 999 (sc->tulip_revinfo & 0xF0) >> 4, 1000 sc->tulip_revinfo & 0x0F, 1001 ether_sprintf(sc->tulip_hwaddr)); 1002 1003#if NBPFILTER > 0 1004 bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 1005#endif 1006 1007 if_attach(ifp); 1008 1009 while (ifa && ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_LINK) 1010 ifa = ifa->ifa_next; 1011 1012 if (ifa != NULL && ifa->ifa_addr != NULL) { 1013 struct sockaddr_dl *sdl; 1014 /* 1015 * Provide our ether address to the higher layers 1016 */ 1017 sdl = (struct sockaddr_dl *) ifa->ifa_addr; 1018 sdl->sdl_type = IFT_ETHER; 1019 sdl->sdl_alen = 6; 1020 sdl->sdl_slen = 0; 1021 bcopy(sc->tulip_ac.ac_enaddr, LLADDR(sdl), 6); 1022 } 1023} 1024 1025static void 1026tulip_initcsrs( 1027 tulip_softc_t *sc, 1028 volatile tulip_uint32_t *va_csrs, 1029 size_t csr_size) 1030{ 1031 sc->tulip_csrs.csr_busmode = va_csrs + 0 * csr_size; 1032 sc->tulip_csrs.csr_txpoll = va_csrs + 1 * csr_size; 1033 sc->tulip_csrs.csr_rxpoll = va_csrs + 2 * csr_size; 1034 sc->tulip_csrs.csr_rxlist = va_csrs + 3 * csr_size; 1035 sc->tulip_csrs.csr_txlist = va_csrs + 4 * csr_size; 1036 sc->tulip_csrs.csr_status = va_csrs + 5 * csr_size; 1037 sc->tulip_csrs.csr_command = va_csrs + 6 * csr_size; 1038 sc->tulip_csrs.csr_intr = va_csrs + 7 * csr_size; 1039 sc->tulip_csrs.csr_missed_frame = va_csrs + 8 * csr_size; 1040 sc->tulip_csrs.csr_enetrom = va_csrs + 9 * csr_size; 1041 sc->tulip_csrs.csr_reserved = va_csrs + 10 * csr_size; 1042 sc->tulip_csrs.csr_full_duplex = va_csrs + 11 * csr_size; 1043 sc->tulip_csrs.csr_sia_status = va_csrs + 12 * csr_size; 1044 sc->tulip_csrs.csr_sia_connectivity = va_csrs + 13 * csr_size; 1045 sc->tulip_csrs.csr_sia_tx_rx = va_csrs + 14 * csr_size; 1046 sc->tulip_csrs.csr_sia_general = va_csrs + 15 * csr_size; 1047} 1048 1049static void 1050tulip_initring( 1051 tulip_softc_t *sc, 1052 tulip_ringinfo_t *ri, 1053 tulip_desc_t *descs, 1054 int ndescs) 1055{ 1056 ri->ri_max = ndescs; 1057 ri->ri_first = descs; 1058 ri->ri_last = ri->ri_first + ri->ri_max; 1059 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 1060 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 1061} 1062 1063#if NPCI > 0 1064/* 1065 * This is the PCI configuration support. Since the DC21040 is available 1066 * on both EISA and PCI boards, one must be careful in how defines the 1067 * DC21040 in the config file. 1068 */ 1069static int tulip_pci_probe(pcici_t config_id); 1070static int tulip_pci_attach(pcici_t config_id); 1071 1072struct pci_driver dedevice = { 1073 tulip_pci_probe, 1074 tulip_pci_attach, 1075 0x00021011ul, 1076#if __FreeBSD__ == 1 1077 "de", 1078#endif 1079 "digital dc21040 ethernet", 1080 tulip_intr 1081}; 1082 1083#define PCI_CFID 0x00 /* Configuration ID */ 1084#define PCI_CFCS 0x04 /* Configurtion Command/Status */ 1085#define PCI_CFRV 0x08 /* Configuration Revision */ 1086#define PCI_CFLT 0x0c /* Configuration Latency Timer */ 1087#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 1088#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 1089#define PCI_CFIT 0x3c /* Configuration Interrupt */ 1090#define PCI_CFDA 0x40 /* Configuration Driver Area */ 1091 1092#define TULIP_PCI_CSRSIZE (8 / sizeof(tulip_uint32_t)) 1093static int 1094tulip_pci_probe( 1095 pcici_t config_id) 1096{ 1097 int idx; 1098 for (idx = 0; idx < NDE; idx++) 1099 if (tulips[idx] == NULL) 1100 return idx; 1101 return -1; 1102} 1103 1104static int 1105tulip_pci_attach( 1106 pcici_t config_id) 1107{ 1108 tulip_softc_t *sc; 1109 int retval, idx, revinfo, unit; 1110 signed int csr; 1111 vm_offset_t va_csrs, pa_csrs; 1112 int result; 1113 tulip_desc_t *rxdescs, *txdescs; 1114 1115 unit = tulip_pci_probe(config_id); 1116 1117 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); 1118 if (sc == NULL) 1119 return -1; 1120 1121 rxdescs = (tulip_desc_t *) 1122 malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT); 1123 if (rxdescs == NULL) { 1124 free((caddr_t) sc, M_DEVBUF); 1125 return -1; 1126 } 1127 1128 txdescs = (tulip_desc_t *) 1129 malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT); 1130 if (txdescs == NULL) { 1131 free((caddr_t) rxdescs, M_DEVBUF); 1132 free((caddr_t) sc, M_DEVBUF); 1133 return -1; 1134 } 1135 1136 bzero(sc, sizeof(sc)); /* Zero out the softc*/ 1137 sc->tulip_rxspace = kmem_alloc(kernel_map, TULIP_RXSPACE + NBPG); 1138 /* 1139 * We've allocated an extra page of receive space so we can double map 1140 * the first page of the receive space into the page after the last page 1141 * of the receive space. This means that even if a receive wraps around 1142 * the end of the receive space, it will still virtually contiguous and 1143 * that greatly simplifies the recevie logic. 1144 */ 1145 pmap_enter(pmap_kernel(), sc->tulip_rxspace + TULIP_RXSPACE, 1146 vtophys(sc->tulip_rxspace), VM_PROT_READ, TRUE); 1147 1148 sc->tulip_unit = unit; 1149 sc->tulip_name = "de"; 1150 retval = pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs); 1151 if (retval) { 1152 printf("de%d: pci_map_mem failed.\n", unit); 1153 kmem_free(kernel_map, sc->tulip_rxspace, TULIP_RXSPACE + NBPG); 1154 free((caddr_t) txdescs, M_DEVBUF); 1155 free((caddr_t) rxdescs, M_DEVBUF); 1156 free((caddr_t) sc, M_DEVBUF); 1157 return -1; 1158 } 1159 tulips[unit] = sc; 1160 tulip_initcsrs(sc, (volatile tulip_uint32_t *) va_csrs, TULIP_PCI_CSRSIZE); 1161 tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS); 1162 tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS); 1163 sc->tulip_revinfo = pci_conf_read(config_id, PCI_CFRV); 1164 if ((retval = tulip_read_macaddr(sc)) < 0) { 1165 printf("de%d: can't read ENET ROM (why=%d) (", sc->tulip_unit, retval); 1166 for (idx = 0; idx < 32; idx++) 1167 printf("%02x", sc->tulip_rombuf[idx]); 1168 printf("\n"); 1169 printf("%s%d: DC21040 %d.%d ethernet address %s\n", 1170 sc->tulip_name, sc->tulip_unit, 1171 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F, 1172 "unknown"); 1173 } else { 1174 TULIP_RESET(sc); 1175 tulip_attach(sc); 1176 } 1177 return 1; 1178} 1179#endif /* NPCI > 0 */ 1180#endif /* NDE > 0 */ 1181