if_de.c revision 8699
1/*- 2 * Copyright (c) 1994, 1995 Matt Thomas (matt@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.25 1995/05/22 05:51:41 davidg Exp $ 25 * 26 */ 27 28/* 29 * DEC DC21040 PCI Ethernet Controller 30 * 31 * Written by Matt Thomas 32 * BPF support code stolen directly from if_ec.c 33 * 34 * This driver supports the DEC DE435 or any other PCI 35 * board which support DC21040 or DC21140 (mostly). 36 */ 37 38#define __IF_DE_C__ "pl2 95/03/21" 39#ifndef __bsdi__ 40#include "de.h" 41#endif 42#if NDE > 0 || defined(__bsdi__) 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/mbuf.h> 47#include <sys/protosw.h> 48#include <sys/socket.h> 49#include <sys/ioctl.h> 50#include <sys/errno.h> 51#include <sys/malloc.h> 52#include <sys/kernel.h> 53#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */ 54#if defined(__FreeBSD__) 55#include <sys/devconf.h> 56#include <machine/clock.h> 57#endif 58#if defined(__bsdi__) 59#include <sys/device.h> 60#endif 61 62#include <net/if.h> 63#include <net/if_types.h> 64#include <net/if_dl.h> 65#include <net/route.h> 66 67#include "bpfilter.h" 68#if NBPFILTER > 0 69#include <net/bpf.h> 70#include <net/bpfdesc.h> 71#endif 72 73#ifdef INET 74#include <netinet/in.h> 75#include <netinet/in_systm.h> 76#include <netinet/in_var.h> 77#include <netinet/ip.h> 78#include <netinet/if_ether.h> 79#endif 80 81#ifdef NS 82#include <netns/ns.h> 83#include <netns/ns_if.h> 84#endif 85 86#include <vm/vm.h> 87#include <vm/vm_kern.h> 88#include <vm/vm_param.h> 89 90#if defined(__FreeBSD__) 91#include <pci.h> 92#if NPCI > 0 93#include <pci/pcivar.h> 94#include <pci/dc21040.h> 95#endif 96#endif 97 98#if defined(__bsdi__) 99#include <i386/pci/pci.h> 100#include <i386/pci/dc21040.h> 101#include <i386/isa/isa.h> 102#include <i386/isa/icu.h> 103#include <i386/isa/dma.h> 104#include <i386/isa/isavar.h> 105#endif 106 107/* 108 * This module supports 109 * the DEC DC21040 PCI Ethernet Controller. 110 * the DEC DC21140 PCI Fast Ethernet Controller. 111 */ 112 113typedef struct { 114 unsigned long addr; 115 unsigned long length; 116} tulip_addrvec_t; 117 118typedef struct { 119 tulip_desc_t *ri_first; 120 tulip_desc_t *ri_last; 121 tulip_desc_t *ri_nextin; 122 tulip_desc_t *ri_nextout; 123 int ri_max; 124 int ri_free; 125} tulip_ringinfo_t; 126 127typedef struct { 128 volatile tulip_uint32_t *csr_busmode; /* CSR0 */ 129 volatile tulip_uint32_t *csr_txpoll; /* CSR1 */ 130 volatile tulip_uint32_t *csr_rxpoll; /* CSR2 */ 131 volatile tulip_uint32_t *csr_rxlist; /* CSR3 */ 132 volatile tulip_uint32_t *csr_txlist; /* CSR4 */ 133 volatile tulip_uint32_t *csr_status; /* CSR5 */ 134 volatile tulip_uint32_t *csr_command; /* CSR6 */ 135 volatile tulip_uint32_t *csr_intr; /* CSR7 */ 136 volatile tulip_uint32_t *csr_missed_frame; /* CSR8 */ 137 138 /* DC21040 specific registers */ 139 140 volatile tulip_sint32_t *csr_enetrom; /* CSR9 */ 141 volatile tulip_uint32_t *csr_reserved; /* CSR10 */ 142 volatile tulip_uint32_t *csr_full_duplex; /* CSR11 */ 143 volatile tulip_uint32_t *csr_sia_status; /* CSR12 */ 144 volatile tulip_uint32_t *csr_sia_connectivity; /* CSR13 */ 145 volatile tulip_uint32_t *csr_sia_tx_rx; /* CSR14 */ 146 volatile tulip_uint32_t *csr_sia_general; /* CSR15 */ 147 148 /* DC21140/DC21041 specific registers */ 149 150 volatile tulip_uint32_t *csr_srom_mii; /* CSR9 */ 151 volatile tulip_uint32_t *csr_gp_timer; /* CSR11 */ 152 volatile tulip_uint32_t *csr_gp; /* CSR12 */ 153 volatile tulip_uint32_t *csr_watchdog; /* CSR15 */ 154} tulip_regfile_t; 155 156/* 157 * The DC21040 has a stupid restriction in that the receive 158 * buffers must be longword aligned. But since Ethernet 159 * headers are not a multiple of longwords in size this forces 160 * the data to non-longword aligned. Since IP requires the 161 * data to be longword aligned, we need to copy it after it has 162 * been DMA'ed in our memory. 163 * 164 * Since we have to copy it anyways, we might as well as allocate 165 * dedicated receive space for the input. This allows to use a 166 * small receive buffer size and more ring entries to be able to 167 * better keep with a flood of tiny Ethernet packets. 168 * 169 * The receive space MUST ALWAYS be a multiple of the page size. 170 * And the number of receive descriptors multiplied by the size 171 * of the receive buffers must equal the recevive space. This 172 * is so that we can manipulate the page tables so that even if a 173 * packet wraps around the end of the receive space, we can 174 * treat it as virtually contiguous. 175 * 176 * The above used to be true (the stupid restriction is still true) 177 * but we gone to directly DMA'ing into MBUFs because with 100Mb 178 * cards the copying is just too much of a hit. 179 */ 180#define TULIP_RXDESCS 16 181#define TULIP_TXDESCS 128 182#define TULIP_RXQ_TARGET 8 183 184typedef enum { 185 TULIP_DC21040_GENERIC, 186 TULIP_DC21140_DEC_EB, 187 TULIP_DC21140_DEC_DE500, 188 TULIP_DC21140_COGENT_EM100 189} tulip_board_t; 190 191typedef struct _tulip_softc_t tulip_softc_t; 192 193typedef struct { 194 tulip_board_t bd_type; 195 const char *bd_description; 196 int (*bd_media_probe)(tulip_softc_t *sc); 197 void (*bd_media_select)(tulip_softc_t *sc); 198} tulip_boardsw_t; 199 200typedef enum { TULIP_DC21040, TULIP_DC21140, TULIP_DC21041 } tulip_chipid_t; 201 202struct _tulip_softc_t { 203#if defined(__bsdi__) 204 struct device tulip_dev; /* base device */ 205 struct isadev tulip_id; /* ISA device */ 206 struct intrhand tulip_ih; /* intrrupt vectoring */ 207 struct atshutdown tulip_ats; /* shutdown routine */ 208#endif 209 struct arpcom tulip_ac; 210 tulip_regfile_t tulip_csrs; 211 unsigned tulip_flags; 212#define TULIP_WANTSETUP 0x01 213#define TULIP_WANTHASH 0x02 214#define TULIP_DOINGSETUP 0x04 215#define TULIP_ALTPHYS 0x08 /* use AUI */ 216 unsigned char tulip_rombuf[128]; 217 tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)]; 218 tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)]; 219 tulip_uint32_t tulip_intrmask; 220 tulip_uint32_t tulip_cmdmode; 221 tulip_uint32_t tulip_revinfo; 222 tulip_chipid_t tulip_chipid; 223 const tulip_boardsw_t *tulip_boardsw; 224#if NBPFILTER > 0 && !defined(__bsdi__) && !defined(__FreeBSD__) 225 caddr_t tulip_bpf; /* BPF context */ 226#endif 227 struct ifqueue tulip_txq; 228 struct ifqueue tulip_rxq; 229 tulip_ringinfo_t tulip_rxinfo; 230 tulip_ringinfo_t tulip_txinfo; 231}; 232 233#ifndef IFF_ALTPHYS 234#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */ 235#endif 236const char *tulip_chipdescs[] = { 237 "DC21040 [10Mb/s]", 238 "DC21140 [10-100Mb/s]", 239 "DC21041 [10Mb/s]" 240}; 241 242#if defined(__FreeBSD__) 243typedef void ifnet_ret_t; 244tulip_softc_t *tulips[NDE]; 245#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit]) 246#define tulip_bpf tulip_ac.ac_if.if_bpf 247#endif 248#if defined(__bsdi__) 249typedef int ifnet_ret_t; 250extern struct cfdriver decd; 251#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) 252#define tulip_bpf tulip_ac.ac_if.if_bpf 253#endif 254 255#define tulip_if tulip_ac.ac_if 256#define tulip_unit tulip_ac.ac_if.if_unit 257#define tulip_name tulip_ac.ac_if.if_name 258#define tulip_hwaddr tulip_ac.ac_enaddr 259 260#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 261#define TULIP_CHECK_RXCRC 0 262#define TULIP_MAX_TXSEG 30 263 264#define TULIP_ADDREQUAL(a1, a2) \ 265 (((u_short *)a1)[0] == ((u_short *)a2)[0] \ 266 && ((u_short *)a1)[1] == ((u_short *)a2)[1] \ 267 && ((u_short *)a1)[2] == ((u_short *)a2)[2]) 268#define TULIP_ADDRBRDCST(a1) \ 269 (((u_short *)a1)[0] == 0xFFFFU \ 270 && ((u_short *)a1)[1] == 0xFFFFU \ 271 && ((u_short *)a1)[2] == 0xFFFFU) 272 273static ifnet_ret_t tulip_start(struct ifnet *ifp); 274static void tulip_rx_intr(tulip_softc_t *sc); 275static void tulip_addr_filter(tulip_softc_t *sc); 276 277#if __FreeBSD__ > 1 || defined(__bsdi__) 278#define TULIP_IFRESET_ARGS int unit 279#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit) 280#else 281#define TULIP_IFRESET_ARGS int unit, int uban 282#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit, 0) 283#endif 284 285 286static int 287tulip_dc21040_media_probe( 288 tulip_softc_t *sc) 289{ 290 int cnt; 291 292 *sc->tulip_csrs.csr_sia_connectivity = 0; 293 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 294 for (cnt = 0; cnt < 2400; cnt++) { 295 if ((*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) == 0) 296 break; 297 DELAY(1000); 298 } 299 return (*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) != 0; 300} 301 302static void 303tulip_dc21040_media_select( 304 tulip_softc_t *sc) 305{ 306 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT; 307 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_RESET; 308 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 309 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 310 printf("%s%d: enabling Thinwire/AUI port\n", 311 sc->tulip_if.if_name, sc->tulip_if.if_unit); 312 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_AUI; 313 sc->tulip_flags |= TULIP_ALTPHYS; 314 } else { 315 if (sc->tulip_flags & TULIP_ALTPHYS) 316 printf("%s%d: enabling 10baseT/UTP port\n", 317 sc->tulip_if.if_name, sc->tulip_if.if_unit); 318 *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 319 sc->tulip_flags &= ~TULIP_ALTPHYS; 320 } 321} 322 323static const tulip_boardsw_t tulip_dc21040_boardsw = { 324 TULIP_DC21040_GENERIC, 325 "", 326 tulip_dc21040_media_probe, 327 tulip_dc21040_media_select 328}; 329 330static int 331tulip_dc21140_evalboard_media_probe( 332 tulip_softc_t *sc) 333{ 334 *sc->tulip_csrs.csr_gp = TULIP_GP_EB_PINS; 335 *sc->tulip_csrs.csr_gp = TULIP_GP_EB_INIT; 336 *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 337 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 338 *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 339 DELAY(1000000); 340 return (*sc->tulip_csrs.csr_gp & TULIP_GP_EB_OK100) != 0; 341} 342 343static void 344tulip_dc21140_evalboard_media_select( 345 tulip_softc_t *sc) 346{ 347 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 348 *sc->tulip_csrs.csr_gp = TULIP_GP_EB_PINS; 349 *sc->tulip_csrs.csr_gp = TULIP_GP_EB_INIT; 350 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 351 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 352 printf("%s%d: enabling 100baseTX UTP port\n", 353 sc->tulip_if.if_name, sc->tulip_if.if_unit); 354 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 355 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 356 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 357 sc->tulip_flags |= TULIP_ALTPHYS; 358 } else { 359 if (sc->tulip_flags & TULIP_ALTPHYS) 360 printf("%s%d: enabling 10baseT UTP port\n", 361 sc->tulip_if.if_name, sc->tulip_if.if_unit); 362 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 363 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 364 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 365 sc->tulip_flags &= ~TULIP_ALTPHYS; 366 } 367} 368 369static const tulip_boardsw_t tulip_dc21140_eb_boardsw = { 370 TULIP_DC21140_DEC_EB, 371 "", 372 tulip_dc21140_evalboard_media_probe, 373 tulip_dc21140_evalboard_media_select 374}; 375 376 377static int 378tulip_dc21140_cogent_em100_media_probe( 379 tulip_softc_t *sc) 380{ 381 *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_PINS; 382 *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_INIT; 383 *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 384 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 385 *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 386 return 1; 387} 388 389static void 390tulip_dc21140_cogent_em100_media_select( 391 tulip_softc_t *sc) 392{ 393 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 394 *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_PINS; 395 *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_INIT; 396 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 397 printf("%s%d: enabling 100baseTX UTP port\n", 398 sc->tulip_if.if_name, sc->tulip_if.if_unit); 399 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 400 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 401 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 402 sc->tulip_flags |= TULIP_ALTPHYS; 403} 404 405static const tulip_boardsw_t tulip_dc21140_cogent_em100_boardsw = { 406 TULIP_DC21140_COGENT_EM100, 407 "Cogent EM100", 408 tulip_dc21140_cogent_em100_media_probe, 409 tulip_dc21140_cogent_em100_media_select 410}; 411 412static int 413tulip_dc21140_de500_media_probe( 414 tulip_softc_t *sc) 415{ 416 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_PINS; 417 DELAY(1000); 418 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX; 419 if ((*sc->tulip_csrs.csr_gp & (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) != (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) 420 return (*sc->tulip_csrs.csr_gp & TULIP_GP_DE500_NOTOK_100) != 0; 421 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100; 422 *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 423 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 424 *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 425 DELAY(1000000); 426 return (*sc->tulip_csrs.csr_gp & TULIP_GP_DE500_NOTOK_100) != 0; 427} 428 429static void 430tulip_dc21140_de500_media_select( 431 tulip_softc_t *sc) 432{ 433 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 434 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_PINS; 435 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 436 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 437 printf("%s%d: enabling 100baseTX UTP port\n", 438 sc->tulip_if.if_name, sc->tulip_if.if_unit); 439 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 440 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 441 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 442 sc->tulip_flags |= TULIP_ALTPHYS; 443 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX 444 |TULIP_GP_DE500_FORCE_100; 445 } else { 446 if (sc->tulip_flags & TULIP_ALTPHYS) 447 printf("%s%d: enabling 10baseT UTP port\n", 448 sc->tulip_if.if_name, sc->tulip_if.if_unit); 449 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 450 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 451 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 452 sc->tulip_flags &= ~TULIP_ALTPHYS; 453 *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX; 454 } 455} 456 457static const tulip_boardsw_t tulip_dc21140_de500_boardsw = { 458 TULIP_DC21140_DEC_DE500, "Digital DE500 ", 459 tulip_dc21140_de500_media_probe, 460 tulip_dc21140_de500_media_select 461}; 462 463static ifnet_ret_t 464tulip_reset( 465 TULIP_IFRESET_ARGS) 466{ 467 tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(unit); 468 tulip_ringinfo_t *ri; 469 tulip_desc_t *di; 470 471 *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 472 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 473 33MHz that comes to two microseconds but wait a 474 bit longer anyways) */ 475 476 (*sc->tulip_boardsw->bd_media_select)(sc); 477 478 *sc->tulip_csrs.csr_txlist = vtophys(&sc->tulip_txinfo.ri_first[0]); 479 *sc->tulip_csrs.csr_rxlist = vtophys(&sc->tulip_rxinfo.ri_first[0]); 480 *sc->tulip_csrs.csr_intr = 0; 481 *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_BURSTLEN_8LW 482 |TULIP_BUSMODE_CACHE_ALIGN8 483 |(BYTE_ORDER != LITTLE_ENDIAN 484 ? TULIP_BUSMODE_BIGENDIAN 485 : 0); 486 487 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 488 /* 489 * Free all the mbufs that were on the transmit ring. 490 */ 491 for (;;) { 492 struct mbuf *m; 493 IF_DEQUEUE(&sc->tulip_txq, m); 494 if (m == NULL) 495 break; 496 m_freem(m); 497 } 498 499 ri = &sc->tulip_txinfo; 500 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 501 ri->ri_free = ri->ri_max; 502 for (di = ri->ri_first; di < ri->ri_last; di++) 503 di->d_status = 0; 504 505 /* 506 * We need to collect all the mbufs were on the 507 * receive ring before we reinit it either to put 508 * them back on or to know if we have to allocate 509 * more. 510 */ 511 ri = &sc->tulip_rxinfo; 512 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 513 ri->ri_free = ri->ri_max; 514 for (di = ri->ri_first; di < ri->ri_last; di++) { 515 di->d_status = 0; 516 di->d_length1 = 0; di->d_addr1 = 0; 517 di->d_length2 = 0; di->d_addr2 = 0; 518 } 519 for (;;) { 520 struct mbuf *m; 521 IF_DEQUEUE(&sc->tulip_rxq, m); 522 if (m == NULL) 523 break; 524 m_freem(m); 525 } 526 527 sc->tulip_intrmask = TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 528 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 529 |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED; 530 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP); 531 tulip_addr_filter(sc); 532} 533 534static ifnet_ret_t 535tulip_init( 536 int unit) 537{ 538 tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(unit); 539 540 if (sc->tulip_if.if_flags & IFF_UP) { 541 sc->tulip_if.if_flags |= IFF_RUNNING; 542 if (sc->tulip_if.if_flags & IFF_PROMISC) { 543 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 544 } else { 545 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 546 if (sc->tulip_if.if_flags & IFF_ALLMULTI) { 547 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 548 } else { 549 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 550 } 551 } 552 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 553 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 554 tulip_rx_intr(sc); 555 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 556 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 557 } else { 558 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 559 tulip_start(&sc->tulip_if); 560 } 561 sc->tulip_cmdmode |= TULIP_CMD_THRSHLD160; 562 *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 563 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 564 } else { 565 TULIP_RESET(sc); 566 sc->tulip_if.if_flags &= ~IFF_RUNNING; 567 } 568} 569 570 571#if TULIP_CHECK_RXCRC 572static unsigned 573tulip_crc32( 574 u_char *addr, 575 int len) 576{ 577 unsigned int crc = 0xFFFFFFFF; 578 static unsigned int crctbl[256]; 579 int idx; 580 static int done; 581 /* 582 * initialize the multicast address CRC table 583 */ 584 for (idx = 0; !done && idx < 256; idx++) { 585 unsigned int tmp = idx; 586 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 587 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 588 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 589 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 590 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 591 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 592 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 593 tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 594 crctbl[idx] = tmp; 595 } 596 done = 1; 597 598 while (len-- > 0) 599 crc = (crc >> 8) ^ crctbl[*addr++] ^ crctbl[crc & 0xFF]; 600 601 return crc; 602} 603#endif 604 605static void 606tulip_rx_intr( 607 tulip_softc_t *sc) 608{ 609 tulip_ringinfo_t *ri = &sc->tulip_rxinfo; 610 struct ifnet *ifp = &sc->tulip_if; 611 612 for (;;) { 613 struct ether_header eh; 614 tulip_desc_t *eop = ri->ri_nextin; 615 int total_len = 0; 616 struct mbuf *m = NULL; 617 int accept = 0; 618 619 if (sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) 620 goto queue_mbuf; 621 622 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 623 break; 624 625 total_len = ((eop->d_status >> 16) & 0x7FF) - 4; 626 IF_DEQUEUE(&sc->tulip_rxq, m); 627 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0) { 628 629#if TULIP_CHECK_RXCRC 630 unsigned crc = tulip_crc32(mtod(m, unsigned char *), total_len); 631 if (~crc != *((unsigned *) &bufaddr[total_len])) { 632 printf("de0: bad rx crc: %08x [rx] != %08x\n", 633 *((unsigned *) &bufaddr[total_len]), ~crc); 634 goto next; 635 } 636#endif 637 eh = *mtod(m, struct ether_header *); 638#if NBPFILTER > 0 639 if (sc->tulip_bpf != NULL) { 640 bpf_tap(sc->tulip_bpf, mtod(m, caddr_t), total_len); 641 if (sc->tulip_if.if_flags & IFF_PROMISC && 642 (eh.ether_dhost[0] & 1) == 0 && 643 !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr)) 644 goto next; 645 } 646#endif 647 accept = 1; 648 } else { 649 ifp->if_ierrors++; 650 } 651 next: 652 ifp->if_ipackets++; 653 if (++ri->ri_nextin == ri->ri_last) 654 ri->ri_nextin = ri->ri_first; 655 queue_mbuf: 656 /* 657 * Either we are priming the TULIP with mbufs (m == NULL) 658 * or we are about to accept an mbuf for the upper layers 659 * so we need to allocate an mbuf to replace it. If we 660 * can't replace, then count it as an input error and reuse 661 * the mbuf. 662 */ 663 if (accept || m == NULL) { 664 struct mbuf *m0; 665 MGETHDR(m0, M_DONTWAIT, MT_DATA); 666 if (m0 != NULL) { 667 MCLGET(m0, M_DONTWAIT); 668 if ((m0->m_flags & M_EXT) == 0) { 669 m_freem(m0); 670 m0 = NULL; 671 } 672 } 673 if (accept) { 674 if (m0 != NULL) { 675 m->m_pkthdr.rcvif = ifp; 676 m->m_data += sizeof(struct ether_header); 677 m->m_len = m->m_pkthdr.len = total_len - 678 sizeof(struct ether_header); 679#if defined(__bsdi__) 680 eh.ether_type = ntohs(eh.ether_type); 681#endif 682 ether_input(ifp, &eh, m); 683 m = m0; 684 } else { 685 ifp->if_ierrors++; 686 } 687 } else { 688 m = m0; 689 } 690 } 691 if (m == NULL) 692 break; 693 /* 694 * Now give the buffer to the TULIP and save in our 695 * receive queue. 696 */ 697 ri->ri_nextout->d_length1 = MCLBYTES - 4; 698 ri->ri_nextout->d_addr1 = vtophys(mtod(m, caddr_t)); 699 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 700 if (++ri->ri_nextout == ri->ri_last) 701 ri->ri_nextout = ri->ri_first; 702 IF_ENQUEUE(&sc->tulip_rxq, m); 703 } 704} 705 706static int 707tulip_tx_intr( 708 tulip_softc_t *sc) 709{ 710 tulip_ringinfo_t *ri = &sc->tulip_txinfo; 711 struct mbuf *m; 712 int xmits = 0; 713 714 while (ri->ri_free < ri->ri_max) { 715 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 716 break; 717 718 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) { 719 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) { 720 /* 721 * We've just finished processing a setup packet. 722 * Mark that we can finished it. If there's not 723 * another pending, startup the TULIP receiver. 724 * Make sure we ack the RXSTOPPED so we won't get 725 * an abormal interrupt indication. 726 */ 727 sc->tulip_flags &= ~TULIP_DOINGSETUP; 728 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 729 tulip_rx_intr(sc); 730 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 731 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 732 *sc->tulip_csrs.csr_status = TULIP_STS_RXSTOPPED; 733 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 734 *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 735 } 736 } else { 737 IF_DEQUEUE(&sc->tulip_txq, m); 738 m_freem(m); 739 sc->tulip_if.if_collisions += 740 (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK) 741 >> TULIP_DSTS_V_TxCOLLCNT; 742 if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM) 743 sc->tulip_if.if_oerrors++; 744 xmits++; 745 } 746 } 747 748 if (++ri->ri_nextin == ri->ri_last) 749 ri->ri_nextin = ri->ri_first; 750 ri->ri_free++; 751 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 752 } 753 sc->tulip_if.if_opackets += xmits; 754 return xmits; 755} 756 757static int 758tulip_txsegment( 759 tulip_softc_t *sc, 760 struct mbuf *m, 761 tulip_addrvec_t *avp, 762 size_t maxseg) 763{ 764 int segcnt; 765 766 for (segcnt = 0; m; m = m->m_next) { 767 int len = m->m_len; 768 caddr_t addr = mtod(m, caddr_t); 769 unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); 770 771 while (len > 0) { 772 unsigned slen = min(len, clsize); 773 if (segcnt < maxseg) { 774 avp->addr = vtophys(addr); 775 avp->length = slen; 776 } 777 len -= slen; 778 addr += slen; 779 clsize = CLBYTES; 780 avp++; 781 segcnt++; 782 } 783 } 784 if (segcnt >= maxseg) { 785 printf("%s%d: tulip_txsegment: extremely fragmented packet encountered (%d segments)\n", 786 sc->tulip_name, sc->tulip_unit, segcnt); 787 return -1; 788 } 789 avp->addr = 0; 790 avp->length = 0; 791 return segcnt; 792} 793 794static ifnet_ret_t 795tulip_start( 796 struct ifnet *ifp) 797{ 798 tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit); 799 struct ifqueue *ifq = &ifp->if_snd; 800 tulip_ringinfo_t *ri = &sc->tulip_txinfo; 801 tulip_desc_t *sop, *eop; 802 struct mbuf *m; 803 static tulip_addrvec_t addrvec[TULIP_MAX_TXSEG+1]; 804 tulip_addrvec_t *avp; 805 int segcnt; 806 tulip_uint32_t d_status; 807 808 if ((ifp->if_flags & IFF_RUNNING) == 0) 809 return; 810 811 for (;;) { 812 if (sc->tulip_flags & TULIP_WANTSETUP) { 813 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 814 ifp->if_flags |= IFF_OACTIVE; 815 return; 816 } 817 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 818 sizeof(sc->tulip_setupbuf)); 819 sc->tulip_flags &= ~TULIP_WANTSETUP; 820 sc->tulip_flags |= TULIP_DOINGSETUP; 821 ri->ri_free--; 822 ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 823 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 824 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 825 if (sc->tulip_flags & TULIP_WANTHASH) 826 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 827 ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf); 828 ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf); 829 ri->ri_nextout->d_length2 = 0; 830 ri->ri_nextout->d_addr2 = 0; 831 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 832 *sc->tulip_csrs.csr_txpoll = 1; 833 /* 834 * Advance the ring for the next transmit packet. 835 */ 836 if (++ri->ri_nextout == ri->ri_last) 837 ri->ri_nextout = ri->ri_first; 838 } 839 840 IF_DEQUEUE(ifq, m); 841 if (m == NULL) 842 break; 843 844 /* 845 * First find out how many and which different pages 846 * the mbuf data occupies. Then check to see if we 847 * have enough descriptor space in our transmit ring 848 * to actually send it. 849 */ 850 segcnt = tulip_txsegment(sc, m, addrvec, 851 min(ri->ri_max - 1, TULIP_MAX_TXSEG)); 852 if (segcnt < 0) { 853 struct mbuf *m0; 854 MGETHDR(m0, M_DONTWAIT, MT_DATA); 855 if (m0 != NULL) { 856 if (m->m_pkthdr.len > MHLEN) { 857 MCLGET(m0, M_DONTWAIT); 858 if ((m0->m_flags & M_EXT) == 0) { 859 m_freem(m); 860 m_freem(m0); 861 continue; 862 } 863 } 864 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 865 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 866 m_freem(m); 867 IF_PREPEND(ifq, m0); 868 continue; 869 } else { 870 m_freem(m); 871 continue; 872 } 873 } 874 if (ri->ri_free - 2 <= (segcnt + 1) >> 1) 875 break; 876 877 ri->ri_free -= (segcnt + 1) >> 1; 878 /* 879 * Now we fill in our transmit descriptors. This is 880 * a bit reminiscent of going on the Ark two by two 881 * since each descriptor for the TULIP can describe 882 * two buffers. So we advance through the address 883 * vector two entries at a time to to fill each 884 * descriptor. Clear the first and last segment bits 885 * in each descriptor (actually just clear everything 886 * but the end-of-ring or chain bits) to make sure 887 * we don't get messed up by previously sent packets. 888 */ 889 sop = ri->ri_nextout; 890 d_status = 0; 891 avp = addrvec; 892 do { 893 eop = ri->ri_nextout; 894 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 895 eop->d_status = d_status; 896 eop->d_addr1 = avp->addr; eop->d_length1 = avp->length; avp++; 897 eop->d_addr2 = avp->addr; eop->d_length2 = avp->length; avp++; 898 d_status = TULIP_DSTS_OWNER; 899 if (++ri->ri_nextout == ri->ri_last) 900 ri->ri_nextout = ri->ri_first; 901 } while ((segcnt -= 2) > 0); 902#if NBPFILTER > 0 903 if (sc->tulip_bpf != NULL) 904 bpf_mtap(sc->tulip_bpf, m); 905#endif 906 /* 907 * The descriptors have been filled in. Mark the first 908 * and last segments, indicate we want a transmit complete 909 * interrupt, give the descriptors to the TULIP, and tell 910 * it to transmit! 911 */ 912 913 IF_ENQUEUE(&sc->tulip_txq, m); 914 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 915 sop->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 916 sop->d_status = TULIP_DSTS_OWNER; 917 918 *sc->tulip_csrs.csr_txpoll = 1; 919 } 920 if (m != NULL) { 921 ifp->if_flags |= IFF_OACTIVE; 922 IF_PREPEND(ifq, m); 923 } 924} 925 926static int 927tulip_intr( 928 tulip_softc_t *sc) 929{ 930 tulip_uint32_t csr; 931 int progress=0; 932 933 while ((csr = *sc->tulip_csrs.csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) { 934 progress = 1; 935 *sc->tulip_csrs.csr_status = csr & sc->tulip_intrmask; 936 937 if (csr & TULIP_STS_SYSERROR) { 938 if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) { 939 TULIP_RESET(sc); 940 tulip_init(sc->tulip_unit); 941 break; 942 } 943 } 944 if (csr & TULIP_STS_ABNRMLINTR) { 945 printf("%s%d: abnormal interrupt: 0x%05x [0x%05x]\n", 946 sc->tulip_name, sc->tulip_unit, csr, csr & sc->tulip_intrmask); 947 *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 948 } 949 if (csr & TULIP_STS_RXINTR) 950 tulip_rx_intr(sc); 951 if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) { 952 tulip_tx_intr(sc); 953 tulip_start(&sc->tulip_if); 954 } 955 } 956 return (progress); 957} 958 959/* 960 * 961 */ 962 963void 964tulip_delay_300ns( 965 tulip_softc_t *sc) 966{ 967 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 968 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 969 970 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 971 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 972 973 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 974 *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 975} 976 977#define EMIT do { *sc->tulip_csrs.csr_srom_mii = csr; tulip_delay_300ns(sc); } while (0) 978 979 980void 981tulip_idle_srom( 982 tulip_softc_t *sc) 983{ 984 unsigned bit, csr; 985 986 csr = SROMSEL | SROMRD; EMIT; 987 csr ^= SROMCS; EMIT; 988 csr ^= SROMCLKON; EMIT; 989 990 /* 991 * Write 25 cycles of 0 which will force the SROM to be idle. 992 */ 993 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 994 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 995 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 996 } 997 csr ^= SROMCLKOFF; EMIT; 998 csr ^= SROMCS; EMIT; EMIT; 999 csr = 0; EMIT; 1000} 1001 1002 1003void 1004tulip_read_srom( 1005 tulip_softc_t *sc) 1006{ 1007 int idx; 1008 const unsigned bitwidth = SROM_BITWIDTH; 1009 const unsigned cmdmask = (SROMCMD_RD << bitwidth); 1010 const unsigned msb = 1 << (bitwidth + 3 - 1); 1011 unsigned lastidx = (1 << bitwidth) - 1; 1012 1013 tulip_idle_srom(sc); 1014 1015 for (idx = 0; idx <= lastidx; idx++) { 1016 unsigned lastbit, data, bits, bit, csr; 1017 csr = SROMSEL | SROMRD; EMIT; 1018 csr ^= SROMCSON; EMIT; 1019 csr ^= SROMCLKON; EMIT; 1020 1021 lastbit = 0; 1022 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 1023 const unsigned thisbit = bits & msb; 1024 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1025 if (thisbit != lastbit) { 1026 csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 1027 } 1028 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1029 lastbit = thisbit; 1030 } 1031 csr ^= SROMCLKOFF; EMIT; 1032 1033 for (data = 0, bits = 0; bits < 16; bits++) { 1034 data <<= 1; 1035 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1036 data |= *sc->tulip_csrs.csr_srom_mii & SROMDIN ? 1 : 0; 1037 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1038 } 1039 sc->tulip_rombuf[idx*2] = data & 0xFF; 1040 sc->tulip_rombuf[idx*2+1] = data >> 8; 1041 csr = SROMSEL | SROMRD; EMIT; 1042 csr = 0; EMIT; 1043 } 1044} 1045 1046#define tulip_mchash(mca) ((tulip_crc32(mca, 6) >> 23) & 0x1FF) 1047#define tulip_srom_crcok(databuf) ( \ 1048 (tulip_crc32(databuf, 126) & 0xFFFF) == \ 1049 ((databuf)[126] | ((databuf)[127] << 8))) 1050 1051static unsigned 1052tulip_crc32( 1053 const unsigned char *databuf, 1054 size_t datalen) 1055{ 1056 u_int idx, bit, data, crc = 0xFFFFFFFFUL; 1057 1058 for (idx = 0; idx < datalen; idx++) 1059 for (data = *databuf++, bit = 0; bit < 8; bit++, data >>= 1) 1060 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0); 1061 return crc; 1062} 1063 1064 1065/* 1066 * This is the standard method of reading the DEC Address ROMS. 1067 */ 1068static int 1069tulip_read_macaddr( 1070 tulip_softc_t *sc) 1071{ 1072 int cksum, rom_cksum, idx; 1073 tulip_sint32_t csr; 1074 unsigned char tmpbuf[8]; 1075 static u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 1076 1077 if (sc->tulip_chipid == TULIP_DC21040) { 1078 *sc->tulip_csrs.csr_enetrom = 1; 1079 sc->tulip_boardsw = &tulip_dc21040_boardsw; 1080 for (idx = 0; idx < 32; idx++) { 1081 int cnt = 0; 1082 while ((csr = *sc->tulip_csrs.csr_enetrom) < 0 && cnt < 10000) 1083 cnt++; 1084 sc->tulip_rombuf[idx] = csr & 0xFF; 1085 } 1086 } else { 1087 /* 1088 * Assume all DC21140 board are compatible with the 1089 * DEC 10/100 evaluation board. Not really valid but ... 1090 */ 1091 if (sc->tulip_chipid == TULIP_DC21140) 1092 sc->tulip_boardsw = &tulip_dc21140_eb_boardsw; 1093 tulip_read_srom(sc); 1094 if (tulip_srom_crcok(sc->tulip_rombuf)) { 1095 /* 1096 * New SROM format. Copy out the Ethernet address. 1097 * If it contains a DE500-XA string, then it must be 1098 * a DE500-XA. 1099 */ 1100 bcopy(sc->tulip_rombuf + 20, sc->tulip_hwaddr, 6); 1101 if (bcmp(sc->tulip_rombuf + 29, "DE500-XA", 8) == 0) 1102 sc->tulip_boardsw = &tulip_dc21140_de500_boardsw; 1103 if (sc->tulip_boardsw == NULL) 1104 return -6; 1105 return 0; 1106 } 1107 } 1108 1109 1110 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 1111 /* 1112 * Some folks don't use the standard ethernet rom format 1113 * but instead just put the address in the first 6 bytes 1114 * of the rom and let the rest be all 0xffs. (Can we say 1115 * ZNYX???) 1116 */ 1117 for (idx = 6; idx < 32; idx++) { 1118 if (sc->tulip_rombuf[idx] != 0xFF) 1119 return -4; 1120 } 1121 /* 1122 * Make sure the address is not multicast or locally assigned 1123 * that the OUI is not 00-00-00. 1124 */ 1125 if ((sc->tulip_rombuf[0] & 3) != 0) 1126 return -4; 1127 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 1128 && sc->tulip_rombuf[2] == 0) 1129 return -4; 1130 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 1131 return 0; 1132 } 1133 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 1134 return -3; 1135 1136 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 1137 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 1138 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 1139 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 1140 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 1141 return -2; 1142 1143 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 1144 1145 cksum = *(u_short *) &sc->tulip_hwaddr[0]; 1146 cksum *= 2; 1147 if (cksum > 65535) cksum -= 65535; 1148 cksum += *(u_short *) &sc->tulip_hwaddr[2]; 1149 if (cksum > 65535) cksum -= 65535; 1150 cksum *= 2; 1151 if (cksum > 65535) cksum -= 65535; 1152 cksum += *(u_short *) &sc->tulip_hwaddr[4]; 1153 if (cksum >= 65535) cksum -= 65535; 1154 1155 rom_cksum = *(u_short *) &sc->tulip_rombuf[6]; 1156 1157 if (cksum != rom_cksum) 1158 return -1; 1159 1160 if (sc->tulip_chipid == TULIP_DC21140) { 1161 if (sc->tulip_hwaddr[0] == TULIP_OUI_COGENT_0 1162 && sc->tulip_hwaddr[1] == TULIP_OUI_COGENT_1 1163 && sc->tulip_hwaddr[2] == TULIP_OUI_COGENT_2) { 1164 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID) 1165 sc->tulip_boardsw = &tulip_dc21140_cogent_em100_boardsw; 1166 } 1167 } 1168 1169 return 0; 1170} 1171 1172static void 1173tulip_addr_filter( 1174 tulip_softc_t *sc) 1175{ 1176 tulip_uint32_t *sp = sc->tulip_setupdata; 1177 struct ether_multistep step; 1178 struct ether_multi *enm; 1179 int i; 1180 1181 sc->tulip_flags &= ~TULIP_WANTHASH; 1182 sc->tulip_flags |= TULIP_WANTSETUP; 1183 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 1184 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 1185 if (sc->tulip_ac.ac_multicnt > 14) { 1186 unsigned hash; 1187 /* 1188 * If we have more than 14 multicasts, we have 1189 * go into hash perfect mode (512 bit multicast 1190 * hash and one perfect hardware). 1191 */ 1192 1193 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 1194 hash = tulip_mchash(etherbroadcastaddr); 1195 sp[hash >> 4] |= 1 << (hash & 0xF); 1196 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 1197 while (enm != NULL) { 1198 hash = tulip_mchash(enm->enm_addrlo); 1199 sp[hash >> 4] |= 1 << (hash & 0xF); 1200 ETHER_NEXT_MULTI(step, enm); 1201 } 1202 sc->tulip_cmdmode |= TULIP_WANTHASH; 1203 sp[39] = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 1204 sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 1205 sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 1206 } else { 1207 /* 1208 * Else can get perfect filtering for 16 addresses. 1209 */ 1210 i = 0; 1211 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 1212 for (; enm != NULL; i++) { 1213 *sp++ = ((u_short *) enm->enm_addrlo)[0]; 1214 *sp++ = ((u_short *) enm->enm_addrlo)[1]; 1215 *sp++ = ((u_short *) enm->enm_addrlo)[2]; 1216 ETHER_NEXT_MULTI(step, enm); 1217 } 1218 /* 1219 * If an IP address is enabled, turn on broadcast 1220 */ 1221 if (sc->tulip_ac.ac_ipaddr.s_addr != 0) { 1222 i++; 1223 *sp++ = 0xFFFF; 1224 *sp++ = 0xFFFF; 1225 *sp++ = 0xFFFF; 1226 } 1227 /* 1228 * Pad the rest with our hardware address 1229 */ 1230 for (; i < 16; i++) { 1231 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 1232 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 1233 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 1234 } 1235 } 1236} 1237 1238/*extern void arp_ifinit(struct arpcom *, struct ifaddr*);*/ 1239 1240static int 1241tulip_ioctl( 1242 struct ifnet *ifp, 1243 int cmd, 1244 caddr_t data) 1245{ 1246 tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit); 1247 struct ifaddr *ifa = (struct ifaddr *)data; 1248 struct ifreq *ifr = (struct ifreq *) data; 1249 int s, error = 0; 1250 1251 s = splimp(); 1252 1253 switch (cmd) { 1254 case SIOCSIFADDR: { 1255 1256 ifp->if_flags |= IFF_UP; 1257 switch(ifa->ifa_addr->sa_family) { 1258#ifdef INET 1259 case AF_INET: { 1260 ((struct arpcom *)ifp)->ac_ipaddr = IA_SIN(ifa)->sin_addr; 1261 tulip_addr_filter(sc); /* reset multicast filtering */ 1262 (*ifp->if_init)(ifp->if_unit); 1263#if defined(__FreeBSD__) 1264 arp_ifinit((struct arpcom *)ifp, ifa); 1265#endif 1266 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 1267 break; 1268 } 1269#endif /* INET */ 1270 1271#ifdef NS 1272 /* This magic copied from if_is.c; I don't use XNS, 1273 * so I have no way of telling if this actually 1274 * works or not. 1275 */ 1276 case AF_NS: { 1277 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 1278 if (ns_nullhost(*ina)) { 1279 ina->x_host = *(union ns_host *)(sc->tulip_ac.ac_enaddr); 1280 } else { 1281 ifp->if_flags &= ~IFF_RUNNING; 1282 bcopy((caddr_t)ina->x_host.c_host, 1283 (caddr_t)sc->tulip_ac.ac_enaddr, 1284 sizeof sc->tulip_ac.ac_enaddr); 1285 } 1286 1287 (*ifp->if_init)(ifp->if_unit); 1288 break; 1289 } 1290#endif /* NS */ 1291 1292 default: { 1293 (*ifp->if_init)(ifp->if_unit); 1294 break; 1295 } 1296 } 1297 break; 1298 } 1299 1300 case SIOCSIFFLAGS: { 1301 /* 1302 * Changing the connection forces a reset. 1303 */ 1304 if (sc->tulip_flags & TULIP_ALTPHYS) { 1305 if ((ifp->if_flags & IFF_ALTPHYS) == 0) 1306 TULIP_RESET(sc); 1307 } else { 1308 if (ifp->if_flags & IFF_ALTPHYS) 1309 TULIP_RESET(sc); 1310 } 1311 (*ifp->if_init)(ifp->if_unit); 1312 break; 1313 } 1314 1315 case SIOCADDMULTI: 1316 case SIOCDELMULTI: { 1317 /* 1318 * Update multicast listeners 1319 */ 1320 if (cmd == SIOCADDMULTI) 1321 error = ether_addmulti(ifr, &sc->tulip_ac); 1322 else 1323 error = ether_delmulti(ifr, &sc->tulip_ac); 1324 1325 if (error == ENETRESET) { 1326 tulip_addr_filter(sc); /* reset multicast filtering */ 1327 (*ifp->if_init)(ifp->if_unit); 1328 error = 0; 1329 } 1330 break; 1331 } 1332#if defined(SIOCSIFMTU) 1333 case SIOCSIFMTU: 1334 /* 1335 * Set the interface MTU. 1336 */ 1337 if (ifr->ifr_mtu > ETHERMTU) { 1338 error = EINVAL; 1339 } else { 1340 ifp->if_mtu = ifr->ifr_mtu; 1341 } 1342 break; 1343#endif 1344 1345 default: { 1346 error = EINVAL; 1347 break; 1348 } 1349 } 1350 1351 splx(s); 1352 return error; 1353} 1354 1355static void 1356tulip_attach( 1357 tulip_softc_t *sc) 1358{ 1359 struct ifnet *ifp = &sc->tulip_if; 1360 1361 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; 1362 ifp->if_init = tulip_init; 1363 ifp->if_ioctl = tulip_ioctl; 1364 ifp->if_output = ether_output; 1365 ifp->if_start = tulip_start; 1366 1367#ifndef __bsdi__ 1368 printf("%s%d", sc->tulip_name, sc->tulip_unit); 1369#endif 1370 printf(": %s%s pass %d.%d Ethernet address %s\n", 1371 sc->tulip_boardsw->bd_description, 1372 tulip_chipdescs[sc->tulip_chipid], 1373 (sc->tulip_revinfo & 0xF0) >> 4, 1374 sc->tulip_revinfo & 0x0F, 1375 ether_sprintf(sc->tulip_hwaddr)); 1376 1377 if ((*sc->tulip_boardsw->bd_media_probe)(sc)) { 1378 ifp->if_flags |= IFF_ALTPHYS; 1379 } else { 1380 sc->tulip_flags |= TULIP_ALTPHYS; 1381 } 1382 1383 TULIP_RESET(sc); 1384 1385 if_attach(ifp); 1386 1387#if NBPFILTER > 0 1388 bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 1389#endif 1390} 1391 1392static void 1393tulip_initcsrs( 1394 tulip_softc_t *sc, 1395 volatile tulip_uint32_t *va_csrs, 1396 size_t csr_size) 1397{ 1398 sc->tulip_csrs.csr_busmode = va_csrs + 0 * csr_size; 1399 sc->tulip_csrs.csr_txpoll = va_csrs + 1 * csr_size; 1400 sc->tulip_csrs.csr_rxpoll = va_csrs + 2 * csr_size; 1401 sc->tulip_csrs.csr_rxlist = va_csrs + 3 * csr_size; 1402 sc->tulip_csrs.csr_txlist = va_csrs + 4 * csr_size; 1403 sc->tulip_csrs.csr_status = va_csrs + 5 * csr_size; 1404 sc->tulip_csrs.csr_command = va_csrs + 6 * csr_size; 1405 sc->tulip_csrs.csr_intr = va_csrs + 7 * csr_size; 1406 sc->tulip_csrs.csr_missed_frame = va_csrs + 8 * csr_size; 1407 if (sc->tulip_chipid == TULIP_DC21040) { 1408 sc->tulip_csrs.csr_enetrom = (tulip_sint32_t *) va_csrs + 9 * csr_size; 1409 sc->tulip_csrs.csr_reserved = va_csrs + 10 * csr_size; 1410 sc->tulip_csrs.csr_full_duplex = va_csrs + 11 * csr_size; 1411 sc->tulip_csrs.csr_sia_status = va_csrs + 12 * csr_size; 1412 sc->tulip_csrs.csr_sia_connectivity = va_csrs + 13 * csr_size; 1413 sc->tulip_csrs.csr_sia_tx_rx = va_csrs + 14 * csr_size; 1414 sc->tulip_csrs.csr_sia_general = va_csrs + 15 * csr_size; 1415 } else if (sc->tulip_chipid == TULIP_DC21140 || sc->tulip_chipid == TULIP_DC21041) { 1416 sc->tulip_csrs.csr_srom_mii = va_csrs + 9 * csr_size; 1417 sc->tulip_csrs.csr_gp_timer = va_csrs + 11 * csr_size; 1418 sc->tulip_csrs.csr_gp = va_csrs + 12 * csr_size; 1419 sc->tulip_csrs.csr_watchdog = va_csrs + 15 * csr_size; 1420 } 1421} 1422 1423static void 1424tulip_initring( 1425 tulip_softc_t *sc, 1426 tulip_ringinfo_t *ri, 1427 tulip_desc_t *descs, 1428 int ndescs) 1429{ 1430 ri->ri_max = ndescs; 1431 ri->ri_first = descs; 1432 ri->ri_last = ri->ri_first + ri->ri_max; 1433 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 1434 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 1435} 1436 1437/* 1438 * This is the PCI configuration support. Since the DC21040 is available 1439 * on both EISA and PCI boards, one must be careful in how defines the 1440 * DC21040 in the config file. 1441 */ 1442 1443#define PCI_CFID 0x00 /* Configuration ID */ 1444#define PCI_CFCS 0x04 /* Configurtion Command/Status */ 1445#define PCI_CFRV 0x08 /* Configuration Revision */ 1446#define PCI_CFLT 0x0c /* Configuration Latency Timer */ 1447#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 1448#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 1449#define PCI_CFIT 0x3c /* Configuration Interrupt */ 1450#define PCI_CFDA 0x40 /* Configuration Driver Area */ 1451 1452#define TULIP_PCI_CSRSIZE (8 / sizeof(tulip_uint32_t)) 1453 1454#if defined(__FreeBSD__) 1455 1456#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit 1457 1458static int 1459tulip_pci_shutdown( 1460 struct kern_devconf *kdc, 1461 int force) 1462{ 1463 if (kdc->kdc_unit < NDE) { 1464 tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit); 1465 *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 1466 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 1467 33MHz that comes to two microseconds but wait a 1468 bit longer anyways) */ 1469 } 1470 (void) dev_detach(kdc); 1471 return 0; 1472} 1473 1474static char* 1475tulip_pci_probe( 1476 pcici_t config_id, 1477 pcidi_t device_id) 1478{ 1479 if (device_id == 0x00021011ul) 1480 return "Digital DC21040 Ethernet"; 1481 if (device_id == 0x00141011ul) 1482 return "Digital DC21041 Ethernet"; 1483 if (device_id == 0x00091011ul) 1484 return "Digital DC21140 Fast Ethernet"; 1485 return NULL; 1486} 1487 1488static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 1489static u_long tulip_pci_count; 1490 1491struct pci_device dedevice = { 1492 "de", 1493 tulip_pci_probe, 1494 tulip_pci_attach, 1495 &tulip_pci_count, 1496 tulip_pci_shutdown, 1497}; 1498 1499DATA_SET (pcidevice_set, dedevice); 1500#endif /* __FreeBSD__ */ 1501 1502#if defined(__bsdi__) 1503#define TULIP_PCI_ATTACH_ARGS struct device *parent, struct device *self, void *aux 1504 1505static void 1506tulip_pci_shutdown( 1507 void *arg) 1508{ 1509 tulip_softc_t *sc = (tulip_softc_t *) arg; 1510 *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 1511 DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 1512 33MHz that comes to two microseconds but wait a 1513 bit longer anyways) */ 1514} 1515 1516static int 1517tulip_pci_match( 1518 pci_devaddr_t *pa) 1519{ 1520 int irq; 1521 unsigned id; 1522 1523 id = pci_inl(pa, PCI_VENDOR_ID); 1524 if ((id & 0xFFFF) != 0x1011) 1525 return 0; 1526 id >>= 16; 1527 if (id != 2 && id != 9 && id != 0x14) 1528 return 0; 1529 irq = pci_inl(pa, PCI_I_PIN) & 0xFF; 1530 if (irq == 0 || irq >= 16) 1531 return 0; 1532 1533 return 1; 1534} 1535 1536int 1537tulip_pci_probe( 1538 struct device *parent, 1539 struct cfdata *cf, 1540 void *aux) 1541{ 1542 struct isa_attach_args *ia = (struct isa_attach_args *) aux; 1543 unsigned irq; 1544 pci_devaddr_t *pa; 1545 1546 pa = pci_scan(tulip_pci_match); 1547 if (pa == NULL) 1548 return 0; 1549 1550 irq = (1 << (pci_inl(pa, PCI_I_PIN) & 0xFF)); 1551 1552 if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) { 1553 printf("fpa%d: error: desired IRQ of %d does not match device's actual IRQ of %d,\n", 1554 cf->cf_unit, 1555 ffs(ia->ia_irq) - 1, ffs(irq) - 1); 1556 return 0; 1557 } 1558 if (ia->ia_irq == IRQUNK) { 1559 if ((irq = isa_irqalloc(irq)) == 0) 1560 return 0; 1561 ia->ia_irq = irq; 1562 } 1563 1564 /* PCI bus masters don't use host DMA channels */ 1565 ia->ia_drq = DRQNONE; 1566 1567 /* Get the memory base address; assume the BIOS set it up correctly */ 1568 ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7); 1569 pci_outl(pa, PCI_CBMA, 0xFFFFFFFF); 1570 ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1; 1571 pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr); 1572 1573 /* Disable I/O space access */ 1574 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1); 1575 ia->ia_iobase = 0; 1576 ia->ia_iosize = 0; 1577 1578 ia->ia_aux = (void *) pa; 1579 return 1; 1580} 1581 1582static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 1583 1584struct cfdriver decd = { 1585 0, "de", tulip_pci_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t) 1586}; 1587 1588#endif /* __bsdi__ */ 1589 1590static void 1591tulip_pci_attach( 1592 TULIP_PCI_ATTACH_ARGS) 1593{ 1594#if defined(__FreeBSD__) 1595 tulip_softc_t *sc; 1596#endif 1597#if defined(__bsdi__) 1598 tulip_softc_t *sc = (tulip_softc_t *) self; 1599 struct isa_attach_args *ia = (struct isa_attach_args *) aux; 1600 pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux; 1601 int unit = sc->tulip_dev.dv_unit; 1602#endif 1603 int retval, idx, revinfo, id; 1604 vm_offset_t va_csrs, pa_csrs; 1605 tulip_desc_t *rxdescs, *txdescs; 1606 tulip_chipid_t chipid; 1607 1608#if defined(__FreeBSD__) 1609 if (unit >= NDE) { 1610 printf("de%d: not configured; kernel is built for only %d device%s.\n", 1611 unit, NDE, NDE == 1 ? "" : "s"); 1612 return; 1613 } 1614#endif 1615 1616#if defined(__FreeBSD__) 1617 revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF; 1618 id = pci_conf_read(config_id, PCI_CFID); 1619#endif 1620#if defined(__bsdi__) 1621 revinfo = pci_inl(pa, PCI_CFRV) & 0xFF; 1622 id = pci_inl(pa, PCI_CFID); 1623#endif 1624 1625 if (id == 0x00021011ul) chipid = TULIP_DC21040; 1626 else if (id == 0x00091011) chipid = TULIP_DC21140; 1627 else if (id == 0x00141011) chipid = TULIP_DC21041; 1628 else return; 1629 1630 if (chipid == TULIP_DC21040 && revinfo < 0x20) { 1631 printf("de%d: not configured; DC21040 pass 2.3 required (%d.%d found)\n", 1632 unit, revinfo >> 4, revinfo & 0x0f); 1633 return; 1634 } else if (chipid == TULIP_DC21140 && revinfo < 0x11) { 1635 printf("de%d: not configured; DC21140 pass 1.1 required (%d.%d found)\n", 1636 unit, revinfo >> 4, revinfo & 0x0f); 1637 return; 1638 } 1639 1640#if defined(__FreeBSD__) 1641 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); 1642 if (sc == NULL) 1643 return; 1644 bzero(sc, sizeof(*sc)); /* Zero out the softc*/ 1645#endif 1646 1647 rxdescs = (tulip_desc_t *) 1648 malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT); 1649 if (rxdescs == NULL) { 1650#if defined(__FreeBSD__) 1651 free((caddr_t) sc, M_DEVBUF); 1652#endif 1653 return; 1654 } 1655 1656 txdescs = (tulip_desc_t *) 1657 malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT); 1658 if (txdescs == NULL) { 1659 free((caddr_t) rxdescs, M_DEVBUF); 1660#if defined(__FreeBSD__) 1661 free((caddr_t) sc, M_DEVBUF); 1662#endif 1663 return; 1664 } 1665 1666 sc->tulip_chipid = chipid; 1667 sc->tulip_unit = unit; 1668 sc->tulip_name = "de"; 1669#if defined(__FreeBSD__) 1670 retval = pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs); 1671 if (!retval) { 1672 free((caddr_t) txdescs, M_DEVBUF); 1673 free((caddr_t) rxdescs, M_DEVBUF); 1674 free((caddr_t) sc, M_DEVBUF); 1675 return; 1676 } 1677 tulips[unit] = sc; 1678#endif 1679#if defined(__bsdi__) 1680 va_csrs = (vm_offset_t) mapphys((vm_offset_t) ia->ia_maddr, ia->ia_msize); 1681#endif 1682 sc->tulip_revinfo = revinfo; 1683 tulip_initcsrs(sc, (volatile tulip_uint32_t *) va_csrs, TULIP_PCI_CSRSIZE); 1684 tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS); 1685 tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS); 1686 if ((retval = tulip_read_macaddr(sc)) < 0) { 1687 printf("de%d: can't read ENET ROM (why=%d) (", sc->tulip_unit, retval); 1688 for (idx = 0; idx < 32; idx++) 1689 printf("%02x", sc->tulip_rombuf[idx]); 1690 printf("\n"); 1691 printf("%s%d: %s%s pass %d.%d Ethernet address %s\n", 1692 sc->tulip_name, sc->tulip_unit, 1693 (sc->tulip_boardsw != NULL ? sc->tulip_boardsw->bd_description : ""), 1694 tulip_chipdescs[sc->tulip_chipid], 1695 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F, 1696 "unknown"); 1697 } else { 1698 TULIP_RESET(sc); 1699 tulip_attach(sc); 1700#if defined(__FreeBSD__) 1701 pci_map_int (config_id, tulip_intr, (void*) sc, &net_imask); 1702#endif 1703#if defined(__bsdi__) 1704 isa_establish(&sc->tulip_id, &sc->tulip_dev); 1705 1706 sc->tulip_ih.ih_fun = tulip_intr; 1707 sc->tulip_ih.ih_arg = (void *)sc; 1708 intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET); 1709 1710 sc->tulip_ats.func = tulip_pci_shutdown; 1711 sc->tulip_ats.arg = (void *) sc; 1712 atshutdown(&sc->tulip_ats, ATSH_ADD); 1713#endif 1714 } 1715} 1716#endif /* NDE > 0 */ 1717