if_de.c revision 1.11
1/* $OpenBSD: if_de.c,v 1.11 1996/06/10 07:34:41 deraadt Exp $ */ 2/* $NetBSD: if_de.c,v 1.22.4.1 1996/06/03 20:32:07 cgd Exp $ */ 3 4/*- 5 * Copyright (c) 1994, 1995 Matt Thomas (matt@lkg.dec.com) 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software withough specific prior written permission 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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, DC21041, or DC21140 (mostly). 36 */ 37 38#if defined(__FreeBSD__) 39#include "de.h" 40#endif 41#if NDE > 0 || !defined(__FreeBSD__) 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/mbuf.h> 46#include <sys/protosw.h> 47#include <sys/socket.h> 48#include <sys/ioctl.h> 49#include <sys/errno.h> 50#include <sys/malloc.h> 51#include <sys/kernel.h> 52#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */ 53#if defined(__FreeBSD__) 54#include <sys/devconf.h> 55#include <machine/clock.h> 56#elif defined(__bsdi__) || defined(__NetBSD__) 57#include <sys/device.h> 58#endif 59 60#include <net/if.h> 61#include <net/if_types.h> 62#include <net/if_dl.h> 63#include <net/route.h> 64 65#include "bpfilter.h" 66#if NBPFILTER > 0 67#include <net/bpf.h> 68#include <net/bpfdesc.h> 69#endif 70 71#ifdef INET 72#include <netinet/in.h> 73#include <netinet/in_systm.h> 74#include <netinet/in_var.h> 75#include <netinet/ip.h> 76#include <netinet/if_ether.h> 77#endif 78 79#include <vm/vm.h> 80#include <vm/vm_kern.h> 81#include <vm/vm_param.h> 82 83#if defined(__FreeBSD__) 84#include <pci.h> 85#if NPCI > 0 86#include <pci/pcivar.h> 87#include <pci/dc21040.h> 88#endif 89#endif /* __FreeBSD__ */ 90 91#if defined(__bsdi__) 92#include <i386/pci/pci.h> 93#include <i386/pci/ic/dc21040.h> 94#include <i386/isa/isa.h> 95#include <i386/isa/icu.h> 96#include <i386/isa/dma.h> 97#include <i386/isa/isavar.h> 98#include <eisa.h> 99#if NEISA > 0 100#include <i386/eisa/eisa.h> 101#define TULIP_EISA 102#endif 103#endif /* __bsdi__ */ 104 105#if defined(__NetBSD__) 106#include <machine/bus.h> 107#include <machine/intr.h> 108 109#include <dev/pci/pcireg.h> 110#include <dev/pci/pcivar.h> 111#include <dev/ic/dc21040reg.h> 112#endif /* __NetBSD__ */ 113 114/* 115 * Intel CPUs should use I/O mapped access. 116 */ 117#if defined(__i386__) 118#define TULIP_IOMAPPED 119#endif 120 121/* 122 * This module supports 123 * the DEC DC21040 PCI Ethernet Controller. 124 * the DEC DC21041 PCI Ethernet Controller. 125 * the DEC DC21140 PCI Fast Ethernet Controller. 126 */ 127 128typedef struct { 129 tulip_desc_t *ri_first; 130 tulip_desc_t *ri_last; 131 tulip_desc_t *ri_nextin; 132 tulip_desc_t *ri_nextout; 133 int ri_max; 134 int ri_free; 135} tulip_ringinfo_t; 136 137#ifdef TULIP_IOMAPPED 138 139#define TULIP_EISA_CSRSIZE 16 140#define TULIP_PCI_CSRSIZE 8 141 142#ifndef __NetBSD__ 143typedef tulip_uint16_t tulip_csrptr_t; 144 145#define TULIP_READ_CSR(sc, csr) (inl((sc)->tulip_csrs.csr)) 146#define TULIP_WRITE_CSR(sc, csr, val) outl((sc)->tulip_csrs.csr, val) 147 148#define TULIP_READ_CSRBYTE(sc, csr) (inb((sc)->tulip_csrs.csr)) 149#define TULIP_WRITE_CSRBYTE(sc, csr, val) outb((sc)->tulip_csrs.csr, val) 150#else 151typedef bus_io_size_t tulip_csrptr_t; 152 153#define TULIP_READ_CSR(sc, csr) \ 154 bus_io_read_4((sc)->tulip_bc, (sc)->tulip_ioh, (sc)->tulip_csrs.csr) 155#define TULIP_WRITE_CSR(sc, csr, val) \ 156 bus_io_write_4((sc)->tulip_bc, (sc)->tulip_ioh, (sc)->tulip_csrs.csr, (val)) 157 158#define TULIP_READ_CSRBYTE(sc, csr) \ 159 bus_io_read_1((sc)->tulip_bc, (sc)->tulip_ioh, (sc)->tulip_csrs.csr) 160#define TULIP_WRITE_CSRBYTE(sc, csr, val) \ 161 bus_io_write_1((sc)->tulip_bc, (sc)->tulip_ioh, (sc)->tulip_csrs.csr, (val)) 162#endif 163 164#else /* TULIP_IOMAPPED */ 165 166#define TULIP_PCI_CSRSIZE 8 167 168#ifndef __NetBSD__ 169typedef volatile tulip_uint32_t *tulip_csrptr_t; 170 171/* 172 * macros to read and write CSRs. Note that the "0 +" in 173 * READ_CSR is to prevent the macro from being an lvalue 174 * and WRITE_CSR shouldn't be assigned from. 175 */ 176#define TULIP_READ_CSR(sc, csr) (0 + *(sc)->tulip_csrs.csr) 177#define TULIP_WRITE_CSR(sc, csr, val) \ 178 ((void)(*(sc)->tulip_csrs.csr = (val))) 179#else 180typedef bus_mem_size_t tulip_csrptr_t; 181 182#define TULIP_READ_CSR(sc, csr) \ 183 bus_mem_read_4((sc)->tulip_bc, (sc)->tulip_memh, (sc)->tulip_csrs.csr) 184#define TULIP_WRITE_CSR(sc, csr, val) \ 185 bus_mem_write_4((sc)->tulip_bc, (sc)->tulip_memh, (sc)->tulip_csrs.csr, \ 186 (val)) 187#endif 188#endif /* TULIP_IOMAPPED */ 189 190typedef struct { 191 tulip_csrptr_t csr_busmode; /* CSR0 */ 192 tulip_csrptr_t csr_txpoll; /* CSR1 */ 193 tulip_csrptr_t csr_rxpoll; /* CSR2 */ 194 tulip_csrptr_t csr_rxlist; /* CSR3 */ 195 tulip_csrptr_t csr_txlist; /* CSR4 */ 196 tulip_csrptr_t csr_status; /* CSR5 */ 197 tulip_csrptr_t csr_command; /* CSR6 */ 198 tulip_csrptr_t csr_intr; /* CSR7 */ 199 tulip_csrptr_t csr_missed_frame; /* CSR8 */ 200 201 /* DC21040 specific registers */ 202 203 tulip_csrptr_t csr_enetrom; /* CSR9 */ 204 tulip_csrptr_t csr_reserved; /* CSR10 */ 205 tulip_csrptr_t csr_full_duplex; /* CSR11 */ 206 207 /* DC21040/DC21041 common registers */ 208 209 tulip_csrptr_t csr_sia_status; /* CSR12 */ 210 tulip_csrptr_t csr_sia_connectivity; /* CSR13 */ 211 tulip_csrptr_t csr_sia_tx_rx; /* CSR14 */ 212 tulip_csrptr_t csr_sia_general; /* CSR15 */ 213 214 /* DC21140/DC21041 common registers */ 215 216 tulip_csrptr_t csr_srom_mii; /* CSR9 */ 217 tulip_csrptr_t csr_gp_timer; /* CSR11 */ 218 219 /* DC21140 specific registers */ 220 221 tulip_csrptr_t csr_gp; /* CSR12 */ 222 tulip_csrptr_t csr_watchdog; /* CSR15 */ 223 224 /* DC21041 specific registers */ 225 226 tulip_csrptr_t csr_bootrom; /* CSR10 */ 227} tulip_regfile_t; 228 229/* 230 * The DC21040 has a stupid restriction in that the receive 231 * buffers must be longword aligned. But since Ethernet 232 * headers are not a multiple of longwords in size this forces 233 * the data to non-longword aligned. Since IP requires the 234 * data to be longword aligned, we need to copy it after it has 235 * been DMA'ed in our memory. 236 * 237 * Since we have to copy it anyways, we might as well as allocate 238 * dedicated receive space for the input. This allows to use a 239 * small receive buffer size and more ring entries to be able to 240 * better keep with a flood of tiny Ethernet packets. 241 * 242 * The receive space MUST ALWAYS be a multiple of the page size. 243 * And the number of receive descriptors multiplied by the size 244 * of the receive buffers must equal the recevive space. This 245 * is so that we can manipulate the page tables so that even if a 246 * packet wraps around the end of the receive space, we can 247 * treat it as virtually contiguous. 248 * 249 * The above used to be true (the stupid restriction is still true) 250 * but we gone to directly DMA'ing into MBUFs because with 100Mb 251 * cards the copying is just too much of a hit. 252 */ 253#if defined(__alpha__) 254#define TULIP_COPY_RXDATA 1 255#endif 256 257#define TULIP_RXDESCS 16 258#define TULIP_TXDESCS 128 259#define TULIP_RXQ_TARGET 16 260#define TULIP_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16) 261 262typedef enum { 263 TULIP_DC21040_GENERIC, 264 TULIP_DC21040_ZX314_MASTER, 265 TULIP_DC21040_ZX314_SLAVE, 266 TULIP_DC21140_DEC_EB, 267 TULIP_DC21140_DEC_DE500, 268 TULIP_DC21140_COGENT_EM100, 269 TULIP_DC21140_ZNYX_ZX34X, 270 TULIP_DC21041_GENERIC, 271 TULIP_DC21041_DE450 272} tulip_board_t; 273 274typedef struct _tulip_softc_t tulip_softc_t; 275 276typedef struct { 277 tulip_board_t bd_type; 278 const char *bd_description; 279 int (*bd_media_probe)(tulip_softc_t *sc); 280 void (*bd_media_select)(tulip_softc_t *sc); 281} tulip_boardsw_t; 282 283typedef enum { 284 TULIP_DC21040, TULIP_DC21140, 285 TULIP_DC21041, TULIP_DE425, 286 TULIP_CHIPID_UNKNOWN 287} tulip_chipid_t; 288 289typedef enum { 290 TULIP_PROBE_INACTIVE, TULIP_PROBE_10BASET, TULIP_PROBE_AUI, 291 TULIP_PROBE_BNC 292} tulip_probe_state_t; 293 294typedef enum { 295 TULIP_MEDIA_UNKNOWN, TULIP_MEDIA_10BASET, 296 TULIP_MEDIA_BNC, TULIP_MEDIA_AUI, 297 TULIP_MEDIA_BNCAUI, TULIP_MEDIA_100BASET 298} tulip_media_t; 299 300struct _tulip_softc_t { 301#if defined(__bsdi__) 302 struct device tulip_dev; /* base device */ 303 struct isadev tulip_id; /* ISA device */ 304 struct intrhand tulip_ih; /* intrrupt vectoring */ 305 struct atshutdown tulip_ats; /* shutdown hook */ 306#endif 307#if defined(__NetBSD__) 308 struct device tulip_dev; /* base device */ 309 void *tulip_ih; /* intrrupt vectoring */ 310 void *tulip_ats; /* shutdown hook */ 311 bus_chipset_tag_t tulip_bc; 312 pci_chipset_tag_t tulip_pc; 313#ifdef TULIP_IOMAPPED 314 bus_io_handle_t tulip_ioh; /* I/O region handle */ 315#else 316 bus_io_handle_t tulip_memh; /* memory region handle */ 317#endif 318#endif 319 char tulip_xname[IFNAMSIZ]; /* name + unit number */ 320 struct arpcom tulip_ac; 321 tulip_regfile_t tulip_csrs; 322 unsigned tulip_flags; 323#define TULIP_WANTSETUP 0x0001 324#define TULIP_WANTHASH 0x0002 325#define TULIP_DOINGSETUP 0x0004 326#define TULIP_ALTPHYS 0x0008 /* use AUI */ 327#define TULIP_TXPROBE_ACTIVE 0x0010 328#define TULIP_TXPROBE_OK 0x0020 329#define TULIP_INRESET 0x0040 330#define TULIP_WANTRXACT 0x0080 331#define TULIP_SLAVEDROM 0x0100 332#define TULIP_ROMOK 0x0200 333 unsigned char tulip_rombuf[128]; 334 tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)]; 335 tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)]; 336 tulip_uint32_t tulip_intrmask; 337 tulip_uint32_t tulip_cmdmode; 338 tulip_uint32_t tulip_revinfo; 339 tulip_uint32_t tulip_gpticks; 340 /* tulip_uint32_t tulip_bus; XXX */ 341 tulip_media_t tulip_media; 342 tulip_probe_state_t tulip_probe_state; 343 tulip_chipid_t tulip_chipid; 344 const tulip_boardsw_t *tulip_boardsw; 345 tulip_softc_t *tulip_slaves; 346 struct ifqueue tulip_txq; 347 struct ifqueue tulip_rxq; 348 tulip_ringinfo_t tulip_rxinfo; 349 tulip_ringinfo_t tulip_txinfo; 350}; 351 352#ifndef IFF_ALTPHYS 353#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */ 354#endif 355static const char *tulip_chipdescs[] = { 356 "DC21040 [10Mb/s]", 357 "DC21140 [10-100Mb/s]", 358 "DC21041 [10Mb/s]", 359#if defined(TULIP_EISA) 360 "DE425 [10Mb/s]" 361#endif 362}; 363 364#if defined(__FreeBSD__) 365typedef void ifnet_ret_t; 366typedef int ioctl_cmd_t; 367tulip_softc_t *tulips[NDE]; 368#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit]) 369#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) 370#define TULIP_BURSTSIZE(unit) pci_max_burst_len 371#endif 372#if defined(__bsdi__) 373typedef int ifnet_ret_t; 374typedef int ioctl_cmd_t; 375extern struct cfdriver decd; 376#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) 377#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) 378#define TULIP_BURSTSIZE(unit) log2_burst_size 379#endif 380#if defined(__NetBSD__) 381typedef void ifnet_ret_t; 382typedef u_long ioctl_cmd_t; 383extern struct cfattach de_ca; 384extern struct cfdriver de_cd; 385#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) de_cd.cd_devs[unit]) 386#define TULIP_IFP_TO_SOFTC(ifp) ((tulip_softc_t *)((ifp)->if_softc)) 387#endif 388 389#ifndef TULIP_BURSTSIZE 390#define TULIP_BURSTSIZE(unit) 3 391#endif 392 393#define tulip_if tulip_ac.ac_if 394#ifdef __NetBSD__ 395#define tulip_unit tulip_dev.dv_unit 396#define tulip_name tulip_dev.dv_cfdata->cf_driver->cd_name 397#else 398#define tulip_unit tulip_ac.ac_if.if_unit 399#define tulip_name tulip_ac.ac_if.if_name 400#endif 401#define tulip_bpf tulip_ac.ac_if.if_bpf 402#define tulip_hwaddr tulip_ac.ac_enaddr 403 404#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 405#define TULIP_CHECK_RXCRC 0 406#define TULIP_MAX_TXSEG 30 407 408#define TULIP_ADDREQUAL(a1, a2) \ 409 (((u_short *)a1)[0] == ((u_short *)a2)[0] \ 410 && ((u_short *)a1)[1] == ((u_short *)a2)[1] \ 411 && ((u_short *)a1)[2] == ((u_short *)a2)[2]) 412#define TULIP_ADDRBRDCST(a1) \ 413 (((u_short *)a1)[0] == 0xFFFFU \ 414 && ((u_short *)a1)[1] == 0xFFFFU \ 415 && ((u_short *)a1)[2] == 0xFFFFU) 416 417static ifnet_ret_t tulip_start(struct ifnet *ifp); 418static void tulip_rx_intr(tulip_softc_t *sc); 419static void tulip_addr_filter(tulip_softc_t *sc); 420 421#if defined(__NetBSD__) && defined(__alpha__) 422/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */ 423#define vtophys(va) __alpha_bus_XXX_dmamap(sc->tulip_bc, (void *)(va)) 424 425#endif 426 427static int 428tulip_dc21040_media_probe( 429 tulip_softc_t * const sc) 430{ 431 int cnt; 432 433 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0); 434 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET); 435 for (cnt = 0; cnt < 2400; cnt++) { 436 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0) 437 break; 438 DELAY(1000); 439 } 440 return (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) != 0; 441} 442 443static void 444tulip_dc21040_media_select( 445 tulip_softc_t * const sc) 446{ 447 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 448 |TULIP_CMD_BACKOFFCTR; 449 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 450 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 451 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 452 printf("%s: enabling Thinwire/AUI port\n", sc->tulip_xname); 453 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_AUI); 454 sc->tulip_flags |= TULIP_ALTPHYS; 455 } else { 456 if (sc->tulip_flags & TULIP_ALTPHYS) 457 printf("%s: enabling 10baseT/UTP port\n", sc->tulip_xname); 458 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET); 459 sc->tulip_flags &= ~TULIP_ALTPHYS; 460 sc->tulip_media = TULIP_MEDIA_10BASET; 461 } 462} 463 464static const tulip_boardsw_t tulip_dc21040_boardsw = { 465 TULIP_DC21040_GENERIC, 466 "", 467 tulip_dc21040_media_probe, 468 tulip_dc21040_media_select 469}; 470 471static int 472tulip_zx314_media_probe( 473 tulip_softc_t * const sc) 474{ 475 TULIP_WRITE_CSR(sc, csr_sia_connectivity, 0); 476 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET); 477 return 0; 478} 479 480static void 481tulip_zx314_media_select( 482 tulip_softc_t * const sc) 483{ 484 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 485 |TULIP_CMD_BACKOFFCTR; 486 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 487 if (sc->tulip_flags & TULIP_ALTPHYS) 488 printf("%s: enabling 10baseT/UTP port\n", sc->tulip_xname); 489 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_10BASET); 490 sc->tulip_flags &= ~TULIP_ALTPHYS; 491 sc->tulip_media = TULIP_MEDIA_10BASET; 492} 493 494 495static const tulip_boardsw_t tulip_dc21040_zx314_master_boardsw = { 496 TULIP_DC21040_ZX314_MASTER, 497 "ZNYX ZX314 ", 498 tulip_zx314_media_probe, 499 tulip_zx314_media_select 500}; 501 502static const tulip_boardsw_t tulip_dc21040_zx314_slave_boardsw = { 503 TULIP_DC21040_ZX314_SLAVE, 504 "ZNYX ZX314 ", 505 tulip_zx314_media_probe, 506 tulip_zx314_media_select 507}; 508 509static int 510tulip_dc21140_evalboard_media_probe( 511 tulip_softc_t * const sc) 512{ 513 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS); 514 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT); 515 TULIP_WRITE_CSR(sc, csr_command, 516 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT | 517 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 518 TULIP_WRITE_CSR(sc, csr_command, 519 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 520 DELAY(1000000); 521 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_EB_OK100) != 0; 522} 523 524static void 525tulip_dc21140_evalboard_media_select( 526 tulip_softc_t * const sc) 527{ 528 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE 529 |TULIP_CMD_BACKOFFCTR; 530 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_PINS); 531 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EB_INIT); 532 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 533 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 534 printf("%s: enabling 100baseTX UTP port\n", sc->tulip_xname); 535 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 536 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 537 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 538 sc->tulip_flags |= TULIP_ALTPHYS; 539 sc->tulip_media = TULIP_MEDIA_100BASET; 540 } else { 541 if (sc->tulip_flags & TULIP_ALTPHYS) 542 printf("%s: enabling 10baseT UTP port\n", sc->tulip_xname); 543 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 544 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 545 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 546 sc->tulip_flags &= ~TULIP_ALTPHYS; 547 sc->tulip_media = TULIP_MEDIA_10BASET; 548 } 549#ifdef BIG_PACKET 550 if (sc->tulip_if.if_mtu > ETHERMTU) { 551 TULIP_WRITE_CSR(sc, csr_watchdog, TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE); 552 } 553#endif 554} 555 556static const tulip_boardsw_t tulip_dc21140_eb_boardsw = { 557 TULIP_DC21140_DEC_EB, 558 "", 559 tulip_dc21140_evalboard_media_probe, 560 tulip_dc21140_evalboard_media_select 561}; 562 563static int 564tulip_dc21140_cogent_em100_media_probe( 565 tulip_softc_t * const sc) 566{ 567 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS); 568 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT); 569 TULIP_WRITE_CSR(sc, csr_command, 570 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT | 571 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 572 TULIP_WRITE_CSR(sc, csr_command, 573 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 574 return 1; 575} 576 577static void 578tulip_dc21140_cogent_em100_media_select( 579 tulip_softc_t * const sc) 580{ 581 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE 582 |TULIP_CMD_BACKOFFCTR; 583 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_PINS); 584 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_EM100_INIT); 585 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 586 printf("%s: enabling 100baseTX UTP port\n", sc->tulip_xname); 587 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 588 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 589 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 590 sc->tulip_flags |= TULIP_ALTPHYS; 591 sc->tulip_media = TULIP_MEDIA_100BASET; 592#ifdef BIG_PACKET 593 if (sc->tulip_if.if_mtu > ETHERMTU) { 594 TULIP_WRITE_CSR(sc, csr_watchdog, TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE); 595 } 596#endif 597} 598 599static const tulip_boardsw_t tulip_dc21140_cogent_em100_boardsw = { 600 TULIP_DC21140_COGENT_EM100, 601 "Cogent EM100 ", 602 tulip_dc21140_cogent_em100_media_probe, 603 tulip_dc21140_cogent_em100_media_select 604}; 605 606 607static int 608tulip_dc21140_znyx_zx34x_media_probe( 609 tulip_softc_t * const sc) 610{ 611 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS); 612 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT); 613 TULIP_WRITE_CSR(sc, csr_command, 614 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT | 615 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 616 TULIP_WRITE_CSR(sc, csr_command, 617 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 618 DELAY(1000000); 619 620 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_ZX34X_OK10); 621} 622 623static void 624tulip_dc21140_znyx_zx34x_media_select( 625 tulip_softc_t * const sc) 626{ 627 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE 628 |TULIP_CMD_BACKOFFCTR; 629 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_PINS); 630 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_ZX34X_INIT); 631 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 632 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 633 printf("%s: enabling 100baseTX UTP port\n", sc->tulip_xname); 634 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 635 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 636 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 637 sc->tulip_flags |= TULIP_ALTPHYS; 638 sc->tulip_media = TULIP_MEDIA_100BASET; 639 } else { 640 if (sc->tulip_flags & TULIP_ALTPHYS) 641 printf("%s: enabling 10baseT UTP port\n", sc->tulip_xname); 642 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 643 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 644 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 645 sc->tulip_flags &= ~TULIP_ALTPHYS; 646 sc->tulip_media = TULIP_MEDIA_10BASET; 647 } 648#ifdef BIG_PACKET 649 if (sc->tulip_if.if_mtu > ETHERMTU) { 650 TULIP_WRITE_CSR(sc, csr_watchdog, TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE); 651 } 652#endif 653} 654 655static const tulip_boardsw_t tulip_dc21140_znyx_zx34x_boardsw = { 656 TULIP_DC21140_ZNYX_ZX34X, 657 "ZNYX ZX34X ", 658 tulip_dc21140_znyx_zx34x_media_probe, 659 tulip_dc21140_znyx_zx34x_media_select 660}; 661 662static int 663tulip_dc21140_de500_media_probe( 664 tulip_softc_t * const sc) 665{ 666 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS); 667 DELAY(1000); 668 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX); 669 if ((TULIP_READ_CSR(sc, csr_gp) & 670 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) != 671 (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) 672 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) == 0; 673 TULIP_WRITE_CSR(sc, csr_gp, 674 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100); 675 TULIP_WRITE_CSR(sc, csr_command, 676 TULIP_READ_CSR(sc, csr_command) | TULIP_CMD_PORTSELECT | 677 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 678 TULIP_WRITE_CSR(sc, csr_command, 679 TULIP_READ_CSR(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 680 DELAY(1000000); 681 return (TULIP_READ_CSR(sc, csr_gp) & TULIP_GP_DE500_NOTOK_100) == 0; 682} 683 684static void 685tulip_dc21140_de500_media_select( 686 tulip_softc_t * const sc) 687{ 688 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE 689 |TULIP_CMD_BACKOFFCTR; 690 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_PINS); 691 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 692 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 693 printf("%s: enabling 100baseTX UTP port\n", sc->tulip_xname); 694 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 695 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 696 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 697 sc->tulip_flags |= TULIP_ALTPHYS; 698 sc->tulip_media = TULIP_MEDIA_100BASET; 699 TULIP_WRITE_CSR(sc, csr_gp, 700 TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100); 701 } else { 702 if (sc->tulip_flags & TULIP_ALTPHYS) 703 printf("%s: enabling 10baseT UTP port\n", sc->tulip_xname); 704 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 705 |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 706 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 707 sc->tulip_flags &= ~TULIP_ALTPHYS; 708 sc->tulip_media = TULIP_MEDIA_10BASET; 709 TULIP_WRITE_CSR(sc, csr_gp, TULIP_GP_DE500_HALFDUPLEX); 710 } 711#ifdef BIG_PACKET 712 if (sc->tulip_if.if_mtu > ETHERMTU) { 713 TULIP_WRITE_CSR(sc, csr_watchdog, TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE); 714 } 715#endif 716} 717 718static const tulip_boardsw_t tulip_dc21140_de500_boardsw = { 719 TULIP_DC21140_DEC_DE500, "Digital DE500 ", 720 tulip_dc21140_de500_media_probe, 721 tulip_dc21140_de500_media_select 722}; 723 724static int 725tulip_dc21041_media_probe( 726 tulip_softc_t * const sc) 727{ 728 return 0; 729} 730 731#ifdef BIG_PACKET 732#define TULIP_DC21041_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0) 733#else 734#define TULIP_DC21041_SIAGEN_WATCHDOG 0 735#endif 736 737static void 738tulip_dc21041_media_select( 739 tulip_softc_t * const sc) 740{ 741 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT 742 /* |TULIP_CMD_FULLDUPLEX */ |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR; 743 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_GPTIMEOUT 744 |TULIP_STS_ABNRMLINTR|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 745 if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 746 if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) { 747 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 748 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE); 749 sc->tulip_flags |= TULIP_ALTPHYS|TULIP_WANTRXACT; 750 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 751 } 752 } else { 753 if (sc->tulip_flags & TULIP_ALTPHYS) { 754 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 755 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE|TULIP_ALTPHYS); 756 sc->tulip_flags |= TULIP_WANTRXACT; 757 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 758 } 759 } 760 761 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) { 762 if (sc->tulip_media == TULIP_MEDIA_10BASET) { 763 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 764 } else if (sc->tulip_media == TULIP_MEDIA_BNC) { 765 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT; 766 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 767 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC); 768 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC); 769 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC|TULIP_DC21041_SIAGEN_WATCHDOG); 770 return; 771 } else if (sc->tulip_media == TULIP_MEDIA_AUI) { 772 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT; 773 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 774 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI); 775 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI); 776 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI|TULIP_DC21041_SIAGEN_WATCHDOG); 777 return; 778 } 779 780 switch (sc->tulip_probe_state) { 781 case TULIP_PROBE_INACTIVE: { 782 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode); 783 sc->tulip_if.if_flags |= IFF_OACTIVE; 784 sc->tulip_gpticks = 200; 785 sc->tulip_probe_state = TULIP_PROBE_10BASET; 786 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 787 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET); 788 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET); 789 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET|TULIP_DC21041_SIAGEN_WATCHDOG); 790 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */ 791 break; 792 } 793 case TULIP_PROBE_10BASET: { 794 if (--sc->tulip_gpticks > 0) { 795 if ((TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) == 0) { 796 TULIP_WRITE_CSR(sc, csr_gp_timer, 12000000 / 204800); /* 120 ms */ 797 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 798 break; 799 } 800 } 801 sc->tulip_gpticks = 4; 802 if (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_OTHERRXACTIVITY) { 803 sc->tulip_probe_state = TULIP_PROBE_BNC; 804 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 805 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC); 806 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC); 807 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC|TULIP_DC21041_SIAGEN_WATCHDOG); 808 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */ 809 } else { 810 sc->tulip_probe_state = TULIP_PROBE_AUI; 811 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 812 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI); 813 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI); 814 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI|TULIP_DC21041_SIAGEN_WATCHDOG); 815 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */ 816 } 817 break; 818 } 819 case TULIP_PROBE_BNC: 820 case TULIP_PROBE_AUI: { 821 if (sc->tulip_flags & TULIP_TXPROBE_OK) { 822 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT; 823 sc->tulip_flags &= ~(TULIP_TXPROBE_OK|TULIP_TXPROBE_ACTIVE); 824 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */ 825 if ((sc->tulip_probe_state == TULIP_PROBE_AUI 826 && sc->tulip_media != TULIP_MEDIA_AUI) 827 || (sc->tulip_probe_state == TULIP_PROBE_BNC 828 && sc->tulip_media != TULIP_MEDIA_AUI)) { 829 printf("%s: enabling %s port\n", sc->tulip_xname, 830 sc->tulip_probe_state == TULIP_PROBE_BNC 831 ? "Thinwire/BNC" : "AUI"); 832 if (sc->tulip_probe_state == TULIP_PROBE_AUI) 833 sc->tulip_media = TULIP_MEDIA_AUI; 834 else if (sc->tulip_probe_state == TULIP_PROBE_BNC) 835 sc->tulip_media = TULIP_MEDIA_BNC; 836 } 837 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 838 break; 839 } 840 if ((sc->tulip_flags & TULIP_WANTRXACT) == 0 841 || (TULIP_READ_CSR(sc, csr_sia_status) & TULIP_SIASTS_RXACTIVITY)) { 842 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) { 843 struct mbuf *m; 844 /* 845 * Before we are sure this is the right media we need 846 * to send a small packet to make sure there's carrier. 847 * Strangely, BNC and AUI will 'see" receive data if 848 * either is connected so the transmit is the only way 849 * to verify the connectivity. 850 */ 851 MGETHDR(m, M_DONTWAIT, MT_DATA); 852 if (m == NULL) { 853 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */ 854 break; 855 } 856 /* 857 * Construct a LLC TEST message which will point to ourselves. 858 */ 859 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_dhost, 6); 860 bcopy(sc->tulip_hwaddr, mtod(m, struct ether_header *)->ether_shost, 6); 861 mtod(m, struct ether_header *)->ether_type = htons(3); 862 mtod(m, unsigned char *)[14] = 0; 863 mtod(m, unsigned char *)[15] = 0; 864 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */ 865 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; 866 /* 867 * send it! 868 */ 869 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; 870 sc->tulip_flags &= ~TULIP_TXPROBE_OK; 871 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 872 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode); 873 IF_PREPEND(&sc->tulip_if.if_snd, m); 874 tulip_start(&sc->tulip_if); 875 break; 876 } 877 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 878 } 879 /* 880 * Take 2 passes through before deciding to not 881 * wait for receive activity. Then take another 882 * two passes before spitting out a warning. 883 */ 884 if (sc->tulip_gpticks > 0 && --sc->tulip_gpticks == 0) { 885 if (sc->tulip_flags & TULIP_WANTRXACT) { 886 sc->tulip_flags &= ~TULIP_WANTRXACT; 887 sc->tulip_gpticks = 4; 888 } else { 889 printf("%s: autosense failed: cable problem?\n", 890 sc->tulip_xname); 891 } 892 } 893 /* 894 * Since this media failed to probe, try the other one. 895 */ 896 if (sc->tulip_probe_state == TULIP_PROBE_AUI) { 897 sc->tulip_probe_state = TULIP_PROBE_BNC; 898 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 899 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_BNC); 900 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_BNC); 901 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_BNC|TULIP_DC21041_SIAGEN_WATCHDOG); 902 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */ 903 } else { 904 sc->tulip_probe_state = TULIP_PROBE_AUI; 905 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 906 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_AUI); 907 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_AUI); 908 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_AUI|TULIP_DC21041_SIAGEN_WATCHDOG); 909 TULIP_WRITE_CSR(sc, csr_gp_timer, 100000000 / 204800); /* 100 ms */ 910 } 911 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 912 break; 913 } 914 } 915 } else { 916 /* 917 * If the link has passed LinkPass, 10baseT is the 918 * proper media to use. 919 */ 920 if (sc->tulip_media != TULIP_MEDIA_10BASET) 921 printf("%s: enabling 10baseT/UTP port\n", sc->tulip_xname); 922 if (sc->tulip_media != TULIP_MEDIA_10BASET 923 || (sc->tulip_flags & TULIP_INRESET)) { 924 sc->tulip_media = TULIP_MEDIA_10BASET; 925 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 926 TULIP_WRITE_CSR(sc, csr_sia_connectivity, TULIP_DC21041_SIACONN_10BASET); 927 TULIP_WRITE_CSR(sc, csr_sia_tx_rx, TULIP_DC21041_SIATXRX_10BASET); 928 TULIP_WRITE_CSR(sc, csr_sia_general, TULIP_DC21041_SIAGEN_10BASET|TULIP_DC21041_SIAGEN_WATCHDOG); 929 } 930 TULIP_WRITE_CSR(sc, csr_gp_timer, 0); /* disable */ 931 sc->tulip_gpticks = 1; 932 sc->tulip_probe_state = TULIP_PROBE_10BASET; 933 sc->tulip_intrmask &= ~TULIP_STS_GPTIMEOUT; 934 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 935 } 936 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 937} 938 939static const tulip_boardsw_t tulip_dc21041_boardsw = { 940 TULIP_DC21041_GENERIC, 941 "", 942 tulip_dc21041_media_probe, 943 tulip_dc21041_media_select 944}; 945 946static const tulip_boardsw_t tulip_dc21041_de450_boardsw = { 947 TULIP_DC21041_DE450, 948 "Digital DE450 ", 949 tulip_dc21041_media_probe, 950 tulip_dc21041_media_select 951}; 952 953static void 954tulip_reset( 955 tulip_softc_t * const sc) 956{ 957 tulip_ringinfo_t *ri; 958 tulip_desc_t *di; 959 960 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 961 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 962 33MHz that comes to two microseconds but wait a 963 bit longer anyways) */ 964 965 sc->tulip_flags |= TULIP_INRESET; 966 sc->tulip_intrmask = 0; 967 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 968 969 TULIP_WRITE_CSR(sc, csr_txlist, vtophys(&sc->tulip_txinfo.ri_first[0])); 970 TULIP_WRITE_CSR(sc, csr_rxlist, vtophys(&sc->tulip_rxinfo.ri_first[0])); 971 TULIP_WRITE_CSR(sc, csr_busmode, 972 (1 << (TULIP_BURSTSIZE(sc->tulip_unit) + 8)) 973 |TULIP_BUSMODE_CACHE_ALIGN8 974 |(BYTE_ORDER != LITTLE_ENDIAN ? TULIP_BUSMODE_BIGENDIAN : 0)); 975 976 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 977 /* 978 * Free all the mbufs that were on the transmit ring. 979 */ 980 for (;;) { 981 struct mbuf *m; 982 IF_DEQUEUE(&sc->tulip_txq, m); 983 if (m == NULL) 984 break; 985 m_freem(m); 986 } 987 988 ri = &sc->tulip_txinfo; 989 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 990 ri->ri_free = ri->ri_max; 991 for (di = ri->ri_first; di < ri->ri_last; di++) 992 di->d_status = 0; 993 994 /* 995 * We need to collect all the mbufs were on the 996 * receive ring before we reinit it either to put 997 * them back on or to know if we have to allocate 998 * more. 999 */ 1000 ri = &sc->tulip_rxinfo; 1001 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 1002 ri->ri_free = ri->ri_max; 1003 for (di = ri->ri_first; di < ri->ri_last; di++) { 1004 di->d_status = 0; 1005 di->d_length1 = 0; di->d_addr1 = 0; 1006 di->d_length2 = 0; di->d_addr2 = 0; 1007 } 1008 for (;;) { 1009 struct mbuf *m; 1010 IF_DEQUEUE(&sc->tulip_rxq, m); 1011 if (m == NULL) 1012 break; 1013 m_freem(m); 1014 } 1015 1016 (*sc->tulip_boardsw->bd_media_select)(sc); 1017 1018 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 1019 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 1020 |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED; 1021 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET); 1022 tulip_addr_filter(sc); 1023} 1024 1025static void 1026tulip_init( 1027 tulip_softc_t * const sc) 1028{ 1029 if (sc->tulip_if.if_flags & IFF_UP) { 1030 sc->tulip_if.if_flags |= IFF_RUNNING; 1031 if (sc->tulip_if.if_flags & IFF_PROMISC) { 1032 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 1033 } else { 1034 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 1035 if (sc->tulip_if.if_flags & IFF_ALLMULTI) { 1036 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 1037 } else { 1038 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 1039 } 1040 } 1041 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 1042 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 1043 tulip_rx_intr(sc); 1044 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 1045 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 1046 } else { 1047 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 1048 tulip_start(&sc->tulip_if); 1049 } 1050 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 1051 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode); 1052 } else { 1053 tulip_reset(sc); 1054 sc->tulip_if.if_flags &= ~IFF_RUNNING; 1055 } 1056} 1057 1058static void 1059tulip_rx_intr( 1060 tulip_softc_t * const sc) 1061{ 1062 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; 1063 struct ifnet * const ifp = &sc->tulip_if; 1064 1065 for (;;) { 1066 struct ether_header eh; 1067 tulip_desc_t *eop = ri->ri_nextin; 1068 int total_len = 0, last_offset = 0; 1069 struct mbuf *ms = NULL, *me = NULL; 1070 int accept = 0; 1071 1072 if (sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) 1073 goto queue_mbuf; 1074 1075 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 1076 return; 1077 1078 /* 1079 * It is possible (though improbable unless the BIG_PACKET support 1080 * is enabled) for a received packet to cross more than one receive 1081 * descriptor. 1082 */ 1083 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { 1084 if (++eop == ri->ri_last) 1085 eop = ri->ri_first; 1086 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 1087 return; 1088 total_len++; 1089 } 1090 1091 /* 1092 * Dequeue the first buffer for the start of the packet. Hopefully this 1093 * will be the only one we need to dequeue. However, if the packet consumed 1094 * multiple descriptors, then we need to dequeue those buffers and chain to 1095 * the starting mbuf. All buffers but the last buffer have the same length 1096 * so we can set that now. (we add to last_offset instead of multiplying 1097 * since we normally won't go into the loop and thereby saving a ourselves 1098 * from doing a multiplication by 0 in the normal case). 1099 */ 1100 IF_DEQUEUE(&sc->tulip_rxq, ms); 1101 for (me = ms; total_len > 0; total_len--) { 1102 me->m_len = TULIP_RX_BUFLEN; 1103 last_offset += TULIP_RX_BUFLEN; 1104 IF_DEQUEUE(&sc->tulip_rxq, me->m_next); 1105 me = me->m_next; 1106 } 1107 1108 /* 1109 * Now get the size of received packet. 1110 */ 1111 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; 1112 if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0 1113#ifdef BIG_PACKET 1114 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) && 1115 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT| 1116 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC| 1117 TULIP_DSTS_RxOVERFLOW))) 1118#endif 1119 ) { 1120 me->m_len = total_len - last_offset; 1121 eh = *mtod(ms, struct ether_header *); 1122#if NBPFILTER > 0 1123 if (sc->tulip_bpf != NULL) 1124 if (me == ms) 1125 bpf_tap(sc->tulip_bpf, mtod(ms, caddr_t), total_len); 1126 else 1127 bpf_mtap(sc->tulip_bpf, ms); 1128#endif 1129 if ((sc->tulip_if.if_flags & IFF_PROMISC) 1130 && (eh.ether_dhost[0] & 1) == 0 1131 && !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr)) 1132 goto next; 1133 accept = 1; 1134 total_len -= sizeof(struct ether_header); 1135 } else { 1136 ifp->if_ierrors++; 1137 } 1138 next: 1139 ifp->if_ipackets++; 1140 if (++eop == ri->ri_last) 1141 eop = ri->ri_first; 1142 ri->ri_nextin = eop; 1143 queue_mbuf: 1144 /* 1145 * Either we are priming the TULIP with mbufs (m == NULL) 1146 * or we are about to accept an mbuf for the upper layers 1147 * so we need to allocate an mbuf to replace it. If we 1148 * can't replace, then count it as an input error and reuse 1149 * the mbuf. *** Note that if this packet crossed multiple 1150 * descriptors we don't even try to reallocate all the mbufs 1151 * here. Instead we rely on the test of the beginning of 1152 * the loop to refill for the extra consumed mbufs. 1153 */ 1154 if (accept || ms == NULL) { 1155 struct mbuf *m0; 1156 MGETHDR(m0, M_DONTWAIT, MT_DATA); 1157 if (m0 != NULL) { 1158#if defined(TULIP_COPY_RXDATA) 1159 if (!accept || total_len >= MHLEN) { 1160#endif 1161 MCLGET(m0, M_DONTWAIT); 1162 if ((m0->m_flags & M_EXT) == 0) { 1163 m_freem(m0); 1164 m0 = NULL; 1165 } 1166#if defined(TULIP_COPY_RXDATA) 1167 } 1168#endif 1169 } 1170 if (accept) { 1171 if (m0 != NULL) { 1172#if defined(__bsdi__) 1173 eh.ether_type = ntohs(eh.ether_type); 1174#endif 1175#if !defined(TULIP_COPY_RXDATA) 1176 ms->m_data += sizeof(struct ether_header); 1177 ms->m_len -= sizeof(struct ether_header); 1178 ms->m_pkthdr.len = total_len; 1179 ms->m_pkthdr.rcvif = ifp; 1180 ether_input(ifp, &eh, ms); 1181 ms = m0; 1182#else 1183#ifdef BIG_PACKET 1184#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA 1185#endif 1186 if (ms == me) 1187/*XXX?*/ bcopy(mtod(ms, caddr_t) + sizeof(struct ether_header), 1188 mtod(m0, caddr_t), total_len); 1189 else 1190/*XXX?*/ m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); 1191 m0->m_len = m0->m_pkthdr.len = total_len; 1192 m0->m_pkthdr.rcvif = ifp; 1193 ether_input(ifp, &eh, m0); 1194#endif 1195 } else { 1196 ifp->if_ierrors++; 1197 } 1198 } else { 1199 ms = m0; 1200 } 1201 } 1202 if (ms == NULL) 1203 return; 1204 /* 1205 * Now give the buffer(s) to the TULIP and save in our 1206 * receive queue. 1207 */ 1208 do { 1209 ri->ri_nextout->d_length1 = TULIP_RX_BUFLEN; 1210 ri->ri_nextout->d_addr1 = vtophys(mtod(ms, caddr_t)); 1211 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 1212 if (++ri->ri_nextout == ri->ri_last) 1213 ri->ri_nextout = ri->ri_first; 1214 me = ms->m_next; 1215 ms->m_next = NULL; 1216 IF_ENQUEUE(&sc->tulip_rxq, ms); 1217 } while ((ms = me) != NULL); 1218 } 1219} 1220 1221static int 1222tulip_tx_intr( 1223 tulip_softc_t * const sc) 1224{ 1225 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 1226 struct mbuf *m; 1227 int xmits = 0; 1228 1229 while (ri->ri_free < ri->ri_max) { 1230 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 1231 break; 1232 1233 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) { 1234 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) { 1235 /* 1236 * We've just finished processing a setup packet. 1237 * Mark that we can finished it. If there's not 1238 * another pending, startup the TULIP receiver. 1239 * Make sure we ack the RXSTOPPED so we won't get 1240 * an abormal interrupt indication. 1241 */ 1242 sc->tulip_flags &= ~TULIP_DOINGSETUP; 1243 if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 1244 tulip_rx_intr(sc); 1245 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 1246 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 1247 TULIP_WRITE_CSR(sc, csr_status, TULIP_STS_RXSTOPPED); 1248 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode); 1249 TULIP_WRITE_CSR(sc, csr_intr, sc->tulip_intrmask); 1250 } 1251 } else { 1252 IF_DEQUEUE(&sc->tulip_txq, m); 1253 m_freem(m); 1254 xmits++; 1255 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 1256 if ((ri->ri_nextin->d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) == 0) 1257 sc->tulip_flags |= TULIP_TXPROBE_OK; 1258 (*sc->tulip_boardsw->bd_media_select)(sc); 1259 } else { 1260 sc->tulip_if.if_collisions += 1261 (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK) 1262 >> TULIP_DSTS_V_TxCOLLCNT; 1263 if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM) 1264 sc->tulip_if.if_oerrors++; 1265 } 1266 } 1267 } 1268 1269 if (++ri->ri_nextin == ri->ri_last) 1270 ri->ri_nextin = ri->ri_first; 1271 ri->ri_free++; 1272 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 1273 } 1274 sc->tulip_if.if_opackets += xmits; 1275 return xmits; 1276} 1277 1278static ifnet_ret_t 1279tulip_start( 1280 struct ifnet * const ifp) 1281{ 1282 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 1283 struct ifqueue * const ifq = &ifp->if_snd; 1284 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 1285 struct mbuf *m, *m0, *next_m0; 1286 1287 if ((ifp->if_flags & IFF_RUNNING) == 0 1288 && (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 1289 return; 1290 1291 for (;;) { 1292 tulip_desc_t *eop, *nextout; 1293 int segcnt, free, recopy; 1294 tulip_uint32_t d_status; 1295 1296 if (sc->tulip_flags & TULIP_WANTSETUP) { 1297 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 1298 ifp->if_flags |= IFF_OACTIVE; 1299 return; 1300 } 1301 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 1302 sizeof(sc->tulip_setupbuf)); 1303 sc->tulip_flags &= ~TULIP_WANTSETUP; 1304 sc->tulip_flags |= TULIP_DOINGSETUP; 1305 ri->ri_free--; 1306 ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 1307 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 1308 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 1309 if (sc->tulip_flags & TULIP_WANTHASH) 1310 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 1311 ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf); 1312 ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf); 1313 ri->ri_nextout->d_length2 = 0; 1314 ri->ri_nextout->d_addr2 = 0; 1315 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 1316 TULIP_WRITE_CSR(sc, csr_txpoll, 1); 1317 /* 1318 * Advance the ring for the next transmit packet. 1319 */ 1320 if (++ri->ri_nextout == ri->ri_last) 1321 ri->ri_nextout = ri->ri_first; 1322 /* 1323 * Make sure the next descriptor is owned by us since it 1324 * may have been set up above if we ran out of room in the 1325 * ring. 1326 */ 1327 ri->ri_nextout->d_status = 0; 1328 } 1329 1330 IF_DEQUEUE(ifq, m); 1331 if (m == NULL) 1332 break; 1333 1334 /* 1335 * Now we try to fill in our transmit descriptors. This is 1336 * a bit reminiscent of going on the Ark two by two 1337 * since each descriptor for the TULIP can describe 1338 * two buffers. So we advance through packet filling 1339 * each of the two entries at a time to to fill each 1340 * descriptor. Clear the first and last segment bits 1341 * in each descriptor (actually just clear everything 1342 * but the end-of-ring or chain bits) to make sure 1343 * we don't get messed up by previously sent packets. 1344 * 1345 * We may fail to put the entire packet on the ring if 1346 * there is either not enough ring entries free or if the 1347 * packet has more than MAX_TXSEG segments. In the former 1348 * case we will just wait for the ring to empty. In the 1349 * latter case we have to recopy. 1350 */ 1351 d_status = 0; 1352 recopy = 0; 1353 eop = nextout = ri->ri_nextout; 1354 m0 = m; 1355 segcnt = 0; 1356 free = ri->ri_free; 1357 do { 1358 int len = m0->m_len; 1359 caddr_t addr = mtod(m0, caddr_t); 1360 unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); 1361 1362 next_m0 = m0->m_next; 1363 while (len > 0) { 1364 unsigned slen = min(len, clsize); 1365 1366 segcnt++; 1367 if (segcnt > TULIP_MAX_TXSEG) { 1368 recopy = 1; 1369 next_m0 = NULL; /* to break out of outside loop */ 1370 break; 1371 } 1372 if (segcnt & 1) { 1373 if (--free == 0) { 1374 /* 1375 * There's no more room but since nothing 1376 * has been committed at this point, just 1377 * show output is active, put back the 1378 * mbuf and return. 1379 */ 1380 ifp->if_flags |= IFF_OACTIVE; 1381 IF_PREPEND(ifq, m); 1382 return; 1383 } 1384 eop = nextout; 1385 if (++nextout == ri->ri_last) 1386 nextout = ri->ri_first; 1387 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 1388 eop->d_status = d_status; 1389 eop->d_addr1 = vtophys(addr); eop->d_length1 = slen; 1390 } else { 1391 /* 1392 * Fill in second half of descriptor 1393 */ 1394 eop->d_addr2 = vtophys(addr); eop->d_length2 = slen; 1395 } 1396 d_status = TULIP_DSTS_OWNER; 1397 len -= slen; 1398 addr += slen; 1399 clsize = CLBYTES; 1400 } 1401 } while ((m0 = next_m0) != NULL); 1402 1403 /* 1404 * The packet exceeds the number of transmit buffer 1405 * entries that we can use for one packet, so we have 1406 * recopy it into one mbuf and then try again. 1407 */ 1408 if (recopy) { 1409 MGETHDR(m0, M_DONTWAIT, MT_DATA); 1410 if (m0 != NULL) { 1411 if (m->m_pkthdr.len > MHLEN) { 1412 MCLGET(m0, M_DONTWAIT); 1413 if ((m0->m_flags & M_EXT) == 0) { 1414 m_freem(m); 1415 m_freem(m0); 1416 continue; 1417 } 1418 } 1419 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 1420 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 1421 IF_PREPEND(ifq, m0); 1422 } 1423 m_freem(m); 1424 continue; 1425 } 1426 1427 /* 1428 * The descriptors have been filled in. Now get ready 1429 * to transmit. 1430 */ 1431#if NBPFILTER > 0 1432 if (sc->tulip_bpf != NULL) 1433 bpf_mtap(sc->tulip_bpf, m); 1434#endif 1435 IF_ENQUEUE(&sc->tulip_txq, m); 1436 1437 /* 1438 * Make sure the next descriptor after this packet is owned 1439 * by us since it may have been set up above if we ran out 1440 * of room in the ring. 1441 */ 1442 nextout->d_status = 0; 1443 1444 /* 1445 * If we only used the first segment of the last descriptor, 1446 * make sure the second segment will not be used. 1447 */ 1448 if (segcnt & 1) { 1449 eop->d_addr2 = 0; 1450 eop->d_length2 = 0; 1451 } 1452 1453 /* 1454 * Mark the last and first segments, indicate we want a transmit 1455 * complete interrupt, give the descriptors to the TULIP, and tell 1456 * it to transmit! 1457 */ 1458 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 1459 1460 /* 1461 * Note that ri->ri_nextout is still the start of the packet 1462 * and until we set the OWNER bit, we can still back out of 1463 * everything we have done. 1464 */ 1465 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 1466 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 1467 1468 /* 1469 * This advances the ring for us. 1470 */ 1471 ri->ri_nextout = nextout; 1472 ri->ri_free = free; 1473 1474 TULIP_WRITE_CSR(sc, csr_txpoll, 1); 1475 } 1476 if (m != NULL) { 1477 ifp->if_flags |= IFF_OACTIVE; 1478 IF_PREPEND(ifq, m); 1479 } 1480} 1481 1482static int 1483tulip_intr( 1484 void *arg) 1485{ 1486 tulip_softc_t * sc = (tulip_softc_t *) arg; 1487 tulip_uint32_t csr; 1488#if defined(__bsdi__) 1489 int progress = 1; 1490#else 1491 int progress = 0; 1492#endif 1493 1494 do { 1495 while ((csr = TULIP_READ_CSR(sc, csr_status)) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) { 1496 progress = 1; 1497 TULIP_WRITE_CSR(sc, csr_status, csr & sc->tulip_intrmask); 1498 1499 if (csr & TULIP_STS_SYSERROR) { 1500 if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) { 1501 tulip_reset(sc); 1502 tulip_init(sc); 1503 break; 1504 } 1505 } 1506 if (csr & (TULIP_STS_GPTIMEOUT|TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL)) { 1507 if (sc->tulip_chipid == TULIP_DC21041) { 1508 (*sc->tulip_boardsw->bd_media_select)(sc); 1509 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL)) 1510 csr &= ~TULIP_STS_ABNRMLINTR; 1511 } 1512 } 1513 if (csr & TULIP_STS_ABNRMLINTR) { 1514 printf("%s: abnormal interrupt: 0x%05x [0x%05x]\n", 1515 sc->tulip_xname, csr, csr & sc->tulip_intrmask); 1516 TULIP_WRITE_CSR(sc, csr_command, sc->tulip_cmdmode); 1517 } 1518 if (csr & TULIP_STS_RXINTR) 1519 tulip_rx_intr(sc); 1520 if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) { 1521 tulip_tx_intr(sc); 1522 tulip_start(&sc->tulip_if); 1523 } 1524 } 1525 } while ((sc = sc->tulip_slaves) != NULL); 1526 return progress; 1527} 1528 1529/* 1530 * 1531 */ 1532 1533static void 1534tulip_delay_300ns( 1535 tulip_softc_t * const sc) 1536{ 1537 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1538 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1539 1540 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1541 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1542 1543 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1544 TULIP_READ_CSR(sc, csr_busmode); TULIP_READ_CSR(sc, csr_busmode); 1545} 1546 1547#define EMIT do { TULIP_WRITE_CSR(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0) 1548 1549static void 1550tulip_idle_srom( 1551 tulip_softc_t * const sc) 1552{ 1553 unsigned bit, csr; 1554 1555 csr = SROMSEL | SROMRD; EMIT; 1556 csr ^= SROMCS; EMIT; 1557 csr ^= SROMCLKON; EMIT; 1558 1559 /* 1560 * Write 25 cycles of 0 which will force the SROM to be idle. 1561 */ 1562 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 1563 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1564 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1565 } 1566 csr ^= SROMCLKOFF; EMIT; 1567 csr ^= SROMCS; EMIT; EMIT; 1568 csr = 0; EMIT; 1569} 1570 1571 1572static void 1573tulip_read_srom( 1574 tulip_softc_t * const sc) 1575{ 1576 int idx; 1577 const unsigned bitwidth = SROM_BITWIDTH; 1578 const unsigned cmdmask = (SROMCMD_RD << bitwidth); 1579 const unsigned msb = 1 << (bitwidth + 3 - 1); 1580 unsigned lastidx = (1 << bitwidth) - 1; 1581 1582 tulip_idle_srom(sc); 1583 1584 for (idx = 0; idx <= lastidx; idx++) { 1585 unsigned lastbit, data, bits, bit, csr; 1586 csr = SROMSEL | SROMRD; EMIT; 1587 csr ^= SROMCSON; EMIT; 1588 csr ^= SROMCLKON; EMIT; 1589 1590 lastbit = 0; 1591 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 1592 const unsigned thisbit = bits & msb; 1593 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1594 if (thisbit != lastbit) { 1595 csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 1596 } 1597 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1598 lastbit = thisbit; 1599 } 1600 csr ^= SROMCLKOFF; EMIT; 1601 1602 for (data = 0, bits = 0; bits < 16; bits++) { 1603 data <<= 1; 1604 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1605 data |= TULIP_READ_CSR(sc, csr_srom_mii) & SROMDIN ? 1 : 0; 1606 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1607 } 1608 sc->tulip_rombuf[idx*2] = data & 0xFF; 1609 sc->tulip_rombuf[idx*2+1] = data >> 8; 1610 csr = SROMSEL | SROMRD; EMIT; 1611 csr = 0; EMIT; 1612 } 1613} 1614 1615#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF) 1616#define tulip_srom_crcok(databuf) ( \ 1617 ((tulip_crc32(databuf, 126) & 0xFFFF) ^ 0xFFFF)== \ 1618 ((databuf)[126] | ((databuf)[127] << 8))) 1619 1620static unsigned 1621tulip_crc32( 1622 const unsigned char *databuf, 1623 size_t datalen) 1624{ 1625 u_int idx, bit, data, crc = 0xFFFFFFFFUL; 1626 1627 for (idx = 0; idx < datalen; idx++) 1628 for (data = *databuf++, bit = 0; bit < 8; bit++, data >>= 1) 1629 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0); 1630 return crc; 1631} 1632 1633 1634/* 1635 * This deals with the vagaries of the address roms and the 1636 * brain-deadness that various vendors commit in using them. 1637 */ 1638static int 1639tulip_read_macaddr( 1640 tulip_softc_t *sc) 1641{ 1642 int cksum, rom_cksum, idx; 1643 tulip_uint32_t csr; 1644 unsigned char tmpbuf[8]; 1645 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 1646 1647 if (sc->tulip_chipid == TULIP_DC21040) { 1648 TULIP_WRITE_CSR(sc, csr_enetrom, 1); 1649 for (idx = 0; idx < 32; idx++) { 1650 int cnt = 0; 1651 while (((csr = TULIP_READ_CSR(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000) 1652 cnt++; 1653 sc->tulip_rombuf[idx] = csr & 0xFF; 1654 } 1655 sc->tulip_boardsw = &tulip_dc21040_boardsw; 1656#if defined(TULIP_EISA) 1657 } else if (sc->tulip_chipid == TULIP_DE425) { 1658 int cnt; 1659 for (idx = 0, cnt = 0; idx < sizeof(testpat) && cnt < 32; cnt++) { 1660 tmpbuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom); 1661 if (tmpbuf[idx] == testpat[idx]) 1662 ++idx; 1663 else 1664 idx = 0; 1665 } 1666 for (idx = 0; idx < 32; idx++) 1667 sc->tulip_rombuf[idx] = TULIP_READ_CSRBYTE(sc, csr_enetrom); 1668 sc->tulip_boardsw = &tulip_dc21040_boardsw; 1669#endif /* TULIP_EISA */ 1670 } else { 1671 int new_srom_fmt = 0; 1672 /* 1673 * Assume all DC21140 board are compatible with the 1674 * DEC 10/100 evaluation board. Not really valid but 1675 * it's the best we can do until every one switches to 1676 * the new SROM format. 1677 */ 1678 if (sc->tulip_chipid == TULIP_DC21140) 1679 sc->tulip_boardsw = &tulip_dc21140_eb_boardsw; 1680 /* 1681 * Thankfully all DC21041's act the same. 1682 */ 1683 if (sc->tulip_chipid == TULIP_DC21041) 1684 sc->tulip_boardsw = &tulip_dc21041_boardsw; 1685 tulip_read_srom(sc); 1686 if (tulip_srom_crcok(sc->tulip_rombuf)) { 1687 /* 1688 * SROM CRC is valid therefore it must be in the 1689 * new format. 1690 */ 1691 new_srom_fmt = 1; 1692 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) { 1693 /* 1694 * No checksum is present. See if the SROM id checks out; 1695 * the first 18 bytes should be 0 followed by a 1 followed 1696 * by the number of adapters (which we don't deal with yet). 1697 */ 1698 for (idx = 0; idx < 18; idx++) { 1699 if (sc->tulip_rombuf[idx] != 0) 1700 break; 1701 } 1702 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0) 1703 new_srom_fmt = 2; 1704 } 1705 if (new_srom_fmt) { 1706 /* 1707 * New SROM format. Copy out the Ethernet address. 1708 * If it contains a DE500-XA string, then it must be 1709 * a DE500-XA. 1710 */ 1711 bcopy(sc->tulip_rombuf + 20, sc->tulip_hwaddr, 6); 1712 if (bcmp(sc->tulip_rombuf + 29, "DE500-XA", 8) == 0) 1713 sc->tulip_boardsw = &tulip_dc21140_de500_boardsw; 1714 if (bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) 1715 sc->tulip_boardsw = &tulip_dc21041_de450_boardsw; 1716 if (sc->tulip_boardsw == NULL) 1717 return -6; 1718 sc->tulip_flags |= TULIP_ROMOK; 1719 return 0; 1720 } 1721 } 1722 1723 1724 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 1725 /* 1726 * Some folks don't use the standard ethernet rom format 1727 * but instead just put the address in the first 6 bytes 1728 * of the rom and let the rest be all 0xffs. (Can we say 1729 * ZNYX???) (well sometimes they put in a checksum so we'll 1730 * start at 8). 1731 */ 1732 for (idx = 8; idx < 32; idx++) { 1733 if (sc->tulip_rombuf[idx] != 0xFF) 1734 return -4; 1735 } 1736 /* 1737 * Make sure the address is not multicast or locally assigned 1738 * that the OUI is not 00-00-00. 1739 */ 1740 if ((sc->tulip_rombuf[0] & 3) != 0) 1741 return -4; 1742 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 1743 && sc->tulip_rombuf[2] == 0) 1744 return -4; 1745 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 1746 sc->tulip_flags |= TULIP_ROMOK; 1747 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0 1748 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1 1749 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2 1750 && (sc->tulip_hwaddr[3] & ~3) == 0xF0) { 1751 /* 1752 * Now if the OUI is ZNYX and hwaddr[3] == 0xF0 .. 0xF3 1753 * then it's a ZX314 Master port. 1754 */ 1755 sc->tulip_boardsw = &tulip_dc21040_zx314_master_boardsw; 1756 } 1757 return 0; 1758 } else { 1759 /* 1760 * A number of makers of multiport boards (ZNYX and Cogent) 1761 * only put on one address ROM on their DC21040 boards. So 1762 * if the ROM is all zeros and this is a DC21040, look at the 1763 * previous configured boards (as long as they are on the same 1764 * PCI bus and the bus number is non-zero) until we find the 1765 * master board with address ROM. We then use its address ROM 1766 * as the base for this board. (we add our relative board 1767 * to the last byte of its address). 1768 */ 1769 if (sc->tulip_chipid == TULIP_DC21040 /* && sc->tulip_bus != 0 XXX */) { 1770 for (idx = 0; idx < 32; idx++) { 1771 if (sc->tulip_rombuf[idx] != 0) 1772 break; 1773 } 1774 if (idx == 32) { 1775 int root_unit; 1776 tulip_softc_t *root_sc = NULL; 1777 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 1778 root_sc = TULIP_UNIT_TO_SOFTC(root_unit); 1779 if (root_sc == NULL || (root_sc->tulip_flags & (TULIP_ROMOK|TULIP_SLAVEDROM)) == TULIP_ROMOK) 1780 break; 1781 root_sc = NULL; 1782 } 1783 if (root_sc != NULL 1784 /* && root_sc->tulip_bus == sc->tulip_bus XXX */) { 1785 bcopy(root_sc->tulip_hwaddr, sc->tulip_hwaddr, 6); 1786 sc->tulip_hwaddr[5] += sc->tulip_unit - root_sc->tulip_unit; 1787 sc->tulip_flags |= TULIP_SLAVEDROM; 1788 if (root_sc->tulip_boardsw->bd_type == TULIP_DC21040_ZX314_MASTER) { 1789 sc->tulip_boardsw = &tulip_dc21040_zx314_slave_boardsw; 1790 /* 1791 * Now for a truly disgusting kludge: all 4 DC21040s on 1792 * the ZX314 share the same INTA line so the mapping 1793 * setup by the BIOS on the PCI bridge is worthless. 1794 * Rather than reprogramming the value in the config 1795 * register, we will handle this internally. 1796 */ 1797 sc->tulip_slaves = root_sc->tulip_slaves; 1798 root_sc->tulip_slaves = sc; 1799 } 1800 return 0; 1801 } 1802 } 1803 } 1804 } 1805 1806 /* 1807 * This is the standard DEC address ROM test. 1808 */ 1809 1810 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 1811 return -3; 1812 1813 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 1814 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 1815 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 1816 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 1817 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 1818 return -2; 1819 1820 bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 1821 1822 cksum = *(u_short *) &sc->tulip_hwaddr[0]; 1823 cksum *= 2; 1824 if (cksum > 65535) cksum -= 65535; 1825 cksum += *(u_short *) &sc->tulip_hwaddr[2]; 1826 if (cksum > 65535) cksum -= 65535; 1827 cksum *= 2; 1828 if (cksum > 65535) cksum -= 65535; 1829 cksum += *(u_short *) &sc->tulip_hwaddr[4]; 1830 if (cksum >= 65535) cksum -= 65535; 1831 1832 rom_cksum = *(u_short *) &sc->tulip_rombuf[6]; 1833 1834 if (cksum != rom_cksum) 1835 return -1; 1836 1837 /* 1838 * Check for various boards based on OUI. Did I say braindead? 1839 */ 1840 1841 if (sc->tulip_chipid == TULIP_DC21140) { 1842 if (sc->tulip_hwaddr[0] == TULIP_OUI_COGENT_0 1843 && sc->tulip_hwaddr[1] == TULIP_OUI_COGENT_1 1844 && sc->tulip_hwaddr[2] == TULIP_OUI_COGENT_2) { 1845 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID) 1846 sc->tulip_boardsw = &tulip_dc21140_cogent_em100_boardsw; 1847 } 1848 if (sc->tulip_hwaddr[0] == TULIP_OUI_ZNYX_0 1849 && sc->tulip_hwaddr[1] == TULIP_OUI_ZNYX_1 1850 && sc->tulip_hwaddr[2] == TULIP_OUI_ZNYX_2) { 1851 /* this at least works for the zx342 from Znyx */ 1852 sc->tulip_boardsw = &tulip_dc21140_znyx_zx34x_boardsw; 1853 } 1854 } 1855 1856 sc->tulip_flags |= TULIP_ROMOK; 1857 return 0; 1858} 1859 1860static void 1861tulip_addr_filter( 1862 tulip_softc_t * const sc) 1863{ 1864 tulip_uint32_t *sp = sc->tulip_setupdata; 1865 struct ether_multistep step; 1866 struct ether_multi *enm; 1867 int i; 1868 1869 sc->tulip_flags &= ~TULIP_WANTHASH; 1870 sc->tulip_flags |= TULIP_WANTSETUP; 1871 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 1872 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 1873 if (sc->tulip_ac.ac_multicnt > 14) { 1874 unsigned hash; 1875 /* 1876 * If we have more than 14 multicasts, we have 1877 * go into hash perfect mode (512 bit multicast 1878 * hash and one perfect hardware). 1879 */ 1880 1881 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 1882 hash = tulip_mchash(etherbroadcastaddr); 1883 sp[hash >> 4] |= 1 << (hash & 0xF); 1884 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 1885 while (enm != NULL) { 1886 hash = tulip_mchash(enm->enm_addrlo); 1887 sp[hash >> 4] |= 1 << (hash & 0xF); 1888 ETHER_NEXT_MULTI(step, enm); 1889 } 1890 sc->tulip_flags |= TULIP_WANTHASH; 1891 sp[39] = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 1892 sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 1893 sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 1894 } else { 1895 /* 1896 * Else can get perfect filtering for 16 addresses. 1897 */ 1898 i = 0; 1899 ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 1900 for (; enm != NULL; i++) { 1901 *sp++ = ((u_short *) enm->enm_addrlo)[0]; 1902 *sp++ = ((u_short *) enm->enm_addrlo)[1]; 1903 *sp++ = ((u_short *) enm->enm_addrlo)[2]; 1904 ETHER_NEXT_MULTI(step, enm); 1905 } 1906 /* 1907 * Add the broadcast address. 1908 */ 1909 i++; 1910 *sp++ = 0xFFFF; 1911 *sp++ = 0xFFFF; 1912 *sp++ = 0xFFFF; 1913 /* 1914 * Pad the rest with our hardware address 1915 */ 1916 for (; i < 16; i++) { 1917 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 1918 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 1919 *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 1920 } 1921 } 1922} 1923 1924static int 1925tulip_ioctl( 1926 struct ifnet * const ifp, 1927 ioctl_cmd_t cmd, 1928 caddr_t data) 1929{ 1930 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 1931 struct ifaddr *ifa = (struct ifaddr *)data; 1932 struct ifreq *ifr = (struct ifreq *) data; 1933 int s, error = 0; 1934 1935 s = splnet(); 1936 1937 if ((error = ether_ioctl(ifp, &sc->tulip_ac, cmd, data)) > 0) { 1938 splx(s); 1939 return error; 1940 } 1941 1942 switch (cmd) { 1943 case SIOCSIFADDR: { 1944 ifp->if_flags |= IFF_UP; 1945 switch(ifa->ifa_addr->sa_family) { 1946#ifdef INET 1947 case AF_INET: { 1948 tulip_init(sc); 1949 arp_ifinit(&sc->tulip_ac, ifa); 1950 break; 1951 } 1952#endif /* INET */ 1953 1954 default: { 1955 tulip_init(sc); 1956 break; 1957 } 1958 } 1959 break; 1960 } 1961 case SIOCGIFADDR: { 1962 bcopy((caddr_t) sc->tulip_ac.ac_enaddr, 1963 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data, 1964 6); 1965 break; 1966 } 1967 1968 case SIOCSIFFLAGS: { 1969 /* 1970 * Changing the connection forces a reset. 1971 */ 1972 if (sc->tulip_flags & TULIP_ALTPHYS) { 1973 if ((ifp->if_flags & IFF_ALTPHYS) == 0) 1974 tulip_reset(sc); 1975 } else { 1976 if (ifp->if_flags & IFF_ALTPHYS) 1977 tulip_reset(sc); 1978 } 1979 tulip_init(sc); 1980 break; 1981 } 1982 1983 case SIOCADDMULTI: 1984 case SIOCDELMULTI: { 1985 /* 1986 * Update multicast listeners 1987 */ 1988 if (cmd == SIOCADDMULTI) 1989 error = ether_addmulti(ifr, &sc->tulip_ac); 1990 else 1991 error = ether_delmulti(ifr, &sc->tulip_ac); 1992 1993 if (error == ENETRESET) { 1994 tulip_addr_filter(sc); /* reset multicast filtering */ 1995 tulip_init(sc); 1996 error = 0; 1997 } 1998 break; 1999 } 2000#if defined(SIOCSIFMTU) 2001#if !defined(ifr_mtu) 2002#define ifr_mtu ifr_metric 2003#endif 2004 case SIOCSIFMTU: 2005 /* 2006 * Set the interface MTU. 2007 */ 2008 if (ifr->ifr_mtu > ETHERMTU 2009#ifndef BIG_PACKET 2010 && sc->tulip_chipid != TULIP_DC21140 2011 && sc->tulip_chipid != TULIP_DC21041 2012#endif 2013 ) { 2014 error = EINVAL; 2015 break; 2016 } 2017 ifp->if_mtu = ifr->ifr_mtu; 2018#ifdef BIG_PACKET 2019 tulip_reset(sc); 2020 tulip_init(sc); 2021#endif 2022 break; 2023#endif /* SIOCSIFMTU */ 2024 2025 default: { 2026 error = EINVAL; 2027 break; 2028 } 2029 } 2030 2031 splx(s); 2032 return error; 2033} 2034 2035static void 2036tulip_attach( 2037 tulip_softc_t * const sc) 2038{ 2039 struct ifnet * const ifp = &sc->tulip_if; 2040 2041 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; 2042 ifp->if_ioctl = tulip_ioctl; 2043 ifp->if_output = ether_output; 2044 ifp->if_start = tulip_start; 2045 2046#if defined(__FreeBSD__) 2047 printf("%s", sc->tulip_xname); 2048#elif defined(__bsdi__) 2049 printf("\n%s", sc->tulip_xname); 2050#endif 2051#if defined(__NetBSD__) 2052 printf(": %s%s pass %d.%d\n%s: Ethernet address %s\n", 2053#else 2054 printf(": %s%s pass %d.%d Ethernet address %s\n", 2055#endif 2056 sc->tulip_boardsw->bd_description, 2057 tulip_chipdescs[sc->tulip_chipid], 2058 (sc->tulip_revinfo & 0xF0) >> 4, 2059 sc->tulip_revinfo & 0x0F, 2060#if defined(__NetBSD__) 2061 sc->tulip_dev.dv_xname, 2062#endif 2063 ether_sprintf(sc->tulip_hwaddr)); 2064 2065 if ((*sc->tulip_boardsw->bd_media_probe)(sc)) { 2066 ifp->if_flags |= IFF_ALTPHYS; 2067 } else { 2068 sc->tulip_flags |= TULIP_ALTPHYS; 2069 } 2070 2071 tulip_reset(sc); 2072 2073 if_attach(ifp); 2074#if defined(__NetBSD__) 2075 ether_ifattach(ifp); 2076#endif 2077 2078#if NBPFILTER > 0 2079 bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 2080#endif 2081} 2082 2083static void 2084tulip_initcsrs( 2085 tulip_softc_t * const sc, 2086 tulip_csrptr_t csr_base, 2087 size_t csr_size) 2088{ 2089 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; 2090 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; 2091 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; 2092 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; 2093 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; 2094 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; 2095 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; 2096 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; 2097 sc->tulip_csrs.csr_missed_frame = csr_base + 8 * csr_size; 2098 if (sc->tulip_chipid == TULIP_DC21040) { 2099 sc->tulip_csrs.csr_enetrom = csr_base + 9 * csr_size; 2100 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size; 2101 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size; 2102 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size; 2103 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size; 2104 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size; 2105 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size; 2106#if defined(TULIP_EISA) 2107 } else if (sc->tulip_chipid == TULIP_DE425) { 2108 sc->tulip_csrs.csr_enetrom = csr_base + DE425_ENETROM_OFFSET; 2109 sc->tulip_csrs.csr_reserved = csr_base + 10 * csr_size; 2110 sc->tulip_csrs.csr_full_duplex = csr_base + 11 * csr_size; 2111 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size; 2112 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size; 2113 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size; 2114 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size; 2115#endif /* TULIP_EISA */ 2116 } else if (sc->tulip_chipid == TULIP_DC21140) { 2117 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size; 2118 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size; 2119 sc->tulip_csrs.csr_gp = csr_base + 12 * csr_size; 2120 sc->tulip_csrs.csr_watchdog = csr_base + 15 * csr_size; 2121 } else if (sc->tulip_chipid == TULIP_DC21041) { 2122 sc->tulip_csrs.csr_srom_mii = csr_base + 9 * csr_size; 2123 sc->tulip_csrs.csr_bootrom = csr_base + 10 * csr_size; 2124 sc->tulip_csrs.csr_gp_timer = csr_base + 11 * csr_size; 2125 sc->tulip_csrs.csr_sia_status = csr_base + 12 * csr_size; 2126 sc->tulip_csrs.csr_sia_connectivity = csr_base + 13 * csr_size; 2127 sc->tulip_csrs.csr_sia_tx_rx = csr_base + 14 * csr_size; 2128 sc->tulip_csrs.csr_sia_general = csr_base + 15 * csr_size; 2129 } 2130} 2131 2132static void 2133tulip_initring( 2134 tulip_softc_t * const sc, 2135 tulip_ringinfo_t * const ri, 2136 tulip_desc_t *descs, 2137 int ndescs) 2138{ 2139 ri->ri_max = ndescs; 2140 ri->ri_first = descs; 2141 ri->ri_last = ri->ri_first + ri->ri_max; 2142 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 2143 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 2144} 2145 2146/* 2147 * This is the PCI configuration support. Since the DC21040 is available 2148 * on both EISA and PCI boards, one must be careful in how defines the 2149 * DC21040 in the config file. 2150 */ 2151 2152#define PCI_CFID 0x00 /* Configuration ID */ 2153#define PCI_CFCS 0x04 /* Configurtion Command/Status */ 2154#define PCI_CFRV 0x08 /* Configuration Revision */ 2155#define PCI_CFLT 0x0c /* Configuration Latency Timer */ 2156#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 2157#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 2158#define PCI_CFIT 0x3c /* Configuration Interrupt */ 2159#define PCI_CFDA 0x40 /* Configuration Driver Area */ 2160 2161#if defined(TULIP_EISA) 2162static const int tulip_eisa_irqs[4] = { IRQ5, IRQ9, IRQ10, IRQ11 }; 2163#endif 2164 2165#if defined(__FreeBSD__) 2166 2167#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit 2168 2169static int 2170tulip_pci_shutdown( 2171 struct kern_devconf * const kdc, 2172 int force) 2173{ 2174 if (kdc->kdc_unit < NDE) { 2175 tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit); 2176 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 2177 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 2178 33MHz that comes to two microseconds but wait a 2179 bit longer anyways) */ 2180 } 2181 (void) dev_detach(kdc); 2182 return 0; 2183} 2184 2185static char* 2186tulip_pci_probe( 2187 pcici_t config_id, 2188 pcidi_t device_id) 2189{ 2190 if (PCI_VENDORID(device_id) != DEC_VENDORID) 2191 return NULL; 2192 if (PCI_CHIPID(device_id) == DC21040_CHIPID) 2193 return "Digital DC21040 Ethernet"; 2194 if (PCI_CHIPID(device_id) == DC21041_CHIPID) 2195 return "Digital DC21041 Ethernet"; 2196 if (PCI_CHIPID(device_id) == DC21140_CHIPID) 2197 return "Digital DC21140 Fast Ethernet"; 2198 return NULL; 2199} 2200 2201static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 2202static u_long tulip_pci_count; 2203 2204struct pci_device dedevice = { 2205 "de", 2206 tulip_pci_probe, 2207 tulip_pci_attach, 2208 &tulip_pci_count, 2209 tulip_pci_shutdown, 2210}; 2211 2212DATA_SET (pcidevice_set, dedevice); 2213#endif /* __FreeBSD__ */ 2214 2215#if defined(__bsdi__) 2216#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux 2217 2218static void 2219tulip_shutdown( 2220 void *arg) 2221{ 2222 tulip_softc_t * const sc = (tulip_softc_t *) arg; 2223 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 2224 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 2225 33MHz that comes to two microseconds but wait a 2226 bit longer anyways) */ 2227} 2228 2229static int 2230tulip_pci_match( 2231 pci_devaddr_t *pa) 2232{ 2233 int irq; 2234 unsigned id; 2235 2236 id = pci_inl(pa, PCI_VENDOR_ID); 2237 if (PCI_VENDORID(id) != DEC_VENDORID) 2238 return 0; 2239 id = PCI_CHIPID(id); 2240 if (id != DC21040_CHIPID && id != DC21041_CHIPID && id != DC21140_CHIPID) 2241 return 0; 2242 irq = pci_inl(pa, PCI_I_LINE) & 0xFF; 2243 if (irq == 0 || irq >= 16) { 2244 printf("de?: invalid IRQ %d; skipping\n", irq); 2245 return 0; 2246 } 2247 return 1; 2248} 2249 2250static int 2251tulip_probe( 2252 struct device *parent, 2253 struct cfdata *cf, 2254 void *aux) 2255{ 2256 struct isa_attach_args * const ia = (struct isa_attach_args *) aux; 2257 unsigned irq, slot; 2258 pci_devaddr_t *pa; 2259 2260 switch (ia->ia_bustype) { 2261 case BUS_PCI: 2262 pa = pci_scan(tulip_pci_match); 2263 if (pa == NULL) 2264 return 0; 2265 2266 irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF)); 2267 2268 /* Get the base address; assume the BIOS set it up correctly */ 2269#if defined(TULIP_IOMAPPED) 2270 ia->ia_maddr = NULL; 2271 ia->ia_msize = 0; 2272 ia->ia_iobase = pci_inl(pa, PCI_CBIO) & ~7; 2273 pci_outl(pa, PCI_CBIO, 0xFFFFFFFF); 2274 ia->ia_iosize = ((~pci_inl(pa, PCI_CBIO)) | 7) + 1; 2275 pci_outl(pa, PCI_CBIO, (int) ia->ia_iobase); 2276 2277 /* Disable memory space access */ 2278 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~2); 2279#else 2280 ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7); 2281 pci_outl(pa, PCI_CBMA, 0xFFFFFFFF); 2282 ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1; 2283 pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr); 2284 ia->ia_iobase = 0; 2285 ia->ia_iosize = 0; 2286 2287 /* Disable I/O space access */ 2288 pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1); 2289#endif /* TULIP_IOMAPPED */ 2290 2291 ia->ia_aux = (void *) pa; 2292 break; 2293 2294#if defined(TULIP_EISA) 2295 case BUS_EISA: { 2296 unsigned tmp; 2297 2298 if ((slot = eisa_match(cf, ia)) == 0) 2299 return 0; 2300 ia->ia_iobase = slot << 12; 2301 ia->ia_iosize = EISA_NPORT; 2302 eisa_slotalloc(slot); 2303 tmp = inb(ia->ia_iobase + DE425_CFG0); 2304 irq = tulip_eisa_irqs[(tmp >> 1) & 0x03]; 2305 /* 2306 * Until BSD/OS likes level interrupts, force 2307 * the DE425 into edge-triggered mode. 2308 */ 2309 if ((tmp & 1) == 0) 2310 outb(ia->ia_iobase + DE425_CFG0, tmp | 1); 2311 /* 2312 * CBIO needs to map to the EISA slot 2313 * enable I/O access and Master 2314 */ 2315 outl(ia->ia_iobase + DE425_CBIO, ia->ia_iobase); 2316 outl(ia->ia_iobase + DE425_CFCS, 5 | inl(ia->ia_iobase + DE425_CFCS)); 2317 ia->ia_aux = NULL; 2318 break; 2319 } 2320#endif /* TULIP_EISA */ 2321 2322 default: 2323 return 0; 2324 } 2325 2326 /* PCI bus masters don't use host DMA channels */ 2327 ia->ia_drq = DRQNONE; 2328 2329 if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) { 2330 printf("de%d: error: desired IRQ of %d does not match device's " 2331 "actual IRQ of %d,\n", 2332 cf->cf_unit, 2333 ffs(ia->ia_irq) - 1, ffs(irq) - 1); 2334 return 0; 2335 } 2336 if (ia->ia_irq == IRQUNK) 2337 ia->ia_irq = irq; 2338 ia->ia_irq |= IRQSHARE; 2339 return 1; 2340} 2341 2342static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 2343 2344#if defined(TULIP_EISA) 2345static char *tulip_eisa_ids[] = { 2346 "DEC4250", 2347 NULL 2348}; 2349#endif 2350 2351struct cfdriver decd = { 2352 0, "de", tulip_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t), 2353#if defined(TULIP_EISA) 2354 tulip_eisa_ids 2355#endif 2356}; 2357 2358#endif /* __bsdi__ */ 2359 2360#if defined(__NetBSD__) 2361#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux 2362 2363static void 2364tulip_pci_shutdown( 2365 void *arg) 2366{ 2367 tulip_softc_t * const sc = (tulip_softc_t *) arg; 2368 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 2369 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 2370 33MHz that comes to two microseconds but wait a 2371 bit longer anyways) */ 2372} 2373 2374static int 2375tulip_pci_probe( 2376 struct device *parent, 2377 void *match, 2378 void *aux) 2379{ 2380 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 2381 2382 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID) 2383 return 0; 2384 if (PCI_CHIPID(pa->pa_id) == DC21040_CHIPID 2385 || PCI_CHIPID(pa->pa_id) == DC21041_CHIPID 2386 || PCI_CHIPID(pa->pa_id) == DC21140_CHIPID) 2387 return 1; 2388 2389 return 0; 2390} 2391 2392static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 2393 2394struct cfattach de_ca = { 2395 sizeof(tulip_softc_t), tulip_pci_probe, tulip_pci_attach 2396}; 2397 2398struct cfdriver de_cd = { 2399 0, "de", DV_IFNET 2400}; 2401 2402#endif /* __NetBSD__ */ 2403 2404static void 2405tulip_pci_attach( 2406 TULIP_PCI_ATTACH_ARGS) 2407{ 2408#if defined(__FreeBSD__) 2409 tulip_softc_t *sc; 2410#endif 2411#if defined(__bsdi__) 2412 tulip_softc_t * const sc = (tulip_softc_t *) self; 2413 struct isa_attach_args * const ia = (struct isa_attach_args *) aux; 2414 pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux; 2415 int unit = sc->tulip_dev.dv_unit; 2416#endif 2417#if defined(__NetBSD__) 2418 tulip_softc_t * const sc = (tulip_softc_t *) self; 2419 struct pci_attach_args * const pa = (struct pci_attach_args *) aux; 2420 bus_chipset_tag_t bc = pa->pa_bc; 2421 pci_chipset_tag_t pc = pa->pa_pc; 2422#if defined(TULIP_IOMAPPED) 2423 bus_io_addr_t iobase; 2424 bus_io_size_t iosize; 2425#else 2426 bus_mem_addr_t membase; 2427 bus_mem_size_t memsize; 2428#endif 2429#if defined(__FreeBSD__) 2430 int unit = sc->tulip_dev.dv_unit; 2431#endif 2432 const char *intrstr = NULL; 2433#endif 2434 int retval, idx, revinfo, id; 2435#if !defined(TULIP_IOMAPPED) && !defined(__bsdi__) && !defined(__NetBSD__) 2436 vm_offset_t pa_csrs; 2437#endif 2438 unsigned csrsize = TULIP_PCI_CSRSIZE; 2439 tulip_csrptr_t csr_base; 2440 tulip_desc_t *rxdescs, *txdescs; 2441 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN; 2442 2443#if defined(__FreeBSD__) 2444 if (unit >= NDE) { 2445 printf("de%d: not configured; kernel is built for only %d device%s.\n", 2446 unit, NDE, NDE == 1 ? "" : "s"); 2447 return; 2448 } 2449#endif 2450 2451#if defined(__FreeBSD__) 2452 revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF; 2453 id = pci_conf_read(config_id, PCI_CFID); 2454#endif 2455#if defined(__bsdi__) 2456 if (pa != NULL) { 2457 revinfo = pci_inl(pa, PCI_CFRV) & 0xFF; 2458 id = pci_inl(pa, PCI_CFID); 2459#if defined(TULIP_EISA) 2460 } else { 2461 revinfo = inl(ia->ia_iobase + DE425_CFRV) & 0xFF; 2462 csrsize = TULIP_EISA_CSRSIZE; 2463 chipid = TULIP_DE425; 2464#endif 2465 } 2466#endif 2467#if defined(__NetBSD__) 2468 revinfo = pci_conf_read(pc, pa->pa_tag, PCI_CFRV) & 0xFF; 2469 id = pa->pa_id; 2470#endif 2471 2472 if (PCI_VENDORID(id) == DEC_VENDORID) { 2473 if (PCI_CHIPID(id) == DC21040_CHIPID) chipid = TULIP_DC21040; 2474 else if (PCI_CHIPID(id) == DC21140_CHIPID) chipid = TULIP_DC21140; 2475 else if (PCI_CHIPID(id) == DC21041_CHIPID) chipid = TULIP_DC21041; 2476 } 2477 if (chipid == TULIP_CHIPID_UNKNOWN) 2478 return; 2479 2480 if ((chipid == TULIP_DC21040 || chipid == TULIP_DE425) && revinfo < 0x20) { 2481#ifdef __FreeBSD__ 2482 printf("de%d", unit); 2483#endif 2484 printf(": not configured; DC21040 pass 2.0 required (%d.%d found)\n", 2485 revinfo >> 4, revinfo & 0x0f); 2486 return; 2487 } else if (chipid == TULIP_DC21140 && revinfo < 0x11) { 2488#ifdef __FreeBSD__ 2489 printf("de%d", unit); 2490#endif 2491 printf(": not configured; DC21140 pass 1.1 required (%d.%d found)\n", 2492 revinfo >> 4, revinfo & 0x0f); 2493 return; 2494 } 2495 2496#if defined(__FreeBSD__) 2497 sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); 2498 if (sc == NULL) 2499 return; 2500 bzero(sc, sizeof(*sc)); /* Zero out the softc*/ 2501#endif 2502 2503 rxdescs = (tulip_desc_t *) 2504 malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT); 2505 if (rxdescs == NULL) { 2506#if defined(__FreeBSD__) 2507 free((caddr_t) sc, M_DEVBUF); 2508#endif 2509 return; 2510 } 2511 2512 txdescs = (tulip_desc_t *) 2513 malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT); 2514 if (txdescs == NULL) { 2515 free((caddr_t) rxdescs, M_DEVBUF); 2516#if defined(__FreeBSD__) 2517 free((caddr_t) sc, M_DEVBUF); 2518#endif 2519 return; 2520 } 2521 2522 sc->tulip_chipid = chipid; 2523#if defined(__NetBSD__) 2524 bcopy(self->dv_xname, sc->tulip_if.if_xname, IFNAMSIZ); 2525 sc->tulip_if.if_softc = sc; 2526#else 2527 sc->tulip_unit = unit; 2528 sc->tulip_name = "de"; 2529#endif 2530 sc->tulip_revinfo = revinfo; 2531 2532 /* Set up human-readable name. */ 2533 bzero(sc->tulip_xname, sizeof(sc->tulip_xname)); 2534 sprintf(sc->tulip_xname, "%s%d", sc->tulip_name, sc->tulip_unit); 2535 2536#if defined(__FreeBSD__) 2537#if defined(TULIP_IOMAPPED) 2538 retval = pci_map_port(config_id, PCI_CBIO, &csr_base); 2539#else 2540 retval = pci_map_mem(config_id, PCI_CBMA, (vm_offset_t *) &csr_base, &pa_csrs); 2541#endif 2542 if (!retval) { 2543 free((caddr_t) txdescs, M_DEVBUF); 2544 free((caddr_t) rxdescs, M_DEVBUF); 2545 free((caddr_t) sc, M_DEVBUF); 2546 return; 2547 } 2548 tulips[unit] = sc; 2549#endif /* __FreeBSD__ */ 2550 2551#if defined(__bsdi__) 2552#if defined(TULIP_IOMAPPED) 2553 csr_base = ia->ia_iobase; 2554#else 2555 csr_base = (vm_offset_t) mapphys((vm_offset_t) ia->ia_maddr, ia->ia_msize); 2556#endif 2557#endif /* __bsdi__ */ 2558 2559#if defined(__NetBSD__) 2560 sc->tulip_bc = bc; 2561 sc->tulip_pc = pc; 2562#if defined(TULIP_IOMAPPED) 2563 retval = pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize); 2564 if (!retval) 2565 retval = bus_io_map(bc, iobase, iosize, &sc->tulip_ioh); 2566#else 2567 retval = pci_mem_find(pc, pa->pa_tag, PCI_CBMA, &membase, &memsize, 2568 NULL); 2569 if (!retval) 2570 retval = bus_mem_map(bc, membase, memsize, 0, &sc->tulip_memh); 2571#endif 2572 csr_base = 0; 2573 if (retval) { 2574 free((caddr_t) txdescs, M_DEVBUF); 2575 free((caddr_t) rxdescs, M_DEVBUF); 2576 return; 2577 } 2578#endif /* __NetBSD__ */ 2579 2580 tulip_initcsrs(sc, csr_base, csrsize); 2581 tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS); 2582 tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS); 2583 if ((retval = tulip_read_macaddr(sc)) < 0) { 2584#ifdef __FreeBSD__ 2585 printf("%s", sc->tulip_xname); 2586#endif 2587 printf(": can't read ENET ROM (why=%d) (", retval); 2588 for (idx = 0; idx < 32; idx++) 2589 printf("%02x", sc->tulip_rombuf[idx]); 2590 printf("\n"); 2591 printf("%s: %s%s pass %d.%d Ethernet address %s\n", 2592 sc->tulip_xname, 2593 (sc->tulip_boardsw != NULL ? sc->tulip_boardsw->bd_description : ""), 2594 tulip_chipdescs[sc->tulip_chipid], 2595 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F, 2596 "unknown"); 2597 } else { 2598 /* 2599 * Make sure there won't be any interrupts or such... 2600 */ 2601 TULIP_WRITE_CSR(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 2602 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 2603 33MHz that comes to two microseconds but wait a 2604 bit longer anyways) */ 2605#if defined(__NetBSD__) 2606 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) { 2607 pci_intr_handle_t intrhandle; 2608 2609 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 2610 pa->pa_intrline, &intrhandle)) { 2611 printf(": couldn't map interrupt\n"); 2612 return; 2613 } 2614 intrstr = pci_intr_string(pc, intrhandle); 2615 sc->tulip_ih = pci_intr_establish(pc, intrhandle, IPL_NET, 2616 tulip_intr, sc, self->dv_xname); 2617 if (sc->tulip_ih == NULL) { 2618 printf(": couldn't establish interrupt"); 2619 if (intrstr != NULL) 2620 printf(" at %s", intrstr); 2621 printf("\n"); 2622 return; 2623 } 2624 } 2625 sc->tulip_ats = shutdownhook_establish(tulip_pci_shutdown, sc); 2626 if (sc->tulip_ats == NULL) 2627 printf("\n%s: warning: couldn't establish shutdown hook", 2628 sc->tulip_xname); 2629#endif 2630#if defined(__FreeBSD__) 2631 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) { 2632 if (!pci_map_int (config_id, tulip_intr, (void*) sc, &net_imask)) { 2633 printf("%s: couldn't map interrupt\n", sc->tulip_xname); 2634 return; 2635 } 2636 } 2637#endif 2638#if defined(__bsdi__) 2639 if (sc->tulip_boardsw->bd_type != TULIP_DC21040_ZX314_SLAVE) { 2640 isa_establish(&sc->tulip_id, &sc->tulip_dev); 2641 2642 sc->tulip_ih.ih_fun = tulip_intr; 2643 sc->tulip_ih.ih_arg = (void *)sc; 2644 intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET); 2645 } 2646 2647 sc->tulip_ats.func = tulip_shutdown; 2648 sc->tulip_ats.arg = (void *) sc; 2649 atshutdown(&sc->tulip_ats, ATSH_ADD); 2650#endif 2651 tulip_reset(sc); 2652 tulip_attach(sc); 2653#if defined(__NetBSD__) 2654 if (intrstr != NULL) 2655 printf("%s: interrupting at %s\n", self->dv_xname, intrstr); 2656#endif 2657 } 2658} 2659#endif /* NDE > 0 */ 2660