if_de.c revision 1.122
1/* $OpenBSD: if_de.c,v 1.122 2015/06/25 18:35:48 deraadt Exp $ */ 2/* $NetBSD: if_de.c,v 1.58 1998/01/12 09:39:58 thorpej Exp $ */ 3 4/*- 5 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.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 without 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 * Id: if_de.c,v 1.89 1997/06/03 19:19:55 thomas Exp 28 * 29 */ 30 31/* 32 * DEC 21040 PCI Ethernet Controller 33 * 34 * Written by Matt Thomas 35 * BPF support code stolen directly from if_ec.c 36 * 37 * This driver supports the DEC DE435 or any other PCI 38 * board which support 21040, 21041, or 21140 (mostly). 39 */ 40 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/mbuf.h> 44#include <sys/protosw.h> 45#include <sys/socket.h> 46#include <sys/ioctl.h> 47#include <sys/errno.h> 48#include <sys/malloc.h> 49#include <sys/kernel.h> 50#include <sys/device.h> 51#include <sys/timeout.h> 52#include <sys/pool.h> 53 54#include <net/if.h> 55#include <net/if_media.h> 56#include <net/if_types.h> 57#include <net/if_dl.h> 58#include <net/netisr.h> 59 60#include "bpfilter.h" 61#if NBPFILTER > 0 62#include <net/bpf.h> 63#endif 64 65#include <netinet/in.h> 66#include <netinet/if_ether.h> 67 68#include <machine/bus.h> 69#include <machine/intr.h> 70#include <dev/pci/pcireg.h> 71#include <dev/pci/pcivar.h> 72#include <dev/ic/dc21040reg.h> 73 74/* 75 * Intel CPUs should use I/O mapped access. 76 */ 77#if defined(__i386__) 78#define TULIP_IOMAPPED 79#endif 80 81#define TULIP_HZ 10 82 83#define TULIP_SIAGEN_WATCHDOG 0 84 85#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL) 86 87#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0) 88#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0) 89 90#define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF) 91#define tulip_srom_crcok(databuf) ( \ 92 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \ 93 ((databuf)[126] | ((databuf)[127] << 8))) 94 95/* 96 * This is the PCI configuration support. Since the 21040 is available 97 * on both EISA and PCI boards, one must be careful in how defines the 98 * 21040 in the config file. 99 */ 100 101#define PCI_CFID 0x00 /* Configuration ID */ 102#define PCI_CFCS 0x04 /* Configurtion Command/Status */ 103#define PCI_CFRV 0x08 /* Configuration Revision */ 104#define PCI_CFLT 0x0c /* Configuration Latency Timer */ 105#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 106#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 107#define PCI_CFIT 0x3c /* Configuration Interrupt */ 108#define PCI_CFDA 0x40 /* Configuration Driver Area */ 109 110#define PCI_CONF_WRITE(r, v) pci_conf_write(pa->pa_pc, pa->pa_tag, (r), (v)) 111#define PCI_CONF_READ(r) pci_conf_read(pa->pa_pc, pa->pa_tag, (r)) 112#define PCI_GETBUSDEVINFO(sc) do { \ 113 (sc)->tulip_pci_busno = parent; \ 114 (sc)->tulip_pci_devno = pa->pa_device; \ 115 } while (0) 116 117#include <dev/pci/if_devar.h> 118/* 119 * This module supports 120 * the DEC 21040 PCI Ethernet Controller. 121 * the DEC 21041 PCI Ethernet Controller. 122 * the DEC 21140 PCI Fast Ethernet Controller. 123 */ 124int tulip_probe(struct device *parent, void *match, void *aux); 125void tulip_attach(struct device * const parent, struct device * const self, void * const aux); 126 127struct cfattach de_ca = { 128 sizeof(tulip_softc_t), tulip_probe, tulip_attach 129}; 130 131struct cfdriver de_cd = { 132 NULL, "de", DV_IFNET 133}; 134 135void tulip_timeout_callback(void *arg); 136void tulip_timeout(tulip_softc_t * const sc); 137int tulip_txprobe(tulip_softc_t * const sc); 138void tulip_media_set(tulip_softc_t * const sc, tulip_media_t media); 139void tulip_linkup(tulip_softc_t * const sc, tulip_media_t media); 140void tulip_media_print(tulip_softc_t * const sc); 141tulip_link_status_t tulip_media_link_monitor(tulip_softc_t * const sc); 142void tulip_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event); 143void tulip_media_select(tulip_softc_t * const sc); 144 145void tulip_21040_mediainfo_init(tulip_softc_t * const sc, tulip_media_t media); 146void tulip_21040_media_probe(tulip_softc_t * const sc); 147void tulip_21040_10baset_only_media_probe(tulip_softc_t * const sc); 148void tulip_21040_10baset_only_media_select(tulip_softc_t * const sc); 149void tulip_21040_auibnc_only_media_probe(tulip_softc_t * const sc); 150void tulip_21040_auibnc_only_media_select(tulip_softc_t * const sc); 151 152void tulip_21041_mediainfo_init(tulip_softc_t * const sc); 153void tulip_21041_media_probe(tulip_softc_t * const sc); 154void tulip_21041_media_poll(tulip_softc_t * const sc, const tulip_mediapoll_event_t event); 155 156tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc); 157unsigned tulip_mii_get_phyaddr(tulip_softc_t * const sc, unsigned offset); 158int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities); 159void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr); 160 161void tulip_2114x_media_preset(tulip_softc_t * const sc); 162 163void tulip_null_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event); 164 165void tulip_21140_mediainit(tulip_softc_t * const sc, tulip_media_info_t * const mip, 166 tulip_media_t const media, unsigned gpdata, unsigned cmdmode); 167void tulip_21140_evalboard_media_probe(tulip_softc_t * const sc); 168void tulip_21140_accton_media_probe(tulip_softc_t * const sc); 169void tulip_21140_smc9332_media_probe(tulip_softc_t * const sc); 170void tulip_21140_cogent_em100_media_probe(tulip_softc_t * const sc); 171void tulip_21140_znyx_zx34x_media_probe(tulip_softc_t * const sc); 172 173void tulip_2114x_media_probe(tulip_softc_t * const sc); 174 175void tulip_delay_300ns(tulip_softc_t * const sc); 176void tulip_srom_idle(tulip_softc_t * const sc); 177void tulip_srom_read(tulip_softc_t * const sc); 178void tulip_mii_writebits(tulip_softc_t * const sc, unsigned data, unsigned bits); 179void tulip_mii_turnaround(tulip_softc_t * const sc, unsigned cmd); 180unsigned tulip_mii_readbits(tulip_softc_t * const sc); 181unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno); 182void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, 183 unsigned data); 184 185void tulip_identify_dec_nic(tulip_softc_t * const sc); 186void tulip_identify_znyx_nic(tulip_softc_t * const sc); 187void tulip_identify_smc_nic(tulip_softc_t * const sc); 188void tulip_identify_cogent_nic(tulip_softc_t * const sc); 189void tulip_identify_accton_nic(tulip_softc_t * const sc); 190void tulip_identify_asante_nic(tulip_softc_t * const sc); 191void tulip_identify_compex_nic(tulip_softc_t * const sc); 192 193int tulip_srom_decode(tulip_softc_t * const sc); 194int tulip_read_macaddr(tulip_softc_t * const sc); 195void tulip_ifmedia_add(tulip_softc_t * const sc); 196int tulip_ifmedia_change(struct ifnet * const ifp); 197void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req); 198void tulip_addr_filter(tulip_softc_t * const sc); 199void tulip_reset(tulip_softc_t * const sc); 200void tulip_init(tulip_softc_t * const sc); 201void tulip_rx_intr(tulip_softc_t * const sc); 202int tulip_tx_intr(tulip_softc_t * const sc); 203void tulip_print_abnormal_interrupt(tulip_softc_t * const sc, u_int32_t csr); 204void tulip_intr_handler(tulip_softc_t * const sc, int *progress_p); 205int tulip_intr_shared(void *arg); 206int tulip_intr_normal(void *arg); 207struct mbuf *tulip_mbuf_compress(struct mbuf *m); 208struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m, int); 209void tulip_txput_setup(tulip_softc_t * const sc); 210int tulip_ifioctl(struct ifnet * ifp, u_long cmd, caddr_t data); 211void tulip_ifstart(struct ifnet *ifp); 212void tulip_ifwatchdog(struct ifnet *ifp); 213int tulip_busdma_allocmem(tulip_softc_t * const sc, size_t size, 214 bus_dmamap_t *map_p, tulip_desc_t **desc_p); 215int tulip_busdma_init(tulip_softc_t * const sc); 216void tulip_initcsrs(tulip_softc_t * const sc, bus_addr_t csr_base, size_t csr_size); 217void tulip_initring(tulip_softc_t * const sc, tulip_ringinfo_t * const ri, 218 tulip_desc_t *descs, int ndescs); 219 220bus_dmamap_t tulip_alloc_rxmap(tulip_softc_t *); 221void tulip_free_rxmap(tulip_softc_t *, bus_dmamap_t); 222bus_dmamap_t tulip_alloc_txmap(tulip_softc_t *); 223void tulip_free_txmap(tulip_softc_t *, bus_dmamap_t); 224 225void 226tulip_timeout_callback(void *arg) 227{ 228 tulip_softc_t * const sc = arg; 229 int s; 230 231 s = splnet(); 232 233 TULIP_PERFSTART(timeout) 234 235 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; 236 sc->tulip_probe_timeout -= 1000 / TULIP_HZ; 237 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); 238 239 TULIP_PERFEND(timeout); 240 splx(s); 241} 242 243void 244tulip_timeout(tulip_softc_t * const sc) 245{ 246 if (sc->tulip_flags & TULIP_TIMEOUTPENDING) 247 return; 248 sc->tulip_flags |= TULIP_TIMEOUTPENDING; 249 timeout_add(&sc->tulip_stmo, (hz + TULIP_HZ / 2) / TULIP_HZ); 250} 251 252int 253tulip_txprobe(tulip_softc_t * const sc) 254{ 255 struct mbuf *m; 256 257 /* 258 * Before we are sure this is the right media we need 259 * to send a small packet to make sure there's carrier. 260 * Strangely, BNC and AUI will "see" receive data if 261 * either is connected so the transmit is the only way 262 * to verify the connectivity. 263 */ 264 MGETHDR(m, M_DONTWAIT, MT_DATA); 265 if (m == NULL) 266 return (0); 267 /* 268 * Construct a LLC TEST message which will point to ourselves. 269 */ 270 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 271 ETHER_ADDR_LEN); 272 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 273 ETHER_ADDR_LEN); 274 mtod(m, struct ether_header *)->ether_type = htons(3); 275 mtod(m, unsigned char *)[14] = 0; 276 mtod(m, unsigned char *)[15] = 0; 277 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */ 278 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; 279 /* 280 * send it! 281 */ 282 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 283 sc->tulip_intrmask |= TULIP_STS_TXINTR; 284 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; 285 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 286 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 287 if ((m = tulip_txput(sc, m, 1)) != NULL) 288 m_freem(m); 289 sc->tulip_probe.probe_txprobes++; 290 return (1); 291} 292 293void 294tulip_media_set(tulip_softc_t * const sc, tulip_media_t media) 295{ 296 const tulip_media_info_t *mi = sc->tulip_mediums[media]; 297 298 if (mi == NULL) 299 return; 300 301 /* Reset the SIA first 302 */ 303 if (mi->mi_type == TULIP_MEDIAINFO_SIA || (sc->tulip_features & TULIP_HAVE_SIANWAY)) 304 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 305 306 /* Next, set full duplex if needed. 307 */ 308 if (sc->tulip_flags & TULIP_FULLDUPLEX) { 309#ifdef TULIP_DEBUG 310 if (TULIP_CSR_READ(sc, csr_command) & (TULIP_CMD_RXRUN|TULIP_CMD_TXRUN)) 311 printf(TULIP_PRINTF_FMT ": warning: board is running (FD).\n", TULIP_PRINTF_ARGS); 312 if ((TULIP_CSR_READ(sc, csr_command) & TULIP_CMD_FULLDUPLEX) == 0) 313 printf(TULIP_PRINTF_FMT ": setting full duplex.\n", TULIP_PRINTF_ARGS); 314#endif 315 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 316 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~(TULIP_CMD_RXRUN|TULIP_CMD_TXRUN)); 317 } 318 319 /* Now setup the media. 320 * 321 * If we are switching media, make sure we don't think there's 322 * any stale RX activity 323 */ 324 sc->tulip_flags &= ~TULIP_RXACT; 325 if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 326 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx); 327 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 328 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 329 DELAY(50); 330 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 331 } else 332 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); 333 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity); 334 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 335 /* 336 * If the cmdmode bits don't match the currently operating mode, 337 * set the cmdmode appropriately and reset the chip. 338 */ 339 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 340 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 341 sc->tulip_cmdmode |= mi->mi_cmdmode; 342 tulip_reset(sc); 343 } 344 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 345 DELAY(10); 346 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata); 347 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { 348 /* 349 * If the cmdmode bits don't match the currently operating mode, 350 * set the cmdmode appropriately and reset the chip. 351 */ 352 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { 353 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 354 sc->tulip_cmdmode |= mi->mi_cmdmode; 355 tulip_reset(sc); 356 } 357 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol); 358 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata); 359 } else if (mi->mi_type == TULIP_MEDIAINFO_MII 360 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) { 361 int idx; 362 if (sc->tulip_features & TULIP_HAVE_SIAGP) { 363 const u_int8_t *dp; 364 dp = &sc->tulip_rombuf[mi->mi_reset_offset]; 365 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) { 366 DELAY(10); 367 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 368 } 369 sc->tulip_phyaddr = mi->mi_phyaddr; 370 dp = &sc->tulip_rombuf[mi->mi_gpr_offset]; 371 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) { 372 DELAY(10); 373 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); 374 } 375 } else { 376 for (idx = 0; idx < mi->mi_reset_length; idx++) { 377 DELAY(10); 378 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]); 379 } 380 sc->tulip_phyaddr = mi->mi_phyaddr; 381 for (idx = 0; idx < mi->mi_gpr_length; idx++) { 382 DELAY(10); 383 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]); 384 } 385 } 386 387 if (sc->tulip_features & TULIP_HAVE_SIANWAY) { 388 /* Set the SIA port into MII mode */ 389 TULIP_CSR_WRITE(sc, csr_sia_general, 1); 390 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, 0); 391 TULIP_CSR_WRITE(sc, csr_sia_status, 0); 392 } 393 394 if (sc->tulip_flags & TULIP_TRYNWAY) 395 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 396 else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { 397 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL); 398 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE); 399 sc->tulip_flags &= ~TULIP_DIDNWAY; 400 if (TULIP_IS_MEDIA_FD(media)) 401 data |= PHYCTL_FULL_DUPLEX; 402 if (TULIP_IS_MEDIA_100MB(media)) 403 data |= PHYCTL_SELECT_100MB; 404 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data); 405 } 406 } 407} 408 409void 410tulip_linkup(tulip_softc_t * const sc, tulip_media_t media) 411{ 412 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 413 sc->tulip_flags |= TULIP_PRINTLINKUP; 414 sc->tulip_flags |= TULIP_LINKUP; 415 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 416 if (sc->tulip_media != media) { 417#ifdef TULIP_DEBUG 418 sc->tulip_dbg.dbg_last_media = sc->tulip_media; 419#endif 420 sc->tulip_media = media; 421 sc->tulip_flags |= TULIP_PRINTMEDIA; 422 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) 423 sc->tulip_flags |= TULIP_FULLDUPLEX; 424 else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) 425 sc->tulip_flags &= ~TULIP_FULLDUPLEX; 426 } 427 /* 428 * We could set probe_timeout to 0 but setting to 3000 puts this 429 * in one central place and the only matters is tulip_link is 430 * followed by a tulip_timeout. Therefore setting it should not 431 * result in aberrant behavour. 432 */ 433 sc->tulip_probe_timeout = 3000; 434 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 435 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY); 436 if (sc->tulip_flags & TULIP_INRESET) 437 tulip_media_set(sc, sc->tulip_media); 438 else if (sc->tulip_probe_media != sc->tulip_media) { 439 /* 440 * No reason to change media if we have the right media. 441 */ 442 tulip_reset(sc); 443 } 444 tulip_init(sc); 445} 446 447void 448tulip_media_print(tulip_softc_t * const sc) 449{ 450 if ((sc->tulip_flags & TULIP_LINKUP) == 0) 451 return; 452 if (sc->tulip_flags & TULIP_PRINTMEDIA) { 453#ifdef TULIP_DEBUG 454 printf(TULIP_PRINTF_FMT ": enabling %s port\n", 455 TULIP_PRINTF_ARGS, 456 tulip_mediums[sc->tulip_media]); 457#endif 458 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 459 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) { 460#ifdef TULIP_DEBUG 461 printf(TULIP_PRINTF_FMT ": link up\n", TULIP_PRINTF_ARGS); 462#endif 463 sc->tulip_flags &= ~TULIP_PRINTLINKUP; 464 } 465} 466 467tulip_link_status_t 468tulip_media_link_monitor(tulip_softc_t * const sc) 469{ 470 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media]; 471 tulip_link_status_t linkup = TULIP_LINK_DOWN; 472 473 if (mi == NULL) { 474#if defined(TULIP_DEBUG) 475 printf("tulip_media_link_monitor: %s: botch at line %d\n", 476 tulip_mediums[sc->tulip_media],__LINE__); 477#endif 478 return (TULIP_LINK_UNKNOWN); 479 } 480 481 482 /* 483 * Have we seen some packets? If so, the link must be good. 484 */ 485 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) { 486 sc->tulip_flags &= ~TULIP_RXACT; 487 sc->tulip_probe_timeout = 3000; 488 return (TULIP_LINK_UP); 489 } 490 491 sc->tulip_flags &= ~TULIP_RXACT; 492 if (mi->mi_type == TULIP_MEDIAINFO_MII) { 493 u_int32_t status; 494 /* 495 * Read the PHY status register. 496 */ 497 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS) 498 | tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 499 if (status & PHYSTS_AUTONEG_DONE) { 500 /* 501 * If the PHY has completed autonegotiation, see the if the 502 * remote systems abilities have changed. If so, upgrade or 503 * downgrade as appropriate. 504 */ 505 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES); 506 abilities = (abilities << 6) & status; 507 if (abilities != sc->tulip_abilities) { 508#if defined(TULIP_DEBUG) 509 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n", 510 TULIP_PRINTF_ARGS, sc->tulip_phyaddr, 511 sc->tulip_abilities, abilities); 512#endif 513 if (tulip_mii_map_abilities(sc, abilities)) { 514 tulip_linkup(sc, sc->tulip_probe_media); 515 return (TULIP_LINK_UP); 516 } 517 /* 518 * if we had selected media because of autonegotiation, 519 * we need to probe for the new media. 520 */ 521 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 522 if (sc->tulip_flags & TULIP_DIDNWAY) 523 return (TULIP_LINK_DOWN); 524 } 525 } 526 /* 527 * The link is now up. If was down, say its back up. 528 */ 529 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP) 530 linkup = TULIP_LINK_UP; 531 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { 532 /* 533 * No activity sensor? Assume all's well. 534 */ 535 if (mi->mi_actmask == 0) 536 return (TULIP_LINK_UNKNOWN); 537 /* 538 * Does the activity data match? 539 */ 540 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata) 541 linkup = TULIP_LINK_UP; 542 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { 543 /* 544 * Assume non TP ok for now. 545 */ 546 if (!TULIP_IS_MEDIA_TP(sc->tulip_media)) 547 return (TULIP_LINK_UNKNOWN); 548 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0) 549 linkup = TULIP_LINK_UP; 550#if defined(TULIP_DEBUG) 551 if (sc->tulip_probe_timeout <= 0) 552 printf(TULIP_PRINTF_FMT ": sia status = 0x%08x\n", TULIP_PRINTF_ARGS, TULIP_CSR_READ(sc, csr_sia_status)); 553#endif 554 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) 555 return (TULIP_LINK_UNKNOWN); 556 /* 557 * We will wait for 3 seconds until the link goes into suspect mode. 558 */ 559 if (sc->tulip_flags & TULIP_LINKUP) { 560 if (linkup == TULIP_LINK_UP) 561 sc->tulip_probe_timeout = 3000; 562 if (sc->tulip_probe_timeout > 0) 563 return (TULIP_LINK_UP); 564 565 sc->tulip_flags &= ~TULIP_LINKUP; 566 } 567#if defined(TULIP_DEBUG) 568 sc->tulip_dbg.dbg_link_downed++; 569#endif 570 return (TULIP_LINK_DOWN); 571} 572 573void 574tulip_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event) 575{ 576#if defined(TULIP_DEBUG) 577 sc->tulip_dbg.dbg_events[event]++; 578#endif 579 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE 580 && event == TULIP_MEDIAPOLL_TIMER) { 581 switch (tulip_media_link_monitor(sc)) { 582 case TULIP_LINK_DOWN: { 583 /* 584 * Link Monitor failed. Probe for new media. 585 */ 586 event = TULIP_MEDIAPOLL_LINKFAIL; 587 break; 588 } 589 case TULIP_LINK_UP: { 590 /* 591 * Check again soon. 592 */ 593 tulip_timeout(sc); 594 return; 595 } 596 case TULIP_LINK_UNKNOWN: { 597 /* 598 * We can't tell so don't bother. 599 */ 600 return; 601 } 602 } 603 } 604 605 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 606 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) { 607 if (TULIP_DO_AUTOSENSE(sc)) { 608#if defined(TULIP_DEBUG) 609 sc->tulip_dbg.dbg_link_failures++; 610#endif 611 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 612 if (sc->tulip_if.if_flags & IFF_UP) 613 tulip_reset(sc); /* restart probe */ 614 } 615 return; 616 } 617#if defined(TULIP_DEBUG) 618 sc->tulip_dbg.dbg_link_pollintrs++; 619#endif 620 } 621 622 if (event == TULIP_MEDIAPOLL_START) { 623 sc->tulip_if.if_flags |= IFF_OACTIVE; 624 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE) 625 return; 626 sc->tulip_probe_mediamask = 0; 627 sc->tulip_probe_passes = 0; 628#if defined(TULIP_DEBUG) 629 sc->tulip_dbg.dbg_media_probes++; 630#endif 631 /* 632 * If the SROM contained an explicit media to use, use it. 633 */ 634 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX); 635 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS; 636 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); 637 /* 638 * connidx is defaulted to a media_unknown type. 639 */ 640 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media; 641 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) { 642 tulip_linkup(sc, sc->tulip_probe_media); 643 tulip_timeout(sc); 644 return; 645 } 646 647 if (sc->tulip_features & TULIP_HAVE_GPR) { 648 sc->tulip_probe_state = TULIP_PROBE_GPRTEST; 649 sc->tulip_probe_timeout = 2000; 650 } else { 651 sc->tulip_probe_media = TULIP_MEDIA_MAX; 652 sc->tulip_probe_timeout = 0; 653 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 654 } 655 } 656 657 /* 658 * Ignore txprobe failures or spurious callbacks. 659 */ 660 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED 661 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) { 662 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 663 return; 664 } 665 666 /* 667 * If we really transmitted a packet, then that's the media we'll use. 668 */ 669 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) { 670 if (event == TULIP_MEDIAPOLL_LINKPASS) { 671 /* XXX Check media status just to be sure */ 672 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 673#if defined(TULIP_DEBUG) 674 } else { 675 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 676#endif 677 } 678 tulip_linkup(sc, sc->tulip_probe_media); 679 tulip_timeout(sc); 680 return; 681 } 682 683 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) { 684 /* 685 * Brute force. We cycle through each of the media types 686 * and try to transmit a packet. 687 */ 688 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 689 sc->tulip_probe_media = TULIP_MEDIA_MAX; 690 sc->tulip_probe_timeout = 0; 691 tulip_timeout(sc); 692 return; 693 } 694 695 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST 696 && (sc->tulip_features & TULIP_HAVE_MII)) { 697 tulip_media_t old_media = sc->tulip_probe_media; 698 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); 699 switch (sc->tulip_probe_state) { 700 case TULIP_PROBE_FAILED: 701 case TULIP_PROBE_MEDIATEST: { 702 /* 703 * Try the next media. 704 */ 705 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask; 706 sc->tulip_probe_timeout = 0; 707 break; 708 } 709 case TULIP_PROBE_PHYAUTONEG: { 710 return; 711 } 712 case TULIP_PROBE_INACTIVE: { 713 /* 714 * Only probe if we autonegotiated a media that hasn't failed. 715 */ 716 sc->tulip_probe_timeout = 0; 717 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) { 718 sc->tulip_probe_media = old_media; 719 break; 720 } 721 tulip_linkup(sc, sc->tulip_probe_media); 722 tulip_timeout(sc); 723 return; 724 } 725 default: { 726#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) 727 printf("tulip_media_poll: botch at line %d\n", __LINE__); 728#endif 729 break; 730 } 731 } 732 } 733 734 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) { 735#if defined(TULIP_DEBUG) 736 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++; 737#endif 738 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 739 return; 740 } 741 742 /* 743 * Switch to another media if we tried this one enough. 744 */ 745 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) { 746#if defined(TULIP_DEBUG) 747 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 748 printf(TULIP_PRINTF_FMT ": poll media unknown!\n", 749 TULIP_PRINTF_ARGS); 750 sc->tulip_probe_media = TULIP_MEDIA_MAX; 751 } 752#endif 753 /* 754 * Find the next media type to check for. Full Duplex 755 * types are not allowed. 756 */ 757 do { 758 sc->tulip_probe_media -= 1; 759 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { 760 if (++sc->tulip_probe_passes == 3) { 761 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 762 sc->tulip_if.if_flags &= ~IFF_RUNNING; 763 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 764 return; 765 } 766 } 767 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */ 768 sc->tulip_probe_mediamask = 0; 769 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1; 770 } 771 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL 772 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) 773 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media)); 774 775#if defined(TULIP_DEBUG) 776 printf(TULIP_PRINTF_FMT ": %s: probing %s\n", TULIP_PRINTF_ARGS, 777 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout", 778 tulip_mediums[sc->tulip_probe_media]); 779#endif 780 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000; 781 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 782 sc->tulip_probe.probe_txprobes = 0; 783 tulip_reset(sc); 784 tulip_media_set(sc, sc->tulip_probe_media); 785 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 786 } 787 tulip_timeout(sc); 788 789 /* 790 * If this is hanging off a phy, we know are doing NWAY and we have 791 * forced the phy to a specific speed. Wait for link up before 792 * before sending a packet. 793 */ 794 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) { 795 case TULIP_MEDIAINFO_MII: { 796 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) 797 return; 798 break; 799 } 800 case TULIP_MEDIAINFO_SIA: { 801 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) { 802 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) 803 return; 804 tulip_linkup(sc, sc->tulip_probe_media); 805 return; 806 } 807 break; 808 } 809 case TULIP_MEDIAINFO_RESET: 810 case TULIP_MEDIAINFO_SYM: 811 case TULIP_MEDIAINFO_NONE: 812 case TULIP_MEDIAINFO_GPR: { 813 break; 814 } 815 } 816 /* 817 * Try to send a packet. 818 */ 819 tulip_txprobe(sc); 820} 821 822void 823tulip_media_select(tulip_softc_t * const sc) 824{ 825 if (sc->tulip_features & TULIP_HAVE_GPR) { 826 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); 827 DELAY(10); 828 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata); 829 } 830 /* 831 * If this board has no media, just return 832 */ 833 if (sc->tulip_features & TULIP_HAVE_NOMEDIA) 834 return; 835 836 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 837 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 838 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START); 839 } else 840 tulip_media_set(sc, sc->tulip_media); 841} 842 843void 844tulip_21040_mediainfo_init(tulip_softc_t * const sc, tulip_media_t media) 845{ 846 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 847 |TULIP_CMD_BACKOFFCTR; 848 sc->tulip_if.if_baudrate = 10000000; 849 850 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) { 851 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET); 852 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD); 853 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 854 } 855 856 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) 857 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC); 858 859 if (media == TULIP_MEDIA_UNKNOWN) 860 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA); 861} 862 863void 864tulip_21040_media_probe(tulip_softc_t * const sc) 865{ 866 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN); 867} 868 869void 870tulip_21040_10baset_only_media_probe(tulip_softc_t * const sc) 871{ 872 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET); 873 tulip_media_set(sc, TULIP_MEDIA_10BASET); 874 sc->tulip_media = TULIP_MEDIA_10BASET; 875} 876 877void 878tulip_21040_10baset_only_media_select(tulip_softc_t * const sc) 879{ 880 sc->tulip_flags |= TULIP_LINKUP; 881 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) { 882 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; 883 sc->tulip_flags &= ~TULIP_SQETEST; 884 } else { 885 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 886 sc->tulip_flags |= TULIP_SQETEST; 887 } 888 tulip_media_set(sc, sc->tulip_media); 889} 890 891void 892tulip_21040_auibnc_only_media_probe(tulip_softc_t * const sc) 893{ 894 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC); 895 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP; 896 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 897 sc->tulip_media = TULIP_MEDIA_AUIBNC; 898} 899 900void 901tulip_21040_auibnc_only_media_select(tulip_softc_t * const sc) 902{ 903 tulip_media_set(sc, TULIP_MEDIA_AUIBNC); 904 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; 905} 906 907static const tulip_boardsw_t tulip_21040_boardsw = { 908 TULIP_21040_GENERIC, 909 tulip_21040_media_probe, 910 tulip_media_select, 911 tulip_media_poll, 912}; 913 914static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = { 915 TULIP_21040_GENERIC, 916 tulip_21040_10baset_only_media_probe, 917 tulip_21040_10baset_only_media_select, 918 NULL, 919}; 920 921static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = { 922 TULIP_21040_GENERIC, 923 tulip_21040_auibnc_only_media_probe, 924 tulip_21040_auibnc_only_media_select, 925 NULL, 926}; 927 928void 929tulip_21041_mediainfo_init(tulip_softc_t * const sc) 930{ 931 tulip_media_info_t * const mi = sc->tulip_mediainfo; 932 933 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET); 934 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD); 935 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI); 936 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC); 937} 938 939void 940tulip_21041_media_probe(tulip_softc_t * const sc) 941{ 942 sc->tulip_if.if_baudrate = 10000000; 943 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT 944 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR; 945 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 946 tulip_21041_mediainfo_init(sc); 947} 948 949void 950tulip_21041_media_poll(tulip_softc_t * const sc, const tulip_mediapoll_event_t event) 951{ 952 u_int32_t sia_status; 953 954#if defined(TULIP_DEBUG) 955 sc->tulip_dbg.dbg_events[event]++; 956#endif 957 958 if (event == TULIP_MEDIAPOLL_LINKFAIL) { 959 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE 960 || !TULIP_DO_AUTOSENSE(sc)) 961 return; 962 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 963 tulip_reset(sc); /* start probe */ 964 return; 965 } 966 967 /* 968 * If we've been been asked to start a poll or link change interrupt 969 * restart the probe (and reset the tulip to a known state). 970 */ 971 if (event == TULIP_MEDIAPOLL_START) { 972 sc->tulip_if.if_flags |= IFF_OACTIVE; 973 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN); 974 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 975 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 976 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 977 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT; 978 tulip_media_set(sc, TULIP_MEDIA_10BASET); 979 tulip_timeout(sc); 980 return; 981 } 982 983 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 984 return; 985 986 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) { 987#if defined(TULIP_DEBUG) 988 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; 989#endif 990 tulip_linkup(sc, sc->tulip_probe_media); 991 return; 992 } 993 994 sia_status = TULIP_CSR_READ(sc, csr_sia_status); 995 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status); 996 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) { 997 if (sc->tulip_revinfo >= 0x20) { 998 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6))) 999 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1000 } 1001 /* 1002 * If the link has passed LinkPass, 10baseT is the 1003 * proper media to use. 1004 */ 1005 tulip_linkup(sc, sc->tulip_probe_media); 1006 return; 1007 } 1008 1009 /* 1010 * wait for up to 2.4 seconds for the link to reach pass state. 1011 * Only then start scanning the other media for activity. 1012 * choose media with receive activity over those without. 1013 */ 1014 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) { 1015 if (event != TULIP_MEDIAPOLL_TIMER) 1016 return; 1017 if (sc->tulip_probe_timeout > 0 1018 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) { 1019 tulip_timeout(sc); 1020 return; 1021 } 1022 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1023 sc->tulip_flags |= TULIP_WANTRXACT; 1024 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) 1025 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1026 else 1027 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1028 tulip_media_set(sc, sc->tulip_probe_media); 1029 tulip_timeout(sc); 1030 return; 1031 } 1032 1033 /* 1034 * If we failed, clear the txprobe active flag. 1035 */ 1036 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) 1037 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1038 1039 1040 if (event == TULIP_MEDIAPOLL_TIMER) { 1041 /* 1042 * If we've received something, then that's our link! 1043 */ 1044 if (sc->tulip_flags & TULIP_RXACT) { 1045 tulip_linkup(sc, sc->tulip_probe_media); 1046 return; 1047 } 1048 /* 1049 * if no txprobe active 1050 */ 1051 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0 1052 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0 1053 || (sia_status & TULIP_SIASTS_RXACTIVITY))) { 1054 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1055 tulip_txprobe(sc); 1056 tulip_timeout(sc); 1057 return; 1058 } 1059 /* 1060 * Take 2 passes through before deciding to not 1061 * wait for receive activity. Then take another 1062 * two passes before spitting out a warning. 1063 */ 1064 if (sc->tulip_probe_timeout <= 0) { 1065 if (sc->tulip_flags & TULIP_WANTRXACT) { 1066 sc->tulip_flags &= ~TULIP_WANTRXACT; 1067 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1068 } else { 1069 if ((sc->tulip_if.if_flags & IFF_UP) == 0) { 1070 sc->tulip_if.if_flags &= ~IFF_RUNNING; 1071 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1072 return; 1073 } 1074 } 1075 } 1076 } 1077 1078 /* 1079 * Since this media failed to probe, try the other one. 1080 */ 1081 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; 1082 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) 1083 sc->tulip_probe_media = TULIP_MEDIA_BNC; 1084 else 1085 sc->tulip_probe_media = TULIP_MEDIA_AUI; 1086 tulip_media_set(sc, sc->tulip_probe_media); 1087 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1088 tulip_timeout(sc); 1089} 1090 1091static const tulip_boardsw_t tulip_21041_boardsw = { 1092 TULIP_21041_GENERIC, 1093 tulip_21041_media_probe, 1094 tulip_media_select, 1095 tulip_21041_media_poll 1096}; 1097 1098static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = { 1099 { 0x20005c00, 0, /* 08-00-17 */ 1100 { 1101 { 0x19, 0x0040, 0x0040 }, /* 10TX */ 1102 { 0x19, 0x0040, 0x0000 }, /* 100TX */ 1103 }, 1104#if defined(TULIP_DEBUG) 1105 "NS DP83840", 1106#endif 1107 }, 1108 { 0x0281F400, 0, /* 00-A0-7D */ 1109 { 1110 { 0x12, 0x0010, 0x0000 }, /* 10T */ 1111 { 0 }, /* 100TX */ 1112 { 0x12, 0x0010, 0x0010 }, /* 100T4 */ 1113 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ 1114 }, 1115#if defined(TULIP_DEBUG) 1116 "Seeq 80C240" 1117#endif 1118 }, 1119 { 0x0281F400, 3, /* 00-A0-7D */ 1120 { 1121 { 0x12, 0x0080, 0x0000 }, /* 10T */ 1122 { 0x12, 0x0080, 0x0080 }, /* 100TX */ 1123 { 0 }, /* 100T4 */ 1124 { 0x12, 0x0040, 0x0040 }, /* FULL_DUPLEX */ 1125 }, 1126#if defined(TULIP_DEBUG) 1127 "Seeq 80225" 1128#endif 1129 }, 1130 { 0x0281F400, 0, /* 00-A0-BE */ 1131 { 1132 { 0x11, 0x8000, 0x0000 }, /* 10T */ 1133 { 0x11, 0x8000, 0x8000 }, /* 100TX */ 1134 { 0 }, /* 100T4 */ 1135 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */ 1136 }, 1137#if defined(TULIP_DEBUG) 1138 "ICS 1890" 1139#endif 1140 }, 1141 { 0x78100000, 0, /* 00-A0-CC */ 1142 { 1143 { 0x14, 0x0800, 0x0000 }, /* 10TX */ 1144 { 0x14, 0x0800, 0x0800 }, /* 100TX */ 1145 { 0 }, /* 100T4 */ 1146 { 0x14, 0x1000, 0x1000 }, /* FULL_DUPLEX */ 1147 }, 1148#if defined(TULIP_DEBUG) 1149 "LEVEL1 LXT970" 1150#endif 1151 }, 1152 { 0 } 1153}; 1154 1155tulip_media_t 1156tulip_mii_phy_readspecific(tulip_softc_t * const sc) 1157{ 1158 const tulip_phy_attr_t *attr; 1159 u_int16_t data; 1160 u_int32_t id; 1161 unsigned idx = 0; 1162 static const tulip_media_t table[] = { 1163 TULIP_MEDIA_UNKNOWN, 1164 TULIP_MEDIA_10BASET, 1165 TULIP_MEDIA_100BASETX, 1166 TULIP_MEDIA_100BASET4, 1167 TULIP_MEDIA_UNKNOWN, 1168 TULIP_MEDIA_10BASET_FD, 1169 TULIP_MEDIA_100BASETX_FD, 1170 TULIP_MEDIA_UNKNOWN 1171 }; 1172 1173 /* 1174 * Don't read phy specific registers if link is not up. 1175 */ 1176 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS) 1177 | tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); 1178 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) 1179 return (TULIP_MEDIA_UNKNOWN); 1180 1181 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) | 1182 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH); 1183 for (attr = tulip_mii_phy_attrlist;; attr++) { 1184 if (attr->attr_id == 0) 1185 return (TULIP_MEDIA_UNKNOWN); 1186 if ((id & ~0x0F) == attr->attr_id) 1187 break; 1188 } 1189 1190 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) { 1191 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX]; 1192 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1193 if ((data & pm->pm_mask) == pm->pm_value) 1194 idx = 2; 1195 } 1196 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) { 1197 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4]; 1198 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1199 if ((data & pm->pm_mask) == pm->pm_value) 1200 idx = 3; 1201 } 1202 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) { 1203 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T]; 1204 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1205 if ((data & pm->pm_mask) == pm->pm_value) 1206 idx = 1; 1207 } 1208 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) { 1209 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX]; 1210 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); 1211 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0); 1212 } 1213 return (table[idx]); 1214} 1215 1216unsigned 1217tulip_mii_get_phyaddr(tulip_softc_t * const sc, unsigned offset) 1218{ 1219 unsigned phyaddr; 1220 1221 for (phyaddr = 1; phyaddr < 32; phyaddr++) { 1222 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1223 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1224 continue; 1225 if (offset == 0) 1226 return (phyaddr); 1227 offset--; 1228 } 1229 if (offset == 0) { 1230 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS); 1231 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) 1232 return (TULIP_MII_NOPHY); 1233 return (0); 1234 } 1235 return (TULIP_MII_NOPHY); 1236} 1237 1238int 1239tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities) 1240{ 1241 sc->tulip_abilities = abilities; 1242 if (abilities & PHYSTS_100BASETX_FD) 1243 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD; 1244 else if (abilities & PHYSTS_100BASET4) 1245 sc->tulip_probe_media = TULIP_MEDIA_100BASET4; 1246 else if (abilities & PHYSTS_100BASETX) 1247 sc->tulip_probe_media = TULIP_MEDIA_100BASETX; 1248 else if (abilities & PHYSTS_10BASET_FD) 1249 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; 1250 else if (abilities & PHYSTS_10BASET) 1251 sc->tulip_probe_media = TULIP_MEDIA_10BASET; 1252 else { 1253 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1254 return (0); 1255 } 1256 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 1257 return (1); 1258} 1259 1260void 1261tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr) 1262{ 1263 switch (sc->tulip_probe_state) { 1264 case TULIP_PROBE_MEDIATEST: 1265 case TULIP_PROBE_INACTIVE: { 1266 sc->tulip_flags |= TULIP_DIDNWAY; 1267 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET); 1268 sc->tulip_probe_timeout = 3000; 1269 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR; 1270 sc->tulip_probe_state = TULIP_PROBE_PHYRESET; 1271 /* FALLTHROUGH */ 1272 } 1273 case TULIP_PROBE_PHYRESET: { 1274 u_int32_t status; 1275 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1276 if (data & PHYCTL_RESET) { 1277 if (sc->tulip_probe_timeout > 0) { 1278 tulip_timeout(sc); 1279 return; 1280 } 1281#ifdef TULIP_DEBUG 1282 printf(TULIP_PRINTF_FMT "(phy%d): error: reset of PHY never completed!\n", 1283 TULIP_PRINTF_ARGS, phyaddr); 1284#endif 1285 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; 1286 sc->tulip_probe_state = TULIP_PROBE_FAILED; 1287 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING); 1288 return; 1289 } 1290 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS) 1291 | tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1292 if ((status & PHYSTS_CAN_AUTONEG) == 0) { 1293#if defined(TULIP_DEBUG) 1294 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation disabled\n", 1295 TULIP_PRINTF_ARGS, phyaddr); 1296#endif 1297 sc->tulip_flags &= ~TULIP_DIDNWAY; 1298 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1299 return; 1300 } 1301 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01)) 1302 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01); 1303 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE); 1304 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); 1305#if defined(TULIP_DEBUG) 1306 if ((data & PHYCTL_AUTONEG_ENABLE) == 0) 1307 printf(TULIP_PRINTF_FMT "(phy%d): oops: enable autonegotiation failed: 0x%04x\n", 1308 TULIP_PRINTF_ARGS, phyaddr, data); 1309 else 1310 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation restarted: 0x%04x (ad=0x%04x)\n", 1311 TULIP_PRINTF_ARGS, phyaddr, data, 1312 tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT)); 1313 sc->tulip_dbg.dbg_nway_starts++; 1314#endif 1315 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG; 1316 sc->tulip_probe_timeout = 3000; 1317 /* FALLTHROUGH */ 1318 } 1319 case TULIP_PROBE_PHYAUTONEG: { 1320 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS) 1321 | tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); 1322 u_int32_t data; 1323 if ((status & PHYSTS_AUTONEG_DONE) == 0) { 1324 if (sc->tulip_probe_timeout > 0) { 1325 tulip_timeout(sc); 1326 return; 1327 } 1328#if defined(TULIP_DEBUG) 1329 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n", 1330 TULIP_PRINTF_ARGS, phyaddr, status, 1331 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL)); 1332#endif 1333 sc->tulip_flags &= ~TULIP_DIDNWAY; 1334 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; 1335 return; 1336 } 1337 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES) 1338 | tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES); 1339#if defined(TULIP_DEBUG) 1340 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation complete: 0x%04x (sts=0x%04x)\n", 1341 TULIP_PRINTF_ARGS, phyaddr, data, status); 1342#endif 1343 data = (data << 6) & status; 1344 if (!tulip_mii_map_abilities(sc, data)) 1345 sc->tulip_flags &= ~TULIP_DIDNWAY; 1346 return; 1347 } 1348 default: { 1349#if defined(DIAGNOSTIC) 1350 printf("tulip_media_poll: botch at line %d\n", __LINE__); 1351#endif 1352 break; 1353 } 1354 } 1355#if defined(TULIP_DEBUG) 1356 printf(TULIP_PRINTF_FMT "(phy%d): autonegotiation failure: state = %d\n", 1357 TULIP_PRINTF_ARGS, phyaddr, sc->tulip_probe_state); 1358 sc->tulip_dbg.dbg_nway_failures++; 1359#endif 1360} 1361 1362void 1363tulip_2114x_media_preset(tulip_softc_t * const sc) 1364{ 1365 const tulip_media_info_t *mi = NULL; 1366 tulip_media_t media = sc->tulip_media; 1367 1368 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) 1369 media = sc->tulip_media; 1370 else 1371 media = sc->tulip_probe_media; 1372 1373 sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT|TULIP_CMD_NOHEARTBEAT 1374 |TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL); 1375 sc->tulip_flags &= ~(TULIP_SQETEST|TULIP_FULLDUPLEX); 1376 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) { 1377#if defined(TULIP_DEBUG) 1378 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) { 1379#endif 1380 mi = sc->tulip_mediums[media]; 1381 if (mi->mi_type == TULIP_MEDIAINFO_MII) 1382 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1383 else if (mi->mi_type == TULIP_MEDIAINFO_GPR 1384 || mi->mi_type == TULIP_MEDIAINFO_SYM) { 1385 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; 1386 sc->tulip_cmdmode |= mi->mi_cmdmode; 1387 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) 1388 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); 1389#if defined(TULIP_DEBUG) 1390 } else { 1391 printf(TULIP_PRINTF_FMT ": preset: bad media %d!\n", 1392 TULIP_PRINTF_ARGS, media); 1393 } 1394#endif 1395 } 1396 switch (media) { 1397 case TULIP_MEDIA_BNC: 1398 case TULIP_MEDIA_AUI: 1399 case TULIP_MEDIA_10BASET: { 1400 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 1401 sc->tulip_if.if_baudrate = 10000000; 1402 sc->tulip_flags |= TULIP_SQETEST; 1403 break; 1404 } 1405 case TULIP_MEDIA_10BASET_FD: { 1406 sc->tulip_flags |= TULIP_FULLDUPLEX; 1407 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX; 1408 sc->tulip_if.if_baudrate = 10000000; 1409 break; 1410 } 1411 case TULIP_MEDIA_100BASEFX: 1412 case TULIP_MEDIA_100BASET4: 1413 case TULIP_MEDIA_100BASETX: { 1414 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; 1415 sc->tulip_if.if_baudrate = 100000000; 1416 if (mi->mi_type == TULIP_MEDIAINFO_SYM 1417 || mi->mi_type == TULIP_MEDIAINFO_MII) { 1418 sc->tulip_cmdmode |= TULIP_CMD_NOHEARTBEAT; 1419 } 1420 break; 1421 } 1422 case TULIP_MEDIA_100BASEFX_FD: 1423 case TULIP_MEDIA_100BASETX_FD: { 1424 sc->tulip_flags |= TULIP_FULLDUPLEX; 1425 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT|TULIP_CMD_FULLDUPLEX; 1426 sc->tulip_if.if_baudrate = 100000000; 1427 if (mi->mi_type == TULIP_MEDIAINFO_SYM 1428 || mi->mi_type == TULIP_MEDIAINFO_MII) { 1429 sc->tulip_cmdmode |= TULIP_CMD_NOHEARTBEAT; 1430 } 1431 break; 1432 } 1433 default: { 1434 break; 1435 } 1436 } 1437 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 1438} 1439 1440/* 1441 ******************************************************************** 1442 * Start of 21140/21140A support which does not use the MII interface 1443 */ 1444 1445void 1446tulip_null_media_poll(tulip_softc_t * const sc, tulip_mediapoll_event_t event) 1447{ 1448#if defined(TULIP_DEBUG) 1449 sc->tulip_dbg.dbg_events[event]++; 1450#endif 1451#if defined(DIAGNOSTIC) 1452 printf(TULIP_PRINTF_FMT ": botch(media_poll) at line %d\n", 1453 TULIP_PRINTF_ARGS, __LINE__); 1454#endif 1455} 1456 1457void 1458tulip_21140_mediainit(tulip_softc_t * const sc, tulip_media_info_t * const mip, 1459 tulip_media_t const media, unsigned gpdata, unsigned cmdmode) 1460{ 1461 sc->tulip_mediums[media] = mip; 1462 mip->mi_type = TULIP_MEDIAINFO_GPR; 1463 mip->mi_cmdmode = cmdmode; 1464 mip->mi_gpdata = gpdata; 1465} 1466 1467void 1468tulip_21140_evalboard_media_probe(tulip_softc_t * const sc) 1469{ 1470 tulip_media_info_t *mip = sc->tulip_mediainfo; 1471 1472 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1473 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1474 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1475 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1476 TULIP_CSR_WRITE(sc, csr_command, 1477 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1478 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1479 TULIP_CSR_WRITE(sc, csr_command, 1480 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1481 DELAY(1000000); 1482 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) 1483 sc->tulip_media = TULIP_MEDIA_10BASET; 1484 else 1485 sc->tulip_media = TULIP_MEDIA_100BASETX; 1486 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1487 TULIP_GP_EB_INIT, 1488 TULIP_CMD_TXTHRSHLDCTL); 1489 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1490 TULIP_GP_EB_INIT, 1491 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1492 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1493 TULIP_GP_EB_INIT, 1494 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1495 |TULIP_CMD_SCRAMBLER); 1496 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1497 TULIP_GP_EB_INIT, 1498 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1499 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1500} 1501 1502static const tulip_boardsw_t tulip_21140_eb_boardsw = { 1503 TULIP_21140_DEC_EB, 1504 tulip_21140_evalboard_media_probe, 1505 tulip_media_select, 1506 tulip_null_media_poll, 1507 tulip_2114x_media_preset, 1508}; 1509 1510void 1511tulip_21140_accton_media_probe(tulip_softc_t * const sc) 1512{ 1513 tulip_media_info_t *mip = sc->tulip_mediainfo; 1514 unsigned gpdata; 1515 1516 sc->tulip_gpinit = TULIP_GP_EB_PINS; 1517 sc->tulip_gpdata = TULIP_GP_EB_INIT; 1518 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); 1519 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); 1520 TULIP_CSR_WRITE(sc, csr_command, 1521 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1522 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1523 TULIP_CSR_WRITE(sc, csr_command, 1524 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1525 DELAY(1000000); 1526 gpdata = TULIP_CSR_READ(sc, csr_gp); 1527 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) 1528 sc->tulip_media = TULIP_MEDIA_10BASET; 1529 else { 1530 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) 1531 sc->tulip_media = TULIP_MEDIA_BNC; 1532 else 1533 sc->tulip_media = TULIP_MEDIA_100BASETX; 1534 } 1535 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC, 1536 TULIP_GP_EN1207_BNC_INIT, 1537 TULIP_CMD_TXTHRSHLDCTL); 1538 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1539 TULIP_GP_EN1207_UTP_INIT, 1540 TULIP_CMD_TXTHRSHLDCTL); 1541 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1542 TULIP_GP_EN1207_UTP_INIT, 1543 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1544 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1545 TULIP_GP_EN1207_100_INIT, 1546 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1547 |TULIP_CMD_SCRAMBLER); 1548 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1549 TULIP_GP_EN1207_100_INIT, 1550 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1551 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1552} 1553 1554static const tulip_boardsw_t tulip_21140_accton_boardsw = { 1555 TULIP_21140_EN1207, 1556 tulip_21140_accton_media_probe, 1557 tulip_media_select, 1558 tulip_null_media_poll, 1559 tulip_2114x_media_preset, 1560}; 1561 1562void 1563tulip_21140_smc9332_media_probe(tulip_softc_t * const sc) 1564{ 1565 tulip_media_info_t *mip = sc->tulip_mediainfo; 1566 int idx, cnt = 0; 1567 1568 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE); 1569 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 1570 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 1571 33MHz that comes to two microseconds but wait a 1572 bit longer anyways) */ 1573 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT | 1574 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1575 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS; 1576 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT; 1577 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET); 1578 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT); 1579 DELAY(200000); 1580 for (idx = 1000; idx > 0; idx--) { 1581 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1582 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) { 1583 if (++cnt > 100) 1584 break; 1585 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) 1586 break; 1587 else 1588 cnt = 0; 1589 DELAY(1000); 1590 } 1591 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1592 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1593 TULIP_GP_SMC_9332_INIT, 1594 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1595 |TULIP_CMD_SCRAMBLER); 1596 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1597 TULIP_GP_SMC_9332_INIT, 1598 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1599 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1600 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1601 TULIP_GP_SMC_9332_INIT, 1602 TULIP_CMD_TXTHRSHLDCTL); 1603 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1604 TULIP_GP_SMC_9332_INIT, 1605 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1606} 1607 1608static const tulip_boardsw_t tulip_21140_smc9332_boardsw = { 1609 TULIP_21140_SMC_9332, 1610 tulip_21140_smc9332_media_probe, 1611 tulip_media_select, 1612 tulip_null_media_poll, 1613 tulip_2114x_media_preset, 1614}; 1615 1616void 1617tulip_21140_cogent_em100_media_probe(tulip_softc_t * const sc) 1618{ 1619 tulip_media_info_t *mip = sc->tulip_mediainfo; 1620 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command); 1621 1622 sc->tulip_gpinit = TULIP_GP_EM100_PINS; 1623 sc->tulip_gpdata = TULIP_GP_EM100_INIT; 1624 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS); 1625 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT); 1626 1627 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE; 1628 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER); 1629 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 1630 TULIP_CSR_WRITE(sc, csr_command, cmdmode); 1631 sc->tulip_media = TULIP_MEDIA_100BASEFX; 1632 1633 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX, 1634 TULIP_GP_EM100_INIT, 1635 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION); 1636 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD, 1637 TULIP_GP_EM100_INIT, 1638 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1639 |TULIP_CMD_FULLDUPLEX); 1640 } else { 1641 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER); 1642 sc->tulip_media = TULIP_MEDIA_100BASETX; 1643 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1644 TULIP_GP_EM100_INIT, 1645 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1646 |TULIP_CMD_SCRAMBLER); 1647 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1648 TULIP_GP_EM100_INIT, 1649 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1650 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1651 } 1652} 1653 1654static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = { 1655 TULIP_21140_COGENT_EM100, 1656 tulip_21140_cogent_em100_media_probe, 1657 tulip_media_select, 1658 tulip_null_media_poll, 1659 tulip_2114x_media_preset 1660}; 1661 1662void 1663tulip_21140_znyx_zx34x_media_probe(tulip_softc_t * const sc) 1664{ 1665 tulip_media_info_t *mip = sc->tulip_mediainfo; 1666 int cnt10 = 0, cnt100 = 0, idx; 1667 1668 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS; 1669 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT; 1670 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS); 1671 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT); 1672 TULIP_CSR_WRITE(sc, csr_command, 1673 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | 1674 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); 1675 TULIP_CSR_WRITE(sc, csr_command, 1676 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); 1677 1678 DELAY(200000); 1679 for (idx = 1000; idx > 0; idx--) { 1680 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); 1681 if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) { 1682 if (++cnt100 > 100) 1683 break; 1684 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) { 1685 if (++cnt10 > 100) 1686 break; 1687 } else { 1688 cnt10 = 0; 1689 cnt100 = 0; 1690 } 1691 DELAY(1000); 1692 } 1693 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; 1694 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, 1695 TULIP_GP_ZX34X_INIT, 1696 TULIP_CMD_TXTHRSHLDCTL); 1697 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, 1698 TULIP_GP_ZX34X_INIT, 1699 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); 1700 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, 1701 TULIP_GP_ZX34X_INIT, 1702 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1703 |TULIP_CMD_SCRAMBLER); 1704 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, 1705 TULIP_GP_ZX34X_INIT, 1706 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION 1707 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); 1708} 1709 1710static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = { 1711 TULIP_21140_ZNYX_ZX34X, 1712 tulip_21140_znyx_zx34x_media_probe, 1713 tulip_media_select, 1714 tulip_null_media_poll, 1715 tulip_2114x_media_preset, 1716}; 1717 1718void 1719tulip_2114x_media_probe(tulip_softc_t * const sc) 1720{ 1721 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE 1722 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72; 1723} 1724 1725static const tulip_boardsw_t tulip_2114x_isv_boardsw = { 1726 TULIP_21140_ISV, 1727 tulip_2114x_media_probe, 1728 tulip_media_select, 1729 tulip_media_poll, 1730 tulip_2114x_media_preset, 1731}; 1732 1733/* 1734 * ******** END of chip-specific handlers. *********** 1735 */ 1736 1737/* 1738 * Code the read the SROM and MII bit streams (I2C) 1739 */ 1740void 1741tulip_delay_300ns(tulip_softc_t * const sc) 1742{ 1743 int idx; 1744 for (idx = (300 / 33) + 1; idx > 0; idx--) 1745 (void) TULIP_CSR_READ(sc, csr_busmode); 1746} 1747 1748void 1749tulip_srom_idle(tulip_softc_t * const sc) 1750{ 1751 unsigned bit, csr; 1752 1753 csr = SROMSEL ; EMIT; 1754 csr = SROMSEL | SROMRD; EMIT; 1755 csr ^= SROMCS; EMIT; 1756 csr ^= SROMCLKON; EMIT; 1757 1758 /* 1759 * Write 25 cycles of 0 which will force the SROM to be idle. 1760 */ 1761 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 1762 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1763 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1764 } 1765 csr ^= SROMCLKOFF; EMIT; 1766 csr ^= SROMCS; EMIT; 1767 csr = 0; EMIT; 1768} 1769 1770void 1771tulip_srom_read(tulip_softc_t * const sc) 1772{ 1773 unsigned idx; 1774 const unsigned bitwidth = SROM_BITWIDTH; 1775 const unsigned cmdmask = (SROMCMD_RD << bitwidth); 1776 const unsigned msb = 1 << (bitwidth + 3 - 1); 1777 unsigned lastidx = (1 << bitwidth) - 1; 1778 1779 tulip_srom_idle(sc); 1780 1781 for (idx = 0; idx <= lastidx; idx++) { 1782 unsigned lastbit, data, bits, bit, csr; 1783 csr = SROMSEL ; EMIT; 1784 csr = SROMSEL | SROMRD; EMIT; 1785 csr ^= SROMCSON; EMIT; 1786 csr ^= SROMCLKON; EMIT; 1787 1788 lastbit = 0; 1789 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 1790 const unsigned thisbit = bits & msb; 1791 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1792 if (thisbit != lastbit) { 1793 csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 1794 } else { 1795 EMIT; 1796 } 1797 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1798 lastbit = thisbit; 1799 } 1800 csr ^= SROMCLKOFF; EMIT; 1801 1802 for (data = 0, bits = 0; bits < 16; bits++) { 1803 data <<= 1; 1804 csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 1805 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0; 1806 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 1807 } 1808 sc->tulip_rombuf[idx*2] = data & 0xFF; 1809 sc->tulip_rombuf[idx*2+1] = data >> 8; 1810 csr = SROMSEL | SROMRD; EMIT; 1811 csr = 0; EMIT; 1812 } 1813 tulip_srom_idle(sc); 1814} 1815 1816void 1817tulip_mii_writebits(tulip_softc_t * const sc, unsigned data, unsigned bits) 1818{ 1819 unsigned msb = 1 << (bits - 1); 1820 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1821 unsigned lastbit = (csr & MII_DOUT) ? msb : 0; 1822 1823 csr |= MII_WR; MII_EMIT; /* clock low; assert write */ 1824 1825 for (; bits > 0; bits--, data <<= 1) { 1826 const unsigned thisbit = data & msb; 1827 if (thisbit != lastbit) 1828 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */ 1829 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1830 lastbit = thisbit; 1831 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1832 } 1833} 1834 1835void 1836tulip_mii_turnaround(tulip_softc_t * const sc, unsigned cmd) 1837{ 1838 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1839 1840 if (cmd == MII_WRCMD) { 1841 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */ 1842 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1843 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1844 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */ 1845 } else 1846 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */ 1847 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1848 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1849} 1850 1851unsigned 1852tulip_mii_readbits(tulip_softc_t * const sc) 1853{ 1854 unsigned data; 1855 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1856 int idx; 1857 1858 for (idx = 0, data = 0; idx < 16; idx++) { 1859 data <<= 1; /* this is NOOP on the first pass through */ 1860 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ 1861 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN) 1862 data |= 1; 1863 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ 1864 } 1865 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */ 1866 1867 return (data); 1868} 1869 1870unsigned 1871tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno) 1872{ 1873 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1874 unsigned data; 1875 1876 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1877 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1878 tulip_mii_writebits(sc, MII_RDCMD, 8); 1879 tulip_mii_writebits(sc, devaddr, 5); 1880 tulip_mii_writebits(sc, regno, 5); 1881 tulip_mii_turnaround(sc, MII_RDCMD); 1882 1883 data = tulip_mii_readbits(sc); 1884#if defined(TULIP_DEBUG) 1885 sc->tulip_dbg.dbg_phyregs[regno][0] = data; 1886 sc->tulip_dbg.dbg_phyregs[regno][1]++; 1887#endif 1888 return (data); 1889} 1890 1891void 1892tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, 1893 unsigned regno, unsigned data) 1894{ 1895 unsigned csr; 1896 1897 csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); 1898 csr &= ~(MII_RD|MII_CLK); MII_EMIT; 1899 tulip_mii_writebits(sc, MII_PREAMBLE, 32); 1900 tulip_mii_writebits(sc, MII_WRCMD, 8); 1901 tulip_mii_writebits(sc, devaddr, 5); 1902 tulip_mii_writebits(sc, regno, 5); 1903 tulip_mii_turnaround(sc, MII_WRCMD); 1904 tulip_mii_writebits(sc, data, 16); 1905#if defined(TULIP_DEBUG) 1906 sc->tulip_dbg.dbg_phyregs[regno][2] = data; 1907 sc->tulip_dbg.dbg_phyregs[regno][3]++; 1908#endif 1909} 1910 1911void 1912tulip_identify_dec_nic(tulip_softc_t * const sc) 1913{ 1914 strlcpy(sc->tulip_boardid, "DEC ", sizeof(sc->tulip_boardid)); 1915#define D0 4 1916 if (sc->tulip_chipid <= TULIP_DE425) 1917 return; 1918 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0 1919 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) { 1920 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8); 1921 sc->tulip_boardid[D0+8] = ' '; 1922 } 1923#undef D0 1924} 1925 1926void 1927tulip_identify_znyx_nic(tulip_softc_t * const sc) 1928{ 1929 unsigned id = 0; 1930 strlcpy(sc->tulip_boardid, "ZNYX ZX3XX ", sizeof(sc->tulip_boardid)); 1931 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 1932 unsigned znyx_ptr; 1933 sc->tulip_boardid[8] = '4'; 1934 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125]; 1935 if (znyx_ptr < 26 || znyx_ptr > 116) { 1936 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 1937 return; 1938 } 1939 /* ZX344 = 0010 .. 0013FF 1940 */ 1941 if (sc->tulip_rombuf[znyx_ptr] == 0x4A 1942 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52 1943 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) { 1944 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4]; 1945 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) { 1946 sc->tulip_boardid[9] = '2'; 1947 if (id == TULIP_ZNYX_ID_ZX342B) { 1948 sc->tulip_boardid[10] = 'B'; 1949 sc->tulip_boardid[11] = ' '; 1950 } 1951 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 1952 } else if (id == TULIP_ZNYX_ID_ZX344) { 1953 sc->tulip_boardid[10] = '4'; 1954 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 1955 } else if (id == TULIP_ZNYX_ID_ZX345) { 1956 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5'; 1957 } else if (id == TULIP_ZNYX_ID_ZX346) { 1958 sc->tulip_boardid[9] = '6'; 1959 } else if (id == TULIP_ZNYX_ID_ZX351) { 1960 sc->tulip_boardid[8] = '5'; 1961 sc->tulip_boardid[9] = '1'; 1962 } 1963 } 1964 if (id == 0) { 1965 /* 1966 * Assume it's a ZX342... 1967 */ 1968 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; 1969 } 1970 return; 1971 } 1972 sc->tulip_boardid[8] = '1'; 1973 if (sc->tulip_chipid == TULIP_21041) { 1974 sc->tulip_boardid[10] = '1'; 1975 return; 1976 } 1977 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) { 1978 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36]; 1979 if (id == TULIP_ZNYX_ID_ZX312T) { 1980 sc->tulip_boardid[9] = '2'; 1981 sc->tulip_boardid[10] = 'T'; 1982 sc->tulip_boardid[11] = ' '; 1983 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 1984 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) { 1985 sc->tulip_boardid[9] = '4'; 1986 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 1987 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 1988 } else if (id == TULIP_ZNYX_ID_ZX314) { 1989 sc->tulip_boardid[9] = '4'; 1990 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 1991 sc->tulip_features |= TULIP_HAVE_BASEROM; 1992 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) { 1993 sc->tulip_boardid[9] = '5'; 1994 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 1995 } else if (id == TULIP_ZNYX_ID_ZX315) { 1996 sc->tulip_boardid[9] = '5'; 1997 sc->tulip_features |= TULIP_HAVE_BASEROM; 1998 } else 1999 id = 0; 2000 } 2001 if (id == 0) { 2002 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 3) == 0) { 2003 sc->tulip_boardid[9] = '4'; 2004 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2005 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2006 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) { 2007 sc->tulip_boardid[9] = '5'; 2008 sc->tulip_boardsw = &tulip_21040_boardsw; 2009 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2010 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) { 2011 sc->tulip_boardid[9] = '2'; 2012 sc->tulip_boardsw = &tulip_21040_boardsw; 2013 } 2014 } 2015} 2016 2017void 2018tulip_identify_smc_nic(tulip_softc_t * const sc) 2019{ 2020 u_int32_t id1, id2, ei; 2021 int auibnc = 0, utp = 0; 2022 char *cp; 2023 2024 strlcpy(sc->tulip_boardid, "SMC ", sizeof(sc->tulip_boardid)); 2025 if (sc->tulip_chipid == TULIP_21041) 2026 return; 2027 if (sc->tulip_chipid != TULIP_21040) { 2028 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2029 strlcat(sc->tulip_boardid, "9332DST ", sizeof(sc->tulip_boardid)); 2030 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw; 2031 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) 2032 strlcat(sc->tulip_boardid, "9334BDT ", sizeof(sc->tulip_boardid)); 2033 else 2034 strlcat(sc->tulip_boardid, "9332BDT ", sizeof(sc->tulip_boardid)); 2035 return; 2036 } 2037 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8); 2038 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8); 2039 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8); 2040 2041 strlcat(sc->tulip_boardid, "8432", sizeof(sc->tulip_boardid)); 2042 cp = &sc->tulip_boardid[8]; 2043 if ((id1 & 1) == 0) 2044 *cp++ = 'B', auibnc = 1; 2045 if ((id1 & 0xFF) > 0x32) 2046 *cp++ = 'T', utp = 1; 2047 if ((id1 & 0x4000) == 0) 2048 *cp++ = 'A', auibnc = 1; 2049 if (id2 == 0x15) { 2050 sc->tulip_boardid[7] = '4'; 2051 *cp++ = '-'; 2052 *cp++ = 'C'; 2053 *cp++ = 'H'; 2054 *cp++ = (ei ? '2' : '1'); 2055 } 2056 *cp++ = ' '; 2057 *cp = '\0'; 2058 if (utp && !auibnc) 2059 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; 2060 else if (!utp && auibnc) 2061 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw; 2062} 2063 2064void 2065tulip_identify_cogent_nic(tulip_softc_t * const sc) 2066{ 2067 strlcpy(sc->tulip_boardid, "Cogent ", sizeof(sc->tulip_boardid)); 2068 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { 2069 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) { 2070 strlcat(sc->tulip_boardid, "EM100TX ", sizeof(sc->tulip_boardid)); 2071 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2072#if defined(TULIP_COGENT_EM110TX_ID) 2073 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) { 2074 strlcat(sc->tulip_boardid, "EM110TX ", sizeof(sc->tulip_boardid)); 2075 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2076#endif 2077 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { 2078 strlcat(sc->tulip_boardid, "EM100FX ", sizeof(sc->tulip_boardid)); 2079 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; 2080 } 2081 /* 2082 * Magic number (0x24001109U) is the SubVendor (0x2400) and 2083 * SubDevId (0x1109) for the ANA6944TX (EM440TX). 2084 */ 2085 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U 2086 && (sc->tulip_features & TULIP_HAVE_BASEROM)) { 2087 /* 2088 * Cogent (Adaptec) is still mapping all INTs to INTA of 2089 * first 21140. Dumb! Dumb! 2090 */ 2091 strlcat(sc->tulip_boardid, "EM440TX ", sizeof(sc->tulip_boardid)); 2092 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2093 } 2094 } else if (sc->tulip_chipid == TULIP_21040) 2095 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; 2096} 2097 2098void 2099tulip_identify_accton_nic(tulip_softc_t * const sc) 2100{ 2101 strlcpy(sc->tulip_boardid, "ACCTON ", sizeof(sc->tulip_boardid)); 2102 switch (sc->tulip_chipid) { 2103 case TULIP_21140A: 2104 strlcat(sc->tulip_boardid, "EN1207 ", sizeof(sc->tulip_boardid)); 2105 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2106 sc->tulip_boardsw = &tulip_21140_accton_boardsw; 2107 break; 2108 case TULIP_21140: 2109 strlcat(sc->tulip_boardid, "EN1207TX ", sizeof(sc->tulip_boardid)); 2110 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) 2111 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2112 break; 2113 case TULIP_21040: 2114 strlcat(sc->tulip_boardid, "EN1203 ", sizeof(sc->tulip_boardid)); 2115 sc->tulip_boardsw = &tulip_21040_boardsw; 2116 break; 2117 case TULIP_21041: 2118 strlcat(sc->tulip_boardid, "EN1203 ", sizeof(sc->tulip_boardid)); 2119 sc->tulip_boardsw = &tulip_21041_boardsw; 2120 break; 2121 default: 2122 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2123 break; 2124 } 2125} 2126 2127void 2128tulip_identify_asante_nic(tulip_softc_t * const sc) 2129{ 2130 strlcpy(sc->tulip_boardid, "Asante ", sizeof(sc->tulip_boardid)); 2131 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) 2132 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { 2133 tulip_media_info_t *mi = sc->tulip_mediainfo; 2134 int idx; 2135 /* 2136 * The Asante Fast Ethernet doesn't always ship with a valid 2137 * new format SROM. So if isn't in the new format, we cheat 2138 * set it up as if we had. 2139 */ 2140 2141 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS; 2142 sc->tulip_gpdata = 0; 2143 2144 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET); 2145 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET); 2146 DELAY(100); 2147 TULIP_CSR_WRITE(sc, csr_gp, 0); 2148 2149 mi->mi_type = TULIP_MEDIAINFO_MII; 2150 mi->mi_gpr_length = 0; 2151 mi->mi_gpr_offset = 0; 2152 mi->mi_reset_length = 0; 2153 mi->mi_reset_offset = 0; 2154 2155 mi->mi_phyaddr = TULIP_MII_NOPHY; 2156 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) { 2157 DELAY(10000); 2158 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0); 2159 } 2160 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2161#ifdef TULIP_DEBUG 2162 printf(TULIP_PRINTF_FMT ": can't find phy 0\n", TULIP_PRINTF_ARGS); 2163#endif 2164 return; 2165 } 2166 2167 sc->tulip_features |= TULIP_HAVE_MII; 2168 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2169 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; 2170 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD; 2171 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD; 2172 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2173 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2174 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2175 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2176 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2177 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2178 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2179 2180 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2181 } 2182} 2183 2184void 2185tulip_identify_compex_nic(tulip_softc_t * const sc) 2186{ 2187 strlcpy(sc->tulip_boardid, "COMPEX ", sizeof(sc->tulip_boardid)); 2188 if (sc->tulip_chipid == TULIP_21140A) { 2189 int root_unit; 2190 tulip_softc_t *root_sc = NULL; 2191 2192 strlcat(sc->tulip_boardid, "400TX/PCI ", sizeof(sc->tulip_boardid)); 2193 /* 2194 * All 4 chips on these boards share an interrupt. This code 2195 * copied from tulip_read_macaddr. 2196 */ 2197 sc->tulip_features |= TULIP_HAVE_SHAREDINTR; 2198 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2199 root_sc = TULIP_UNIT_TO_SOFTC(root_unit); 2200 if (root_sc == NULL 2201 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR)) 2202 break; 2203 root_sc = NULL; 2204 } 2205 if (root_sc != NULL 2206 && root_sc->tulip_chipid == sc->tulip_chipid 2207 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2208 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2209 sc->tulip_slaves = root_sc->tulip_slaves; 2210 root_sc->tulip_slaves = sc; 2211 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) 2212 printf("\nCannot find master device for de%d interrupts", sc->tulip_unit); 2213 } else 2214 strlcat(sc->tulip_boardid, "unknown ", sizeof(sc->tulip_boardid)); 2215 2216 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */ 2217} 2218 2219int 2220tulip_srom_decode(tulip_softc_t * const sc) 2221{ 2222 unsigned idx1, idx2, idx3; 2223 2224 const tulip_srom_header_t *shp = (tulip_srom_header_t *) &sc->tulip_rombuf[0]; 2225 const tulip_srom_adapter_info_t *saip = (tulip_srom_adapter_info_t *) (shp + 1); 2226 tulip_srom_media_t srom_media; 2227 tulip_media_info_t *mi = sc->tulip_mediainfo; 2228 const u_int8_t *dp; 2229 u_int32_t leaf_offset, blocks, data; 2230 2231 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) { 2232 if (shp->sh_adapter_count == 1) 2233 break; 2234 if (saip->sai_device == sc->tulip_pci_devno) 2235 break; 2236 } 2237 /* 2238 * Didn't find the right media block for this card. 2239 */ 2240 if (idx1 == shp->sh_adapter_count) 2241 return (0); 2242 2243 /* 2244 * Save the hardware address. 2245 */ 2246 bcopy((caddr_t) shp->sh_ieee802_address, (caddr_t) sc->tulip_enaddr, 2247 ETHER_ADDR_LEN); 2248 /* 2249 * If this is a multiple port card, add the adapter index to the last 2250 * byte of the hardware address. (if it isn't multiport, adding 0 2251 * won't hurt. 2252 */ 2253 sc->tulip_enaddr[5] += idx1; 2254 2255 leaf_offset = saip->sai_leaf_offset_lowbyte 2256 + saip->sai_leaf_offset_highbyte * 256; 2257 dp = sc->tulip_rombuf + leaf_offset; 2258 2259 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2; 2260 2261 for (idx2 = 0;; idx2++) { 2262 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype 2263 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED) 2264 break; 2265 } 2266 sc->tulip_connidx = idx2; 2267 2268 if (sc->tulip_chipid == TULIP_21041) { 2269 blocks = *dp++; 2270 for (idx2 = 0; idx2 < blocks; idx2++) { 2271 tulip_media_t media; 2272 data = *dp++; 2273 srom_media = (tulip_srom_media_t) (data & 0x3F); 2274 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2275 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2276 break; 2277 } 2278 media = tulip_srom_mediums[idx3].sm_type; 2279 if (media != TULIP_MEDIA_UNKNOWN) { 2280 if (data & TULIP_SROM_21041_EXTENDED) { 2281 mi->mi_type = TULIP_MEDIAINFO_SIA; 2282 sc->tulip_mediums[media] = mi; 2283 mi->mi_sia_connectivity = dp[0] + dp[1] * 256; 2284 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256; 2285 mi->mi_sia_general = dp[4] + dp[5] * 256; 2286 mi++; 2287 } else { 2288 switch (media) { 2289 case TULIP_MEDIA_BNC: { 2290 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); 2291 mi++; 2292 break; 2293 } 2294 case TULIP_MEDIA_AUI: { 2295 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); 2296 mi++; 2297 break; 2298 } 2299 case TULIP_MEDIA_10BASET: { 2300 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); 2301 mi++; 2302 break; 2303 } 2304 case TULIP_MEDIA_10BASET_FD: { 2305 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); 2306 mi++; 2307 break; 2308 } 2309 default: { 2310 break; 2311 } 2312 } 2313 } 2314 } 2315 if (data & TULIP_SROM_21041_EXTENDED) 2316 dp += 6; 2317 } 2318 } else { 2319 unsigned length, type; 2320 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN; 2321 if (sc->tulip_features & TULIP_HAVE_GPR) 2322 sc->tulip_gpinit = *dp++; 2323 blocks = *dp++; 2324 for (idx2 = 0; idx2 < blocks; idx2++) { 2325 const u_int8_t *ep; 2326 if ((*dp & 0x80) == 0) { 2327 length = 4; 2328 type = 0; 2329 } else { 2330 length = (*dp++ & 0x7f) - 1; 2331 type = *dp++ & 0x3f; 2332 } 2333 ep = dp + length; 2334 switch (type & 0x3f) { 2335 case 0: { /* 21140[A] GPR block */ 2336 tulip_media_t media; 2337 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2338 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2339 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2340 break; 2341 } 2342 media = tulip_srom_mediums[idx3].sm_type; 2343 if (media == TULIP_MEDIA_UNKNOWN) 2344 break; 2345 mi->mi_type = TULIP_MEDIAINFO_GPR; 2346 sc->tulip_mediums[media] = mi; 2347 mi->mi_gpdata = dp[1]; 2348 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) { 2349 sc->tulip_gpdata = mi->mi_gpdata; 2350 gp_media = media; 2351 } 2352 data = dp[2] + dp[3] * 256; 2353 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2354 if (data & TULIP_SROM_2114X_NOINDICATOR) 2355 mi->mi_actmask = 0; 2356 else { 2357 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2358 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2359 } 2360 mi++; 2361 break; 2362 } 2363 case 1: { /* 21140[A] MII block */ 2364 const unsigned phyno = *dp++; 2365 mi->mi_type = TULIP_MEDIAINFO_MII; 2366 mi->mi_gpr_length = *dp++; 2367 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2368 dp += mi->mi_gpr_length; 2369 mi->mi_reset_length = *dp++; 2370 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2371 dp += mi->mi_reset_length; 2372 2373 /* 2374 * Before we probe for a PHY, use the GPR information 2375 * to select it. If we don't, it may be inaccessible. 2376 */ 2377 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET); 2378 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) { 2379 DELAY(10); 2380 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]); 2381 } 2382 sc->tulip_phyaddr = mi->mi_phyaddr; 2383 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) { 2384 DELAY(10); 2385 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]); 2386 } 2387 2388 /* 2389 * At least write something! 2390 */ 2391 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2392 TULIP_CSR_WRITE(sc, csr_gp, 0); 2393 2394 mi->mi_phyaddr = TULIP_MII_NOPHY; 2395 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2396 DELAY(10000); 2397 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2398 } 2399 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2400#if defined(TULIP_DEBUG) 2401 printf(TULIP_PRINTF_FMT ": can't find phy %d\n", 2402 TULIP_PRINTF_ARGS, phyno); 2403#endif 2404 break; 2405 } 2406 sc->tulip_features |= TULIP_HAVE_MII; 2407 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2408 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2409 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2410 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2411 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2412 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2413 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2414 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2415 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2416 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2417 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2418 mi++; 2419 break; 2420 } 2421 case 2: { /* 2114[23] SIA block */ 2422 tulip_media_t media; 2423 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); 2424 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2425 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2426 break; 2427 } 2428 media = tulip_srom_mediums[idx3].sm_type; 2429 if (media == TULIP_MEDIA_UNKNOWN) 2430 break; 2431 mi->mi_type = TULIP_MEDIAINFO_SIA; 2432 sc->tulip_mediums[media] = mi; 2433 if (dp[0] & 0x40) { 2434 mi->mi_sia_connectivity = dp[1] + dp[2] * 256; 2435 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256; 2436 mi->mi_sia_general = dp[5] + dp[6] * 256; 2437 dp += 6; 2438 } else { 2439 switch (media) { 2440 case TULIP_MEDIA_BNC: { 2441 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC); 2442 break; 2443 } 2444 case TULIP_MEDIA_AUI: { 2445 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI); 2446 break; 2447 } 2448 case TULIP_MEDIA_10BASET: { 2449 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET); 2450 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2451 break; 2452 } 2453 case TULIP_MEDIA_10BASET_FD: { 2454 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD); 2455 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2456 break; 2457 } 2458 default: { 2459 goto bad_media; 2460 } 2461 } 2462 } 2463 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16; 2464 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16; 2465 mi++; 2466 bad_media: 2467 break; 2468 } 2469 case 3: { /* 2114[23] MII PHY block */ 2470 const unsigned phyno = *dp++; 2471 const u_int8_t *dp0; 2472 mi->mi_type = TULIP_MEDIAINFO_MII; 2473 mi->mi_gpr_length = *dp++; 2474 mi->mi_gpr_offset = dp - sc->tulip_rombuf; 2475 dp += 2 * mi->mi_gpr_length; 2476 mi->mi_reset_length = *dp++; 2477 mi->mi_reset_offset = dp - sc->tulip_rombuf; 2478 dp += 2 * mi->mi_reset_length; 2479 2480 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset]; 2481 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) { 2482 DELAY(10); 2483 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2484 } 2485 sc->tulip_phyaddr = mi->mi_phyaddr; 2486 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset]; 2487 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) { 2488 DELAY(10); 2489 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); 2490 } 2491 2492 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) 2493 TULIP_CSR_WRITE(sc, csr_sia_general, 0); 2494 2495 mi->mi_phyaddr = TULIP_MII_NOPHY; 2496 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { 2497 DELAY(10000); 2498 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); 2499 } 2500 if (mi->mi_phyaddr == TULIP_MII_NOPHY) { 2501#if defined(TULIP_DEBUG) 2502 printf(TULIP_PRINTF_FMT ": can't find phy %d\n", 2503 TULIP_PRINTF_ARGS, phyno); 2504#endif 2505 break; 2506 } 2507 sc->tulip_features |= TULIP_HAVE_MII; 2508 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; 2509 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; 2510 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; 2511 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; 2512 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2; 2513 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); 2514 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); 2515 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); 2516 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); 2517 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); 2518 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | 2519 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); 2520 mi++; 2521 break; 2522 } 2523 case 4: { /* 21143 SYM block */ 2524 tulip_media_t media; 2525 srom_media = (tulip_srom_media_t) dp[0]; 2526 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { 2527 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) 2528 break; 2529 } 2530 media = tulip_srom_mediums[idx3].sm_type; 2531 if (media == TULIP_MEDIA_UNKNOWN) 2532 break; 2533 mi->mi_type = TULIP_MEDIAINFO_SYM; 2534 sc->tulip_mediums[media] = mi; 2535 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16; 2536 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16; 2537 data = dp[5] + dp[6] * 256; 2538 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); 2539 if (data & TULIP_SROM_2114X_NOINDICATOR) 2540 mi->mi_actmask = 0; 2541 else { 2542 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; 2543 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); 2544 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; 2545 } 2546 if (TULIP_IS_MEDIA_TP(media)) 2547 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; 2548 mi++; 2549 break; 2550 } 2551 default: { 2552 } 2553 } 2554 dp = ep; 2555 } 2556 } 2557 return (mi - sc->tulip_mediainfo); 2558} 2559 2560static const struct { 2561 void (*vendor_identify_nic)(tulip_softc_t * const sc); 2562 unsigned char vendor_oui[3]; 2563} tulip_vendors[] = { 2564 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } }, 2565 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } }, 2566 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } }, 2567 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } }, 2568 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } }, 2569 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } }, 2570 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } }, 2571 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } }, 2572 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } }, 2573 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } }, 2574 { NULL } 2575}; 2576 2577/* 2578 * This deals with the vagaries of the address roms and the 2579 * brain-deadness that various vendors commit in using them. 2580 */ 2581int 2582tulip_read_macaddr(tulip_softc_t * const sc) 2583{ 2584 unsigned cksum, rom_cksum, idx; 2585 u_int32_t csr; 2586 unsigned char tmpbuf[8]; 2587 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 2588 2589 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX; 2590 2591 if (sc->tulip_chipid == TULIP_21040) { 2592 TULIP_CSR_WRITE(sc, csr_enetrom, 1); 2593 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2594 int cnt = 0; 2595 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000) 2596 cnt++; 2597 sc->tulip_rombuf[idx] = csr & 0xFF; 2598 } 2599 sc->tulip_boardsw = &tulip_21040_boardsw; 2600 } else { 2601 if (sc->tulip_chipid == TULIP_21041) { 2602 /* 2603 * Thankfully all 21041's act the same. 2604 */ 2605 sc->tulip_boardsw = &tulip_21041_boardsw; 2606 } else { 2607 /* 2608 * Assume all 21140 board are compatible with the 2609 * DEC 10/100 evaluation board. Not really valid but 2610 * it's the best we can do until every one switches to 2611 * the new SROM format. 2612 */ 2613 2614 sc->tulip_boardsw = &tulip_21140_eb_boardsw; 2615 } 2616 tulip_srom_read(sc); 2617 if (tulip_srom_crcok(sc->tulip_rombuf)) { 2618 /* 2619 * SROM CRC is valid therefore it must be in the 2620 * new format. 2621 */ 2622 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM; 2623 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) { 2624 /* 2625 * No checksum is present. See if the SROM id checks out; 2626 * the first 18 bytes should be 0 followed by a 1 followed 2627 * by the number of adapters (which we don't deal with yet). 2628 */ 2629 for (idx = 0; idx < 18; idx++) { 2630 if (sc->tulip_rombuf[idx] != 0) 2631 break; 2632 } 2633 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0) 2634 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2635 } else if (sc->tulip_chipid >= TULIP_21142) { 2636 sc->tulip_features |= TULIP_HAVE_ISVSROM; 2637 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2638 } 2639 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) { 2640 if (sc->tulip_chipid != TULIP_21041) 2641 sc->tulip_boardsw = &tulip_2114x_isv_boardsw; 2642 2643 /* 2644 * If the SROM specifies more than one adapter, tag this as a 2645 * BASE rom. 2646 */ 2647 if (sc->tulip_rombuf[19] > 1) 2648 sc->tulip_features |= TULIP_HAVE_BASEROM; 2649 if (sc->tulip_boardsw == NULL) 2650 return (-6); 2651 goto check_oui; 2652 } 2653 } 2654 2655 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 2656 /* 2657 * Some folks don't use the standard ethernet rom format 2658 * but instead just put the address in the first 6 bytes 2659 * of the rom and let the rest be all 0xffs. (Can we say 2660 * ZNYX???) (well sometimes they put in a checksum so we'll 2661 * start at 8). 2662 */ 2663 for (idx = 8; idx < 32; idx++) { 2664 if (sc->tulip_rombuf[idx] != 0xFF) 2665 return (-4); 2666 } 2667 /* 2668 * Make sure the address is not multicast or locally assigned 2669 * that the OUI is not 00-00-00. 2670 */ 2671 if ((sc->tulip_rombuf[0] & 3) != 0) 2672 return (-4); 2673 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 2674 && sc->tulip_rombuf[2] == 0) 2675 return (-4); 2676 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, ETHER_ADDR_LEN); 2677 sc->tulip_features |= TULIP_HAVE_OKROM; 2678 goto check_oui; 2679 } else { 2680 /* 2681 * A number of makers of multiport boards (ZNYX and Cogent) 2682 * only put on one address ROM on their 21040 boards. So 2683 * if the ROM is all zeros (or all 0xFFs), look at the 2684 * previous configured boards (as long as they are on the same 2685 * PCI bus and the bus number is non-zero) until we find the 2686 * master board with address ROM. We then use its address ROM 2687 * as the base for this board. (we add our relative board 2688 * to the last byte of its address). 2689 */ 2690 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { 2691 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF) 2692 break; 2693 } 2694 if (idx == sizeof(sc->tulip_rombuf)) { 2695 int root_unit; 2696 tulip_softc_t *root_sc = NULL; 2697 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { 2698 root_sc = TULIP_UNIT_TO_SOFTC(root_unit); 2699 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM) 2700 break; 2701 root_sc = NULL; 2702 } 2703 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM) 2704 && root_sc->tulip_chipid == sc->tulip_chipid 2705 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { 2706 sc->tulip_features |= TULIP_HAVE_SLAVEDROM; 2707 sc->tulip_boardsw = root_sc->tulip_boardsw; 2708 strlcpy(sc->tulip_boardid, root_sc->tulip_boardid, 2709 sizeof(sc->tulip_boardid)); 2710 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) { 2711 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf, 2712 sizeof(sc->tulip_rombuf)); 2713 if (!tulip_srom_decode(sc)) 2714 return (-5); 2715 } else { 2716 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 2717 ETHER_ADDR_LEN); 2718 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit; 2719 } 2720 /* 2721 * Now for a truly disgusting kludge: all 4 21040s on 2722 * the ZX314 share the same INTA line so the mapping 2723 * setup by the BIOS on the PCI bridge is worthless. 2724 * Rather than reprogramming the value in the config 2725 * register, we will handle this internally. 2726 */ 2727 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) { 2728 sc->tulip_slaves = root_sc->tulip_slaves; 2729 root_sc->tulip_slaves = sc; 2730 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; 2731 } 2732 return (0); 2733 } 2734 } 2735 } 2736 2737 /* 2738 * This is the standard DEC address ROM test. 2739 */ 2740 2741 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 2742 return (-3); 2743 2744 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 2745 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 2746 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 2747 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 2748 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 2749 return (-2); 2750 2751 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, ETHER_ADDR_LEN); 2752 2753 cksum = *(u_int16_t *) &sc->tulip_enaddr[0]; 2754 cksum *= 2; 2755 if (cksum > 65535) cksum -= 65535; 2756 cksum += *(u_int16_t *) &sc->tulip_enaddr[2]; 2757 if (cksum > 65535) cksum -= 65535; 2758 cksum *= 2; 2759 if (cksum > 65535) cksum -= 65535; 2760 cksum += *(u_int16_t *) &sc->tulip_enaddr[4]; 2761 if (cksum >= 65535) cksum -= 65535; 2762 2763 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6]; 2764 2765 if (cksum != rom_cksum) 2766 return (-1); 2767 2768 check_oui: 2769 /* 2770 * Check for various boards based on OUI. Did I say braindead? 2771 */ 2772 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) { 2773 if (bcmp((caddr_t) sc->tulip_enaddr, 2774 (caddr_t) tulip_vendors[idx].vendor_oui, 3) == 0) { 2775 (*tulip_vendors[idx].vendor_identify_nic)(sc); 2776 break; 2777 } 2778 } 2779 2780 sc->tulip_features |= TULIP_HAVE_OKROM; 2781 return (0); 2782} 2783 2784void 2785tulip_ifmedia_add(tulip_softc_t * const sc) 2786{ 2787 tulip_media_t media; 2788 int medias = 0; 2789 2790 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2791 if (sc->tulip_mediums[media] != NULL) { 2792 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media], 2793 0, 0); 2794 medias++; 2795 } 2796 } 2797 if (medias == 0) { 2798 sc->tulip_features |= TULIP_HAVE_NOMEDIA; 2799 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0); 2800 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE); 2801 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { 2802 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0); 2803 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO); 2804 } else { 2805 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]); 2806 sc->tulip_flags |= TULIP_PRINTMEDIA; 2807 tulip_linkup(sc, sc->tulip_media); 2808 } 2809} 2810 2811int 2812tulip_ifmedia_change(struct ifnet * const ifp) 2813{ 2814 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 2815 2816 sc->tulip_flags |= TULIP_NEEDRESET; 2817 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 2818 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 2819 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) { 2820 tulip_media_t media; 2821 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { 2822 if (sc->tulip_mediums[media] != NULL 2823 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) { 2824 sc->tulip_flags |= TULIP_PRINTMEDIA; 2825 sc->tulip_flags &= ~TULIP_DIDNWAY; 2826 tulip_linkup(sc, media); 2827 return (0); 2828 } 2829 } 2830 } 2831 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT); 2832 tulip_reset(sc); 2833 tulip_init(sc); 2834 return (0); 2835} 2836 2837/* 2838 * Media status callback 2839 */ 2840void 2841tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req) 2842{ 2843 tulip_softc_t *sc = TULIP_IFP_TO_SOFTC(ifp); 2844 2845 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) 2846 return; 2847 2848 req->ifm_status = IFM_AVALID; 2849 if (sc->tulip_flags & TULIP_LINKUP) 2850 req->ifm_status |= IFM_ACTIVE; 2851 2852 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media]; 2853} 2854 2855bus_dmamap_t 2856tulip_alloc_rxmap(tulip_softc_t *sc) 2857{ 2858 return (sc->tulip_free_rxmaps[--sc->tulip_num_free_rxmaps]); 2859} 2860 2861void 2862tulip_free_rxmap(tulip_softc_t *sc, bus_dmamap_t map) 2863{ 2864 sc->tulip_free_rxmaps[sc->tulip_num_free_rxmaps++] = map; 2865} 2866 2867bus_dmamap_t 2868tulip_alloc_txmap(tulip_softc_t *sc) 2869{ 2870 return (sc->tulip_free_txmaps[--sc->tulip_num_free_txmaps]); 2871} 2872 2873void 2874tulip_free_txmap(tulip_softc_t *sc, bus_dmamap_t map) 2875{ 2876 sc->tulip_free_txmaps[sc->tulip_num_free_txmaps++] = map; 2877} 2878 2879void 2880tulip_addr_filter(tulip_softc_t * const sc) 2881{ 2882 struct arpcom *ac = &sc->tulip_ac; 2883 struct ether_multistep step; 2884 struct ether_multi *enm; 2885 2886 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI); 2887 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART; 2888 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 2889 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 2890 sc->tulip_if.if_flags &= ~IFF_ALLMULTI; 2891 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */ 2892 if (sc->tulip_multicnt > 14) { 2893 u_int32_t *sp = sc->tulip_setupdata; 2894 unsigned hash; 2895 /* 2896 * Some early passes of the 21140 have broken implementations of 2897 * hash-perfect mode. When we get too many multicasts for perfect 2898 * filtering with these chips, we need to switch into hash-only 2899 * mode (this is better than all-multicast on network with lots 2900 * of multicast traffic). 2901 */ 2902 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH) 2903 sc->tulip_flags |= TULIP_WANTHASHONLY; 2904 else 2905 sc->tulip_flags |= TULIP_WANTHASHPERFECT; 2906 /* 2907 * If we have more than 14 multicasts, we have 2908 * go into hash perfect mode (512 bit multicast 2909 * hash and one perfect hardware). 2910 */ 2911 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 2912 if (ac->ac_multirangecnt > 0) { 2913 sc->tulip_flags |= TULIP_ALLMULTI; 2914 sc->tulip_flags &= ~(TULIP_WANTHASHONLY|TULIP_WANTHASHPERFECT); 2915 } else { 2916 ETHER_FIRST_MULTI(step, ac, enm); 2917 while (enm != NULL) { 2918 hash = tulip_mchash(enm->enm_addrlo); 2919#if BYTE_ORDER == BIG_ENDIAN 2920 sp[hash >> 4] |= swap32(1 << (hash & 0xF)); 2921#else 2922 sp[hash >> 4] |= 1 << (hash & 0xF); 2923#endif 2924 ETHER_NEXT_MULTI(step, enm); 2925 } 2926 } 2927 /* 2928 * No reason to use a hash if we are going to be 2929 * receiving every multicast. 2930 */ 2931 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 2932 hash = tulip_mchash(etherbroadcastaddr); 2933#if BYTE_ORDER == BIG_ENDIAN 2934 sp[hash >> 4] |= swap32(1 << (hash & 0xF)); 2935#else 2936 sp[hash >> 4] |= 1 << (hash & 0xF); 2937#endif 2938 if (sc->tulip_flags & TULIP_WANTHASHONLY) { 2939 hash = tulip_mchash(sc->tulip_enaddr); 2940#if BYTE_ORDER == BIG_ENDIAN 2941 sp[hash >> 4] |= swap32(1 << (hash & 0xF)); 2942#else 2943 sp[hash >> 4] |= 1 << (hash & 0xF); 2944#endif 2945 } else { 2946#if BYTE_ORDER == BIG_ENDIAN 2947 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 2948 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 2949 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 2950#else 2951 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0]; 2952 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1]; 2953 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2]; 2954#endif 2955 } 2956 } 2957 } 2958 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) { 2959 u_int32_t *sp = sc->tulip_setupdata; 2960 int idx = 0; 2961 if (ac->ac_multirangecnt > 0) 2962 sc->tulip_flags |= TULIP_ALLMULTI; 2963 2964 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { 2965 /* 2966 * Else can get perfect filtering for 16 addresses. 2967 */ 2968 ETHER_FIRST_MULTI(step, ac, enm); 2969 for (; enm != NULL; idx++) { 2970#if BYTE_ORDER == BIG_ENDIAN 2971 *sp++ = ((u_int16_t *) enm->enm_addrlo)[0] << 16; 2972 *sp++ = ((u_int16_t *) enm->enm_addrlo)[1] << 16; 2973 *sp++ = ((u_int16_t *) enm->enm_addrlo)[2] << 16; 2974#else 2975 *sp++ = ((u_int16_t *) enm->enm_addrlo)[0]; 2976 *sp++ = ((u_int16_t *) enm->enm_addrlo)[1]; 2977 *sp++ = ((u_int16_t *) enm->enm_addrlo)[2]; 2978#endif 2979 ETHER_NEXT_MULTI(step, enm); 2980 } 2981 /* 2982 * Add the broadcast address. 2983 */ 2984 idx++; 2985#if BYTE_ORDER == BIG_ENDIAN 2986 *sp++ = 0xFFFF << 16; 2987 *sp++ = 0xFFFF << 16; 2988 *sp++ = 0xFFFF << 16; 2989#else 2990 *sp++ = 0xFFFF; 2991 *sp++ = 0xFFFF; 2992 *sp++ = 0xFFFF; 2993#endif 2994 } 2995 /* 2996 * Pad the rest with our hardware address 2997 */ 2998 for (; idx < 16; idx++) { 2999#if BYTE_ORDER == BIG_ENDIAN 3000 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; 3001 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; 3002 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; 3003#else 3004 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0]; 3005 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1]; 3006 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2]; 3007#endif 3008 } 3009 } 3010 if (sc->tulip_flags & TULIP_ALLMULTI) 3011 sc->tulip_if.if_flags |= IFF_ALLMULTI; 3012} 3013 3014void 3015tulip_reset(tulip_softc_t * const sc) 3016{ 3017 tulip_ringinfo_t *ri; 3018 tulip_desc_t *di; 3019 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET); 3020 3021 /* 3022 * Brilliant. Simply brilliant. When switching modes/speeds 3023 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS 3024 * bits in CSR6 and then do a software reset to get the 21140 3025 * to properly reset its internal pathways to the right places. 3026 * Grrrr. 3027 */ 3028 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0 3029 && sc->tulip_boardsw->bd_media_preset != NULL) 3030 (*sc->tulip_boardsw->bd_media_preset)(sc); 3031 3032 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 3033 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at 3034 33MHz that comes to two microseconds but wait a 3035 bit longer anyways) */ 3036 3037 if (!inreset) { 3038 sc->tulip_flags |= TULIP_INRESET; 3039 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW); 3040 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3041 sc->tulip_if.if_start = tulip_ifstart; 3042 } 3043 3044 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr); 3045 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr); 3046 TULIP_CSR_WRITE(sc, csr_busmode, 3047 (1 << (TULIP_BURSTSIZE(sc->tulip_unit) + 8)) 3048 |TULIP_BUSMODE_CACHE_ALIGN8 3049 |TULIP_BUSMODE_READMULTIPLE 3050 |(BYTE_ORDER != LITTLE_ENDIAN ? 3051 TULIP_BUSMODE_DESC_BIGENDIAN : 0)); 3052 3053 sc->tulip_txtimer = 0; 3054 IFQ_SET_MAXLEN(&sc->tulip_txq, TULIP_TXDESCS); 3055 /* 3056 * Free all the mbufs that were on the transmit ring. 3057 */ 3058 for (;;) { 3059 bus_dmamap_t map; 3060 struct mbuf *m; 3061 IF_DEQUEUE(&sc->tulip_txq, m); 3062 if (m == NULL) 3063 break; 3064 map = TULIP_GETCTX(m, bus_dmamap_t); 3065 bus_dmamap_unload(sc->tulip_dmatag, map); 3066 tulip_free_txmap(sc, map); 3067 m_freem(m); 3068 } 3069 3070 ri = &sc->tulip_txinfo; 3071 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3072 ri->ri_free = ri->ri_max; 3073 for (di = ri->ri_first; di < ri->ri_last; di++) 3074 di->d_status = 0; 3075 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap, 3076 0, sc->tulip_txdescmap->dm_mapsize, 3077 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3078 3079 /* 3080 * We need to collect all the mbufs were on the 3081 * receive ring before we reinit it either to put 3082 * them back on or to know if we have to allocate 3083 * more. 3084 */ 3085 ri = &sc->tulip_rxinfo; 3086 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3087 ri->ri_free = ri->ri_max; 3088 for (di = ri->ri_first; di < ri->ri_last; di++) { 3089 di->d_status = 0; 3090 di->d_length1 = 0; di->d_addr1 = 0; 3091 di->d_length2 = 0; di->d_addr2 = 0; 3092 } 3093 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap, 3094 0, sc->tulip_rxdescmap->dm_mapsize, 3095 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3096 for (;;) { 3097 bus_dmamap_t map; 3098 struct mbuf *m; 3099 IF_DEQUEUE(&sc->tulip_rxq, m); 3100 if (m == NULL) 3101 break; 3102 map = TULIP_GETCTX(m, bus_dmamap_t); 3103 bus_dmamap_unload(sc->tulip_dmatag, map); 3104 tulip_free_rxmap(sc, map); 3105 m_freem(m); 3106 } 3107 3108 /* 3109 * If tulip_reset is being called recurisvely, exit quickly knowing 3110 * that when the outer tulip_reset returns all the right stuff will 3111 * have happened. 3112 */ 3113 if (inreset) 3114 return; 3115 3116 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 3117 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 3118 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE 3119 |TULIP_STS_RXSTOPPED; 3120 3121 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) 3122 (*sc->tulip_boardsw->bd_media_select)(sc); 3123#if defined(TULIP_DEBUG) 3124 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET) 3125 printf(TULIP_PRINTF_FMT ": tulip_reset: additional reset needed?!?\n", 3126 TULIP_PRINTF_ARGS); 3127#endif 3128 tulip_media_print(sc); 3129 if (sc->tulip_features & TULIP_HAVE_DUALSENSE) 3130 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status)); 3131 3132 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET 3133 |TULIP_RXACT); 3134 tulip_addr_filter(sc); 3135} 3136 3137void 3138tulip_init(tulip_softc_t * const sc) 3139{ 3140 if (sc->tulip_if.if_flags & IFF_UP) { 3141 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) { 3142 /* initialize the media */ 3143 tulip_reset(sc); 3144 } 3145 sc->tulip_if.if_flags |= IFF_RUNNING; 3146 if (sc->tulip_if.if_flags & IFF_PROMISC) { 3147 sc->tulip_flags |= TULIP_PROMISC; 3148 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 3149 sc->tulip_intrmask |= TULIP_STS_TXINTR; 3150 } else { 3151 sc->tulip_flags &= ~TULIP_PROMISC; 3152 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 3153 if (sc->tulip_flags & TULIP_ALLMULTI) 3154 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 3155 else 3156 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 3157 } 3158 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 3159 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) { 3160 tulip_rx_intr(sc); 3161 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3162 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3163 } else { 3164 sc->tulip_if.if_flags |= IFF_OACTIVE; 3165 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 3166 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 3167 } 3168 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3169 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3170 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 3171 tulip_txput_setup(sc); 3172 } else { 3173 sc->tulip_if.if_flags &= ~IFF_RUNNING; 3174 tulip_reset(sc); 3175 } 3176} 3177 3178void 3179tulip_rx_intr(tulip_softc_t * const sc) 3180{ 3181 TULIP_PERFSTART(rxintr) 3182 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; 3183 struct ifnet * const ifp = &sc->tulip_if; 3184 struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 3185 int fillok = 1; 3186#if defined(TULIP_DEBUG) 3187 int cnt = 0; 3188#endif 3189 3190 for (;;) { 3191 TULIP_PERFSTART(rxget) 3192 tulip_desc_t *eop = ri->ri_nextin; 3193 int total_len = 0, last_offset = 0; 3194 struct mbuf *ms = NULL, *me = NULL; 3195 int accept = 0; 3196 bus_dmamap_t map; 3197 int error; 3198 3199 if (fillok && IF_LEN(&sc->tulip_rxq) < TULIP_RXQ_TARGET) 3200 goto queue_mbuf; 3201 3202#if defined(TULIP_DEBUG) 3203 if (cnt == ri->ri_max) 3204 break; 3205#endif 3206 /* 3207 * If the TULIP has no descriptors, there can't be any receive 3208 * descriptors to process. 3209 */ 3210 if (eop == ri->ri_nextout) 3211 break; 3212 3213 /* 3214 * 90% of the packets will fit in one descriptor. So we optimize 3215 * for that case. 3216 */ 3217 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3218 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) { 3219#ifdef DIAGNOSTIC 3220 if (IF_IS_EMPTY(&sc->tulip_rxq)) 3221 panic("%s: tulip_rxq empty", sc->tulip_if.if_xname); 3222#endif 3223 IF_DEQUEUE(&sc->tulip_rxq, ms); 3224 me = ms; 3225 } else { 3226 /* 3227 * If still owned by the TULIP, don't touch it. 3228 */ 3229 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 3230 break; 3231 3232 /* 3233 * It is possible (though improbable unless MCLBYTES < 1518) for 3234 * a received packet to cross more than one receive descriptor. 3235 */ 3236 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { 3237 if (++eop == ri->ri_last) 3238 eop = ri->ri_first; 3239 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3240 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) { 3241 TULIP_PERFEND(rxget); 3242 goto out; 3243 } 3244 total_len++; 3245 } 3246 3247 /* 3248 * Dequeue the first buffer for the start of the packet. Hopefully 3249 * this will be the only one we need to dequeue. However, if the 3250 * packet consumed multiple descriptors, then we need to dequeue 3251 * those buffers and chain to the starting mbuf. All buffers but 3252 * the last buffer have the same length so we can set that now. 3253 * (we add to last_offset instead of multiplying since we normally 3254 * won't go into the loop and thereby saving a ourselves from 3255 * doing a multiplication by 0 in the normal case). 3256 */ 3257 IF_DEQUEUE(&sc->tulip_rxq, ms); 3258 for (me = ms; total_len > 0; total_len--) { 3259 map = TULIP_GETCTX(me, bus_dmamap_t); 3260 TULIP_RXMAP_POSTSYNC(sc, map); 3261 bus_dmamap_unload(sc->tulip_dmatag, map); 3262 tulip_free_rxmap(sc, map); 3263#if defined(DIAGNOSTIC) 3264 TULIP_SETCTX(me, NULL); 3265#endif 3266 me->m_len = TULIP_RX_BUFLEN; 3267 last_offset += TULIP_RX_BUFLEN; 3268 IF_DEQUEUE(&sc->tulip_rxq, me->m_next); 3269 me = me->m_next; 3270 } 3271 } 3272 3273 /* 3274 * Now get the size of received packet (minus the CRC). 3275 */ 3276 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; 3277 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0 3278 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0)) { 3279 me->m_len = total_len - last_offset; 3280 3281 map = TULIP_GETCTX(me, bus_dmamap_t); 3282 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len, 3283 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 3284 bus_dmamap_unload(sc->tulip_dmatag, map); 3285 tulip_free_rxmap(sc, map); 3286#if defined(DIAGNOSTIC) 3287 TULIP_SETCTX(me, NULL); 3288#endif 3289 sc->tulip_flags |= TULIP_RXACT; 3290 accept = 1; 3291 } else { 3292 ifp->if_ierrors++; 3293 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) 3294 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3295 else { 3296#ifdef TULIP_DEBUG 3297 const char *error = NULL; 3298 if (eop->d_status & TULIP_DSTS_RxTOOLONG) { 3299 sc->tulip_dot3stats.dot3StatsFrameTooLongs++; 3300 error = "frame too long"; 3301 } 3302 if (eop->d_status & TULIP_DSTS_RxBADCRC) { 3303 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) { 3304 sc->tulip_dot3stats.dot3StatsAlignmentErrors++; 3305 error = "alignment error"; 3306 } else { 3307 sc->tulip_dot3stats.dot3StatsFCSErrors++; 3308 error = "bad crc"; 3309 } 3310 } 3311 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) { 3312 printf(TULIP_PRINTF_FMT ": receive: %s: %s\n", 3313 TULIP_PRINTF_ARGS, 3314 ether_sprintf(mtod(ms, u_char *) + 6), 3315 error); 3316 sc->tulip_flags |= TULIP_NOMESSAGES; 3317 } 3318#endif 3319 } 3320 3321 map = TULIP_GETCTX(me, bus_dmamap_t); 3322 bus_dmamap_unload(sc->tulip_dmatag, map); 3323 tulip_free_rxmap(sc, map); 3324#if defined(DIAGNOSTIC) 3325 TULIP_SETCTX(me, NULL); 3326#endif 3327 } 3328#if defined(TULIP_DEBUG) 3329 cnt++; 3330#endif 3331 if (++eop == ri->ri_last) 3332 eop = ri->ri_first; 3333 ri->ri_nextin = eop; 3334 queue_mbuf: 3335 /* 3336 * Either we are priming the TULIP with mbufs (m == NULL) 3337 * or we are about to accept an mbuf for the upper layers 3338 * so we need to allocate an mbuf to replace it. If we 3339 * can't replace it, send up it anyways. This may cause 3340 * us to drop packets in the future but that's better than 3341 * being caught in livelock. 3342 * 3343 * Note that if this packet crossed multiple descriptors 3344 * we don't even try to reallocate all the mbufs here. 3345 * Instead we rely on the test of the beginning of 3346 * the loop to refill for the extra consumed mbufs. 3347 */ 3348 if (accept || ms == NULL) { 3349 struct mbuf *m0; 3350 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3351 if (m0 != NULL) { 3352#if defined(TULIP_COPY_RXDATA) 3353 if (!accept || total_len >= (MHLEN - 2)) { 3354#endif 3355 MCLGET(m0, M_DONTWAIT); 3356 if ((m0->m_flags & M_EXT) == 0) { 3357 m_freem(m0); 3358 m0 = NULL; 3359 } 3360#if defined(TULIP_COPY_RXDATA) 3361 } 3362#endif 3363 } 3364 if (accept 3365#if defined(TULIP_COPY_RXDATA) 3366 && m0 != NULL 3367#endif 3368 ) { 3369#if !defined(TULIP_COPY_RXDATA) 3370 ms->m_pkthdr.len = total_len; 3371 ml_enqueue(&ml, ms); 3372#else 3373 m0->m_data += 2; /* align data after header */ 3374 m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); 3375 m0->m_len = m0->m_pkthdr.len = total_len; 3376 ml_enqueue(&ml, m0); 3377 m0 = ms; 3378#endif 3379 } 3380 ms = m0; 3381 } 3382 if (ms == NULL) { 3383 /* 3384 * Couldn't allocate a new buffer. Don't bother 3385 * trying to replenish the receive queue. 3386 */ 3387 fillok = 0; 3388 sc->tulip_flags |= TULIP_RXBUFSLOW; 3389#if defined(TULIP_DEBUG) 3390 sc->tulip_dbg.dbg_rxlowbufs++; 3391#endif 3392 TULIP_PERFEND(rxget); 3393 continue; 3394 } 3395 /* 3396 * Now give the buffer(s) to the TULIP and save in our 3397 * receive queue. 3398 */ 3399 do { 3400 tulip_desc_t * const nextout = ri->ri_nextout; 3401 if (sc->tulip_num_free_rxmaps > 0) { 3402 map = tulip_alloc_rxmap(sc); 3403 } else { 3404 m_freem(ms); 3405 sc->tulip_flags |= TULIP_RXBUFSLOW; 3406#if defined(TULIP_DEBUG) 3407 sc->tulip_dbg.dbg_rxlowbufs++; 3408#endif 3409 break; 3410 } 3411 TULIP_SETCTX(ms, map); 3412 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *), 3413 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT); 3414 if (error) { 3415 printf(TULIP_PRINTF_FMT ": unable to load rx map, " 3416 "error = %d\n", TULIP_PRINTF_ARGS, error); 3417 panic("tulip_rx_intr"); /* XXX */ 3418 } 3419 nextout->d_addr1 = map->dm_segs[0].ds_addr; 3420 nextout->d_length1 = map->dm_segs[0].ds_len; 3421 if (map->dm_nsegs == 2) { 3422 nextout->d_addr2 = map->dm_segs[1].ds_addr; 3423 nextout->d_length2 = map->dm_segs[1].ds_len; 3424 } else { 3425 nextout->d_addr2 = 0; 3426 nextout->d_length2 = 0; 3427 } 3428 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout)); 3429 nextout->d_status = TULIP_DSTS_OWNER; 3430 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t)); 3431 if (++ri->ri_nextout == ri->ri_last) 3432 ri->ri_nextout = ri->ri_first; 3433 me = ms->m_next; 3434 ms->m_next = NULL; 3435 IF_ENQUEUE(&sc->tulip_rxq, ms); 3436 } while ((ms = me) != NULL); 3437 3438 if (IF_LEN(&sc->tulip_rxq) >= TULIP_RXQ_TARGET) 3439 sc->tulip_flags &= ~TULIP_RXBUFSLOW; 3440 TULIP_PERFEND(rxget); 3441 } 3442out: 3443 if_input(ifp, &ml); 3444 3445#if defined(TULIP_DEBUG) 3446 sc->tulip_dbg.dbg_rxintrs++; 3447 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3448#endif 3449 TULIP_PERFEND(rxintr); 3450} 3451 3452int 3453tulip_tx_intr(tulip_softc_t * const sc) 3454{ 3455 TULIP_PERFSTART(txintr) 3456 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3457 struct mbuf *m; 3458 int xmits = 0; 3459 int descs = 0; 3460 3461 while (ri->ri_free < ri->ri_max) { 3462 u_int32_t d_flag; 3463 3464 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin)); 3465 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 3466 break; 3467 3468 ri->ri_free++; 3469 descs++; 3470 d_flag = ri->ri_nextin->d_flag; 3471 if (d_flag & TULIP_DFLAG_TxLASTSEG) { 3472 if (d_flag & TULIP_DFLAG_TxSETUPPKT) { 3473 /* 3474 * We've just finished processing a setup packet. 3475 * Mark that we finished it. If there's not 3476 * another pending, startup the TULIP receiver. 3477 * Make sure we ack the RXSTOPPED so we won't get 3478 * an abormal interrupt indication. 3479 */ 3480 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap); 3481 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY); 3482 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT) 3483 sc->tulip_flags |= TULIP_HASHONLY; 3484 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) { 3485 tulip_rx_intr(sc); 3486 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3487 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3488 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3489 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3490 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3491 } 3492 } else { 3493 const u_int32_t d_status = ri->ri_nextin->d_status; 3494 IF_DEQUEUE(&sc->tulip_txq, m); 3495 if (m != NULL) { 3496 bus_dmamap_t map = TULIP_GETCTX(m, bus_dmamap_t); 3497 TULIP_TXMAP_POSTSYNC(sc, map); 3498 tulip_free_txmap(sc, map); 3499#if NBPFILTER > 0 3500 if (sc->tulip_bpf != NULL) 3501 bpf_mtap(sc->tulip_if.if_bpf, m, BPF_DIRECTION_OUT); 3502#endif 3503 m_freem(m); 3504 } 3505 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 3506 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; 3507 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { 3508#if defined(TULIP_DEBUG) 3509 if (d_status & TULIP_DSTS_TxNOCARR) 3510 sc->tulip_dbg.dbg_txprobe_nocarr++; 3511 if (d_status & TULIP_DSTS_TxEXCCOLL) 3512 sc->tulip_dbg.dbg_txprobe_exccoll++; 3513#endif 3514 event = TULIP_MEDIAPOLL_TXPROBE_FAILED; 3515 } 3516 (*sc->tulip_boardsw->bd_media_poll)(sc, event); 3517 /* 3518 * Escape from the loop before media poll has reset the TULIP! 3519 */ 3520 break; 3521 } else { 3522 xmits++; 3523 if (d_status & TULIP_DSTS_ERRSUM) { 3524 sc->tulip_if.if_oerrors++; 3525 if (d_status & TULIP_DSTS_TxEXCCOLL) 3526 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; 3527 if (d_status & TULIP_DSTS_TxLATECOLL) 3528 sc->tulip_dot3stats.dot3StatsLateCollisions++; 3529 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) 3530 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; 3531 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) 3532 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; 3533 if (d_status & TULIP_DSTS_TxUNDERFLOW) 3534 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; 3535 if (d_status & TULIP_DSTS_TxBABBLE) 3536 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; 3537 } else { 3538 u_int32_t collisions = 3539 (d_status & TULIP_DSTS_TxCOLLMASK) 3540 >> TULIP_DSTS_V_TxCOLLCNT; 3541 sc->tulip_if.if_collisions += collisions; 3542 if (collisions == 1) 3543 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; 3544 else if (collisions > 1) 3545 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; 3546 else if (d_status & TULIP_DSTS_TxDEFERRED) 3547 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; 3548 /* 3549 * SQE is only valid for 10baseT/BNC/AUI when not 3550 * running in full-duplex. In order to speed up the 3551 * test, the corresponding bit in tulip_flags needs to 3552 * set as well to get us to count SQE Test Errors. 3553 */ 3554 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) 3555 sc->tulip_dot3stats.dot3StatsSQETestErrors++; 3556 } 3557 } 3558 } 3559 } 3560 3561 if (++ri->ri_nextin == ri->ri_last) 3562 ri->ri_nextin = ri->ri_first; 3563 3564 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3565 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3566 } 3567 /* 3568 * If nothing left to transmit, disable the timer. 3569 * Else if progress, reset the timer back to 2 ticks. 3570 */ 3571 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE)) 3572 sc->tulip_txtimer = 0; 3573 else if (xmits > 0) 3574 sc->tulip_txtimer = TULIP_TXTIMER; 3575 sc->tulip_if.if_opackets += xmits; 3576 TULIP_PERFEND(txintr); 3577 return (descs); 3578} 3579 3580void 3581tulip_print_abnormal_interrupt(tulip_softc_t * const sc, u_int32_t csr) 3582{ 3583#ifdef TULIP_DEBUG 3584 const char * const *msgp = tulip_status_bits; 3585 const char *sep; 3586 u_int32_t mask; 3587 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024\0"; 3588 3589 csr &= (1 << (nitems(tulip_status_bits))) - 1; 3590 printf(TULIP_PRINTF_FMT ": abnormal interrupt:", TULIP_PRINTF_ARGS); 3591 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { 3592 if ((csr & mask) && *msgp != NULL) { 3593 printf("%s%s", sep, *msgp); 3594 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { 3595 sc->tulip_flags &= ~TULIP_NEWTXTHRESH; 3596 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) 3597 printf(" (switching to store-and-forward mode)"); 3598 else { 3599 printf(" (raising TX threshold to %s)", 3600 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); 3601 } 3602 } 3603 sep = ", "; 3604 } 3605 } 3606 printf("\n"); 3607#endif 3608} 3609 3610void 3611tulip_intr_handler(tulip_softc_t * const sc, int *progress_p) 3612{ 3613 TULIP_PERFSTART(intr) 3614 u_int32_t csr; 3615 3616 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { 3617 *progress_p = 1; 3618 TULIP_CSR_WRITE(sc, csr_status, csr); 3619 3620 if (csr & TULIP_STS_SYSERROR) { 3621 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT; 3622 if (sc->tulip_flags & TULIP_NOMESSAGES) 3623 sc->tulip_flags |= TULIP_SYSTEMERROR; 3624 else { 3625#if defined(TULIP_DEBUG) 3626 printf(TULIP_PRINTF_FMT ": system error: %s\n", 3627 TULIP_PRINTF_ARGS, 3628 tulip_system_errors[sc->tulip_last_system_error]); 3629#endif 3630 } 3631 sc->tulip_flags |= TULIP_NEEDRESET; 3632 sc->tulip_system_errors++; 3633 break; 3634 } 3635 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) { 3636#if defined(TULIP_DEBUG) 3637 sc->tulip_dbg.dbg_link_intrs++; 3638#endif 3639 if (sc->tulip_boardsw->bd_media_poll != NULL) { 3640 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL 3641 ? TULIP_MEDIAPOLL_LINKFAIL 3642 : TULIP_MEDIAPOLL_LINKPASS); 3643 csr &= ~TULIP_STS_ABNRMLINTR; 3644 } 3645 tulip_media_print(sc); 3646 } 3647 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) { 3648 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames); 3649 if (csr & TULIP_STS_RXNOBUF) 3650 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF; 3651 /* 3652 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data 3653 * on receive overflows. 3654 */ 3655 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) { 3656 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3657 /* 3658 * Stop the receiver process and spin until it's stopped. 3659 * Tell rx_intr to drop the packets it dequeues. 3660 */ 3661 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN); 3662 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0) 3663 ; 3664 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3665 sc->tulip_flags |= TULIP_RXIGNORE; 3666 } 3667 tulip_rx_intr(sc); 3668 if (sc->tulip_flags & TULIP_RXIGNORE) { 3669 /* 3670 * Restart the receiver. 3671 */ 3672 sc->tulip_flags &= ~TULIP_RXIGNORE; 3673 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3674 } 3675 } 3676 if (csr & TULIP_STS_ABNRMLINTR) { 3677 u_int32_t tmp = csr & sc->tulip_intrmask 3678 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); 3679 if (csr & TULIP_STS_TXUNDERFLOW) { 3680#if defined(TULIP_DEBUG) 3681 printf ("Underflow interrupt\n"); 3682#endif 3683 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { 3684 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; 3685 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3686 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { 3687 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 3688 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3689 } 3690 } 3691 if (sc->tulip_flags & TULIP_NOMESSAGES) 3692 sc->tulip_statusbits |= tmp; 3693 else { 3694 tulip_print_abnormal_interrupt(sc, tmp); 3695 sc->tulip_flags |= TULIP_NOMESSAGES; 3696 } 3697 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3698 } 3699 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { 3700 tulip_tx_intr(sc); 3701 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3702 tulip_ifstart(&sc->tulip_if); 3703 } 3704 } 3705 if (sc->tulip_flags & TULIP_NEEDRESET) { 3706 tulip_reset(sc); 3707 tulip_init(sc); 3708 } 3709 TULIP_PERFEND(intr); 3710} 3711 3712int 3713tulip_intr_shared(void *arg) 3714{ 3715 tulip_softc_t * sc = arg; 3716 int progress = 0; 3717 3718 for (; sc != NULL; sc = sc->tulip_slaves) { 3719#if defined(TULIP_DEBUG) 3720 sc->tulip_dbg.dbg_intrs++; 3721#endif 3722 tulip_intr_handler(sc, &progress); 3723 } 3724 return (progress); 3725} 3726 3727int 3728tulip_intr_normal(void *arg) 3729{ 3730 tulip_softc_t * sc = (tulip_softc_t *) arg; 3731 int progress = 0; 3732 3733#if defined(TULIP_DEBUG) 3734 sc->tulip_dbg.dbg_intrs++; 3735#endif 3736 tulip_intr_handler(sc, &progress); 3737 3738 return (progress); 3739} 3740 3741struct mbuf * 3742tulip_mbuf_compress(struct mbuf *m) 3743{ 3744 struct mbuf *m0; 3745#if MCLBYTES >= ETHERMTU + 18 3746 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3747 if (m0 != NULL) { 3748 if (m->m_pkthdr.len > MHLEN) { 3749 MCLGET(m0, M_DONTWAIT); 3750 if ((m0->m_flags & M_EXT) == 0) { 3751 m_freem(m); 3752 m_freem(m0); 3753 return (NULL); 3754 } 3755 } 3756 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 3757 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 3758 } 3759#else 3760 int mlen = MHLEN; 3761 int len = m->m_pkthdr.len; 3762 struct mbuf **mp = &m0; 3763 3764 while (len > 0) { 3765 if (mlen == MHLEN) 3766 MGETHDR(*mp, M_DONTWAIT, MT_DATA); 3767 else 3768 MGET(*mp, M_DONTWAIT, MT_DATA); 3769 if (*mp == NULL) { 3770 m_freem(m0); 3771 m0 = NULL; 3772 break; 3773 } 3774 if (len > MLEN) { 3775 MCLGET(*mp, M_DONTWAIT); 3776 if (((*mp)->m_flags & M_EXT) == 0) { 3777 m_freem(m0); 3778 m0 = NULL; 3779 break; 3780 } 3781 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; 3782 else 3783 (*mp)->m_len = len <= mlen ? len : mlen; 3784 m_copydata(m, m->m_pkthdr.len - len, 3785 (*mp)->m_len, mtod((*mp), caddr_t)); 3786 len -= (*mp)->m_len; 3787 mp = &(*mp)->m_next; 3788 mlen = MLEN; 3789 } 3790#endif 3791 m_freem(m); 3792 return (m0); 3793} 3794 3795struct mbuf * 3796tulip_txput(tulip_softc_t * const sc, struct mbuf *m, int notonqueue) 3797{ 3798 TULIP_PERFSTART(txput) 3799 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3800 tulip_desc_t *eop, *nextout; 3801 int segcnt, freedescs; 3802 u_int32_t d_status; 3803 bus_dmamap_t map; 3804 int error; 3805 struct ifnet *ifp = &sc->tulip_if; 3806#ifdef DIAGNOSTIC 3807 struct mbuf *ombuf = m; 3808#endif 3809 int compressed = 0; 3810 3811#if defined(TULIP_DEBUG) 3812 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 3813 printf(TULIP_PRINTF_FMT ": txput%s: tx not running\n", 3814 TULIP_PRINTF_ARGS, 3815 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); 3816 sc->tulip_flags |= TULIP_WANTTXSTART; 3817 sc->tulip_dbg.dbg_txput_finishes[0]++; 3818 goto finish; 3819 } 3820#endif 3821 3822 /* 3823 * Now we try to fill in our transmit descriptors. This is 3824 * a bit reminiscent of going on the Ark two by two 3825 * since each descriptor for the TULIP can describe 3826 * two buffers. So we advance through packet filling 3827 * each of the two entries at a time to to fill each 3828 * descriptor. Clear the first and last segment bits 3829 * in each descriptor (actually just clear everything 3830 * but the end-of-ring or chain bits) to make sure 3831 * we don't get messed up by previously sent packets. 3832 * 3833 * We may fail to put the entire packet on the ring if 3834 * there is either not enough ring entries free or if the 3835 * packet has more than MAX_TXSEG segments. In the former 3836 * case we will just wait for the ring to empty. In the 3837 * latter case we have to recopy. 3838 */ 3839 d_status = 0; 3840 eop = nextout = ri->ri_nextout; 3841 segcnt = 0; 3842 freedescs = ri->ri_free; 3843 3844 /* 3845 * Reclaim some DMA maps from if we are out. 3846 */ 3847 if (sc->tulip_num_free_txmaps == 0) { 3848#if defined(TULIP_DEBUG) 3849 sc->tulip_dbg.dbg_no_txmaps++; 3850#endif 3851 freedescs += tulip_tx_intr(sc); 3852 } 3853 if (sc->tulip_num_free_txmaps > 0) 3854 map = tulip_alloc_txmap(sc); 3855 else { 3856 sc->tulip_flags |= TULIP_WANTTXSTART; 3857#if defined(TULIP_DEBUG) 3858 sc->tulip_dbg.dbg_txput_finishes[1]++; 3859#endif 3860 goto finish; 3861 } 3862 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 3863 if (error != 0) { 3864 if (error == EFBIG) { 3865 /* 3866 * The packet exceeds the number of transmit buffer 3867 * entries that we can use for one packet, so we have 3868 * to recopy it into one mbuf and then try again. 3869 */ 3870 struct mbuf *tmp; 3871 if (!notonqueue) { 3872#ifdef DIAGNOSTIC 3873 if (IF_IS_EMPTY(&ifp->if_snd)) 3874 panic("%s: if_snd queue empty", ifp->if_xname); 3875#endif 3876 IFQ_DEQUEUE(&ifp->if_snd, tmp); 3877#ifdef DIAGNOSTIC 3878 if (tmp != ombuf) 3879 panic("tulip_txput: different mbuf dequeued!"); 3880#endif 3881 } 3882 compressed = 1; 3883 m = tulip_mbuf_compress(m); 3884 if (m == NULL) { 3885#if defined(TULIP_DEBUG) 3886 sc->tulip_dbg.dbg_txput_finishes[2]++; 3887#endif 3888 tulip_free_txmap(sc, map); 3889 goto finish; 3890 } 3891 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); 3892 } 3893 if (error != 0) { 3894 printf(TULIP_PRINTF_FMT ": unable to load tx map, " 3895 "error = %d\n", TULIP_PRINTF_ARGS, error); 3896#if defined(TULIP_DEBUG) 3897 sc->tulip_dbg.dbg_txput_finishes[3]++; 3898#endif 3899 tulip_free_txmap(sc, map); 3900 goto finish; 3901 } 3902 } 3903 if ((freedescs -= (map->dm_nsegs + 1) / 2) <= 0 3904 /* 3905 * See if there's any unclaimed space in the transmit ring. 3906 */ 3907 && (freedescs += tulip_tx_intr(sc)) <= 0) { 3908 /* 3909 * There's no more room but since nothing 3910 * has been committed at this point, just 3911 * show output is active, put back the 3912 * mbuf and return. 3913 */ 3914 sc->tulip_flags |= TULIP_WANTTXSTART; 3915#if defined(TULIP_DEBUG) 3916 sc->tulip_dbg.dbg_txput_finishes[4]++; 3917#endif 3918 bus_dmamap_unload(sc->tulip_dmatag, map); 3919 tulip_free_txmap(sc, map); 3920 goto finish; 3921 } 3922 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) { 3923 eop = nextout; 3924 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 3925 eop->d_status = d_status; 3926 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 3927 eop->d_length1 = map->dm_segs[segcnt].ds_len; 3928 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr; 3929 eop->d_length2 = map->dm_segs[segcnt+1].ds_len; 3930 d_status = TULIP_DSTS_OWNER; 3931 if (++nextout == ri->ri_last) 3932 nextout = ri->ri_first; 3933 } 3934 if (segcnt < map->dm_nsegs) { 3935 eop = nextout; 3936 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 3937 eop->d_status = d_status; 3938 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 3939 eop->d_length1 = map->dm_segs[segcnt].ds_len; 3940 eop->d_addr2 = 0; 3941 eop->d_length2 = 0; 3942 if (++nextout == ri->ri_last) 3943 nextout = ri->ri_first; 3944 } 3945 TULIP_TXMAP_PRESYNC(sc, map); 3946 TULIP_SETCTX(m, map); 3947 map = NULL; 3948 3949 /* 3950 * The descriptors have been filled in. Now get ready 3951 * to transmit. 3952 */ 3953 if (!compressed && !notonqueue) { 3954 /* remove the mbuf from the queue */ 3955 struct mbuf *tmp; 3956#ifdef DIAGNOSTIC 3957 if (IF_IS_EMPTY(&ifp->if_snd)) 3958 panic("%s: if_snd queue empty", ifp->if_xname); 3959#endif 3960 IFQ_DEQUEUE(&ifp->if_snd, tmp); 3961#ifdef DIAGNOSTIC 3962 if (tmp != ombuf) 3963 panic("tulip_txput: different mbuf dequeued!"); 3964#endif 3965 } 3966 3967 IF_ENQUEUE(&sc->tulip_txq, m); 3968 m = NULL; 3969 3970 /* 3971 * Make sure the next descriptor after this packet is owned 3972 * by us since it may have been set up above if we ran out 3973 * of room in the ring. 3974 */ 3975 nextout->d_status = 0; 3976 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 3977 3978 /* 3979 * Mark the last and first segments, indicate we want a transmit 3980 * complete interrupt, and tell it to transmit! 3981 */ 3982 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 3983 3984 /* 3985 * Note that ri->ri_nextout is still the start of the packet 3986 * and until we set the OWNER bit, we can still back out of 3987 * everything we have done. 3988 */ 3989 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 3990 if (eop < ri->ri_nextout) { 3991 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 3992 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout); 3993 TULIP_TXDESC_PRESYNC(sc, ri->ri_first, 3994 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first); 3995 } else { 3996 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 3997 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout); 3998 } 3999 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 4000 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4001 4002 /* 4003 * This advances the ring for us. 4004 */ 4005 ri->ri_nextout = nextout; 4006 ri->ri_free = freedescs; 4007 4008 TULIP_PERFEND(txput); 4009 4010 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 4011 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4012 sc->tulip_if.if_flags |= IFF_OACTIVE; 4013 sc->tulip_if.if_start = tulip_ifstart; 4014 TULIP_PERFEND(txput); 4015 return (NULL); 4016 } 4017 4018 /* 4019 * switch back to the single queueing ifstart. 4020 */ 4021 sc->tulip_flags &= ~TULIP_WANTTXSTART; 4022 if (sc->tulip_txtimer == 0) 4023 sc->tulip_txtimer = TULIP_TXTIMER; 4024#if defined(TULIP_DEBUG) 4025 sc->tulip_dbg.dbg_txput_finishes[5]++; 4026#endif 4027 4028 /* 4029 * If we want a txstart, there must be not enough space in the 4030 * transmit ring. So we want to enable transmit done interrupts 4031 * so we can immediately reclaim some space. When the transmit 4032 * interrupt is posted, the interrupt handler will call tx_intr 4033 * to reclaim space and then txstart (since WANTTXSTART is set). 4034 * txstart will move the packet into the transmit ring and clear 4035 * WANTTXSTART thereby causing TXINTR to be cleared. 4036 */ 4037 finish: 4038#if defined(TULIP_DEBUG) 4039 sc->tulip_dbg.dbg_txput_finishes[6]++; 4040#endif 4041 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { 4042 sc->tulip_if.if_flags |= IFF_OACTIVE; 4043 sc->tulip_if.if_start = tulip_ifstart; 4044 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4045 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4046 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4047 } 4048 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { 4049 if (sc->tulip_intrmask & TULIP_STS_TXINTR) { 4050 sc->tulip_intrmask &= ~TULIP_STS_TXINTR; 4051 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4052 } 4053 } 4054 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4055 TULIP_PERFEND(txput); 4056 return (m); 4057} 4058 4059void 4060tulip_txput_setup(tulip_softc_t * const sc) 4061{ 4062 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4063 tulip_desc_t *nextout; 4064 4065 /* 4066 * We will transmit, at most, one setup packet per call to ifstart. 4067 */ 4068 4069#if defined(TULIP_DEBUG) 4070 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4071 printf(TULIP_PRINTF_FMT ": txput_setup: tx not running\n", 4072 TULIP_PRINTF_ARGS); 4073 sc->tulip_flags |= TULIP_WANTTXSTART; 4074 sc->tulip_if.if_start = tulip_ifstart; 4075 return; 4076 } 4077#endif 4078 /* 4079 * Try to reclaim some free descriptors.. 4080 */ 4081 if (ri->ri_free < 2) 4082 tulip_tx_intr(sc); 4083 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 4084 sc->tulip_flags |= TULIP_WANTTXSTART; 4085 sc->tulip_if.if_start = tulip_ifstart; 4086 return; 4087 } 4088 bcopy(sc->tulip_setupdata, sc->tulip_setupdma, sizeof(sc->tulip_setupdata)); 4089 /* 4090 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is 4091 * set and DOINGSETUP is clear doing an XOR of the two will DTRT. 4092 */ 4093 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; 4094 ri->ri_free--; 4095 nextout = ri->ri_nextout; 4096 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4097 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 4098 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 4099 if (sc->tulip_flags & TULIP_WANTHASHPERFECT) 4100 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 4101 else if (sc->tulip_flags & TULIP_WANTHASHONLY) 4102 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; 4103 4104 nextout->d_length2 = 0; 4105 nextout->d_addr2 = 0; 4106 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len; 4107 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr; 4108 if (sc->tulip_setupmap->dm_nsegs == 2) { 4109 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len; 4110 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr; 4111 } 4112 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap); 4113 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout)); 4114 4115 /* 4116 * Advance the ring for the next transmit packet. 4117 */ 4118 if (++ri->ri_nextout == ri->ri_last) 4119 ri->ri_nextout = ri->ri_first; 4120 4121 /* 4122 * Make sure the next descriptor is owned by us since it 4123 * may have been set up above if we ran out of room in the 4124 * ring. 4125 */ 4126 ri->ri_nextout->d_status = 0; 4127 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4128 nextout->d_status = TULIP_DSTS_OWNER; 4129 /* 4130 * Flush the ownwership of the current descriptor 4131 */ 4132 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4133 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4134 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4135 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4136 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4137 } 4138} 4139 4140/* 4141 * This routine is entered at splnet(). 4142 */ 4143int 4144tulip_ifioctl(struct ifnet * ifp, u_long cmd, caddr_t data) 4145{ 4146 TULIP_PERFSTART(ifioctl) 4147 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4148 struct ifaddr *ifa = (struct ifaddr *)data; 4149 struct ifreq *ifr = (struct ifreq *) data; 4150 int s; 4151 int error = 0; 4152 4153 s = splnet(); 4154 4155 switch (cmd) { 4156 case SIOCSIFADDR: { 4157 ifp->if_flags |= IFF_UP; 4158 tulip_init(sc); 4159 switch(ifa->ifa_addr->sa_family) { 4160 case AF_INET: { 4161 arp_ifinit(&sc->tulip_ac, ifa); 4162 break; 4163 } 4164 4165 default: { 4166 break; 4167 } 4168 } 4169 break; 4170 } 4171 4172 case SIOCSIFFLAGS: { 4173 tulip_init(sc); 4174 break; 4175 } 4176 4177 case SIOCSIFMEDIA: 4178 case SIOCGIFMEDIA: { 4179 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd); 4180 break; 4181 } 4182 4183 default: 4184 error = ether_ioctl(ifp, &sc->tulip_ac, cmd, data); 4185 } 4186 4187 if (error == ENETRESET) { 4188 if (ifp->if_flags & IFF_RUNNING) { 4189 tulip_addr_filter(sc); /* reset multicast filtering */ 4190 tulip_init(sc); 4191 } 4192 error = 0; 4193 } 4194 4195 splx(s); 4196 TULIP_PERFEND(ifioctl); 4197 return (error); 4198} 4199 4200/* 4201 * the original dequeueing policy is dequeue-and-prepend if something 4202 * goes wrong. 4203 * the modification becomes a bit complicated since tulip_txput() might 4204 * copy and modify the mbuf passed. 4205 */ 4206 4207void 4208tulip_ifstart(struct ifnet * const ifp) 4209{ 4210 TULIP_PERFSTART(ifstart) 4211 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4212 4213 if (sc->tulip_if.if_flags & IFF_RUNNING) { 4214 4215 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 4216 tulip_txput_setup(sc); 4217 4218 while (!IFQ_IS_EMPTY(&sc->tulip_if.if_snd)) { 4219 struct mbuf *m, *m0; 4220 IFQ_POLL(&sc->tulip_if.if_snd, m); 4221 if (m == NULL) 4222 break; 4223 if ((m0 = tulip_txput(sc, m, 0)) != NULL) { 4224 if (m0 != m) 4225 /* should not happen */ 4226 printf("tulip_if_start: txput failed!\n"); 4227 break; 4228 } 4229 } 4230 } 4231 4232 TULIP_PERFEND(ifstart); 4233} 4234 4235void 4236tulip_ifwatchdog(struct ifnet *ifp) 4237{ 4238 TULIP_PERFSTART(ifwatchdog) 4239 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4240 4241#if defined(TULIP_DEBUG) 4242 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs; 4243 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz) 4244 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs; 4245 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs; 4246#endif /* TULIP_DEBUG */ 4247 4248 sc->tulip_if.if_timer = 1; 4249 /* 4250 * These should be rare so do a bulk test up front so we can just skip 4251 * them if needed. 4252 */ 4253 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) { 4254 /* 4255 * If the number of receive buffer is low, try to refill 4256 */ 4257 if (sc->tulip_flags & TULIP_RXBUFSLOW) 4258 tulip_rx_intr(sc); 4259 4260#if defined(TULIP_DEBUG) 4261 if (sc->tulip_flags & TULIP_SYSTEMERROR) { 4262 printf(TULIP_PRINTF_FMT ": %d system errors: last was %s\n", 4263 TULIP_PRINTF_ARGS, sc->tulip_system_errors, 4264 tulip_system_errors[sc->tulip_last_system_error]); 4265 } 4266#endif 4267 if (sc->tulip_statusbits) { 4268 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits); 4269 sc->tulip_statusbits = 0; 4270 } 4271 4272 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); 4273 } 4274 4275 if (sc->tulip_txtimer) 4276 tulip_tx_intr(sc); 4277 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { 4278 printf(TULIP_PRINTF_FMT ": transmission timeout\n", TULIP_PRINTF_ARGS); 4279 if (TULIP_DO_AUTOSENSE(sc)) { 4280 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4281 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 4282 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP); 4283 } 4284 tulip_reset(sc); 4285 tulip_init(sc); 4286 } 4287 4288 TULIP_PERFEND(ifwatchdog); 4289 TULIP_PERFMERGE(sc, perf_intr_cycles); 4290 TULIP_PERFMERGE(sc, perf_ifstart_cycles); 4291 TULIP_PERFMERGE(sc, perf_ifioctl_cycles); 4292 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); 4293 TULIP_PERFMERGE(sc, perf_timeout_cycles); 4294 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); 4295 TULIP_PERFMERGE(sc, perf_txput_cycles); 4296 TULIP_PERFMERGE(sc, perf_txintr_cycles); 4297 TULIP_PERFMERGE(sc, perf_rxintr_cycles); 4298 TULIP_PERFMERGE(sc, perf_rxget_cycles); 4299 TULIP_PERFMERGE(sc, perf_intr); 4300 TULIP_PERFMERGE(sc, perf_ifstart); 4301 TULIP_PERFMERGE(sc, perf_ifioctl); 4302 TULIP_PERFMERGE(sc, perf_ifwatchdog); 4303 TULIP_PERFMERGE(sc, perf_timeout); 4304 TULIP_PERFMERGE(sc, perf_ifstart_one); 4305 TULIP_PERFMERGE(sc, perf_txput); 4306 TULIP_PERFMERGE(sc, perf_txintr); 4307 TULIP_PERFMERGE(sc, perf_rxintr); 4308 TULIP_PERFMERGE(sc, perf_rxget); 4309} 4310 4311/* 4312 * All printf's are real as of now! 4313 */ 4314#ifdef printf 4315#undef printf 4316#endif 4317 4318int 4319tulip_busdma_allocmem(tulip_softc_t * const sc, size_t size, 4320 bus_dmamap_t *map_p, tulip_desc_t **desc_p) 4321{ 4322 bus_dma_segment_t segs[1]; 4323 int nsegs, error; 4324 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE, 4325 segs, sizeof(segs)/sizeof(segs[0]), 4326 &nsegs, BUS_DMA_NOWAIT); 4327 if (error == 0) { 4328 void *desc; 4329 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size, 4330 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); 4331 if (error == 0) { 4332 bus_dmamap_t map; 4333 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0, 4334 BUS_DMA_NOWAIT, &map); 4335 if (error == 0) { 4336 error = bus_dmamap_load(sc->tulip_dmatag, map, desc, 4337 size, NULL, BUS_DMA_NOWAIT); 4338 if (error) 4339 bus_dmamap_destroy(sc->tulip_dmatag, map); 4340 else 4341 *map_p = map; 4342 } 4343 if (error) 4344 bus_dmamem_unmap(sc->tulip_dmatag, desc, size); 4345 } 4346 if (error) 4347 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs); 4348 else 4349 *desc_p = desc; 4350 } 4351 return (error); 4352} 4353 4354int 4355tulip_busdma_init(tulip_softc_t * const sc) 4356{ 4357 int error = 0; 4358 4359 sc->tulip_setupdma = dma_alloc(sizeof(sc->tulip_setupdata), PR_WAITOK); 4360 4361 /* 4362 * Allocate dmamap for setup descriptor 4363 */ 4364 error = bus_dmamap_create(sc->tulip_dmatag, TULIP_SETUP, 2, 4365 TULIP_SETUP, 0, BUS_DMA_NOWAIT, &sc->tulip_setupmap); 4366 if (error == 0) { 4367 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap, 4368 sc->tulip_setupdma, TULIP_SETUP, NULL, BUS_DMA_NOWAIT); 4369 if (error) 4370 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap); 4371 } 4372 /* 4373 * Allocate space and dmamap for transmit ring 4374 */ 4375 if (error == 0) { 4376 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS, 4377 &sc->tulip_txdescmap, 4378 &sc->tulip_txdescs); 4379 } 4380 4381 /* 4382 * Allocate dmamaps for each transmit descriptor, and place on the 4383 * free list. 4384 */ 4385 if (error == 0) { 4386 while (error == 0 && sc->tulip_num_free_txmaps < TULIP_TXDESCS) { 4387 bus_dmamap_t map; 4388 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0) 4389 tulip_free_txmap(sc, map); 4390 } 4391 if (error) { 4392 while (sc->tulip_num_free_txmaps > 0) 4393 bus_dmamap_destroy(sc->tulip_dmatag, tulip_alloc_txmap(sc)); 4394 } 4395 } 4396 4397 /* 4398 * Allocate space and dmamap for receive ring 4399 */ 4400 if (error == 0) { 4401 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS, 4402 &sc->tulip_rxdescmap, 4403 &sc->tulip_rxdescs); 4404 } 4405 4406 /* 4407 * Allocate dmamaps for each receive descriptor, and place on the 4408 * free list. 4409 */ 4410 if (error == 0) { 4411 while (error == 0 && sc->tulip_num_free_rxmaps < TULIP_RXDESCS) { 4412 bus_dmamap_t map; 4413 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0) 4414 tulip_free_rxmap(sc, map); 4415 } 4416 if (error) { 4417 while (sc->tulip_num_free_rxmaps > 0) 4418 bus_dmamap_destroy(sc->tulip_dmatag, tulip_alloc_rxmap(sc)); 4419 } 4420 } 4421 return (error); 4422} 4423 4424void 4425tulip_initcsrs(tulip_softc_t * const sc, bus_addr_t csr_base, size_t csr_size) 4426{ 4427 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; 4428 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; 4429 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; 4430 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; 4431 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; 4432 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; 4433 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; 4434 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; 4435 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size; 4436 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size; 4437 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size; 4438 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size; 4439 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size; 4440 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size; 4441 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size; 4442 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size; 4443} 4444 4445void 4446tulip_initring(tulip_softc_t * const sc, tulip_ringinfo_t * const ri, 4447 tulip_desc_t *descs, int ndescs) 4448{ 4449 ri->ri_max = ndescs; 4450 ri->ri_first = descs; 4451 ri->ri_last = ri->ri_first + ri->ri_max; 4452 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 4453 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 4454} 4455 4456int 4457tulip_probe(struct device *parent, void *match, void *aux) 4458{ 4459 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 4460 4461 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID) 4462 return (0); 4463 if (PCI_CHIPID(pa->pa_id) == CHIPID_21040 4464 || PCI_CHIPID(pa->pa_id) == CHIPID_21041 4465 || PCI_CHIPID(pa->pa_id) == CHIPID_21140 4466 || PCI_CHIPID(pa->pa_id) == CHIPID_21142) 4467 return (2); 4468 4469 return (0); 4470} 4471 4472void 4473tulip_attach(struct device * const parent, struct device * const self, void * const aux) 4474{ 4475 tulip_softc_t * const sc = (tulip_softc_t *) self; 4476 struct pci_attach_args * const pa = (struct pci_attach_args *) aux; 4477 struct ifnet * const ifp = &sc->tulip_if; 4478 const int unit = sc->tulip_dev.dv_unit; 4479 int retval, idx; 4480 u_int32_t revinfo, cfdainfo, id; 4481 unsigned csroffset = TULIP_PCI_CSROFFSET; 4482 unsigned csrsize = TULIP_PCI_CSRSIZE; 4483 bus_addr_t csr_base; 4484 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN; 4485 4486 if (unit >= TULIP_MAX_DEVICES) { 4487 printf(": not configured; limit of %d reached or exceeded\n", 4488 TULIP_MAX_DEVICES); 4489 return; 4490 } 4491 4492 revinfo = PCI_CONF_READ(PCI_CFRV) & 0xFF; 4493 id = PCI_CONF_READ(PCI_CFID); 4494 cfdainfo = PCI_CONF_READ(PCI_CFDA); 4495 4496 if (PCI_VENDORID(id) == DEC_VENDORID) { 4497 if (PCI_CHIPID(id) == CHIPID_21040) 4498 chipid = TULIP_21040; 4499 else if (PCI_CHIPID(id) == CHIPID_21041) 4500 chipid = TULIP_21041; 4501 else if (PCI_CHIPID(id) == CHIPID_21140) 4502 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140; 4503 else if (PCI_CHIPID(id) == CHIPID_21142) 4504 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142; 4505 } 4506 4507 if (chipid == TULIP_CHIPID_UNKNOWN) 4508 return; 4509 4510 if ((chipid == TULIP_21040 || chipid == TULIP_DE425) && revinfo < 0x20) { 4511 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n", 4512 revinfo >> 4, revinfo & 0x0f); 4513 return; 4514 } else if (chipid == TULIP_21140 && revinfo < 0x11) { 4515 printf(": not configured; 21140 pass 1.1 required (%d.%d found)\n", 4516 revinfo >> 4, revinfo & 0x0f); 4517 return; 4518 } 4519 4520 PCI_GETBUSDEVINFO(sc); 4521 sc->tulip_chipid = chipid; 4522 sc->tulip_flags |= TULIP_DEVICEPROBE; 4523 if (chipid == TULIP_21140 || chipid == TULIP_21140A) 4524 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD; 4525 if (chipid == TULIP_21140A && revinfo <= 0x22) 4526 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW; 4527 if (chipid == TULIP_21140) 4528 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH; 4529 if (chipid != TULIP_21040 && chipid != TULIP_DE425 && chipid != TULIP_21140) 4530 sc->tulip_features |= TULIP_HAVE_POWERMGMT; 4531 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) { 4532 sc->tulip_features |= TULIP_HAVE_DUALSENSE; 4533 if (chipid != TULIP_21041 || revinfo >= 0x20) 4534 sc->tulip_features |= TULIP_HAVE_SIANWAY; 4535 if (chipid != TULIP_21041) 4536 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD; 4537 if (chipid != TULIP_21041 && revinfo >= 0x20) 4538 sc->tulip_features |= TULIP_HAVE_SIA100; 4539 } 4540 4541 if (sc->tulip_features & TULIP_HAVE_POWERMGMT 4542 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) { 4543 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE); 4544 PCI_CONF_WRITE(PCI_CFDA, cfdainfo); 4545 DELAY(11*1000); 4546 } 4547 4548 if (sc->tulip_features & TULIP_HAVE_STOREFWD) 4549 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 4550 4551 bcopy(self->dv_xname, sc->tulip_if.if_xname, IFNAMSIZ); 4552 sc->tulip_if.if_softc = sc; 4553 sc->tulip_pc = pa->pa_pc; 4554 sc->tulip_dmatag = pa->pa_dmat; 4555 sc->tulip_revinfo = revinfo; 4556 4557 timeout_set(&sc->tulip_stmo, tulip_timeout_callback, sc); 4558 4559 csr_base = 0; 4560 { 4561 bus_space_tag_t iot, memt; 4562 bus_space_handle_t ioh, memh; 4563 int ioh_valid, memh_valid; 4564 4565 ioh_valid = (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 4566 &iot, &ioh, NULL, NULL, 0) == 0); 4567 memh_valid = (pci_mapreg_map(pa, PCI_CBMA, 4568 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, 4569 &memt, &memh, NULL, NULL, 0) == 0); 4570 4571 if (memh_valid) { 4572 sc->tulip_bustag = memt; 4573 sc->tulip_bushandle = memh; 4574 } else if (ioh_valid) { 4575 sc->tulip_bustag = iot; 4576 sc->tulip_bushandle = ioh; 4577 } else { 4578 printf(": unable to map device registers\n"); 4579 return; 4580 } 4581 } 4582 4583 tulip_initcsrs(sc, csr_base + csroffset, csrsize); 4584 4585 if ((retval = tulip_busdma_init(sc)) != 0) { 4586 printf(": error initing bus_dma: %d\n", retval); 4587 return; 4588 } 4589 4590 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS); 4591 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS); 4592 4593 /* 4594 * Make sure there won't be any interrupts or such... 4595 */ 4596 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 4597 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at 4598 33MHz that comes to two microseconds but wait a 4599 bit longer anyways) */ 4600 4601 if ((retval = tulip_read_macaddr(sc)) < 0) { 4602 printf(", %s%s pass %d.%d", sc->tulip_boardid, 4603 tulip_chipdescs[sc->tulip_chipid], 4604 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F); 4605 printf(": can't read ENET ROM (why=%d) (", retval); 4606 for (idx = 0; idx < 32; idx++) 4607 printf("%02x", sc->tulip_rombuf[idx]); 4608 printf(", address unknown\n"); 4609 } else { 4610 int (*intr_rtn)(void *) = tulip_intr_normal; 4611 4612 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR) 4613 intr_rtn = tulip_intr_shared; 4614 4615 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) { 4616 pci_intr_handle_t intrhandle; 4617 const char *intrstr; 4618 4619 if (pci_intr_map(pa, &intrhandle)) { 4620 printf(": couldn't map interrupt\n"); 4621 return; 4622 } 4623 4624 intrstr = pci_intr_string(pa->pa_pc, intrhandle); 4625 sc->tulip_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, 4626 intr_rtn, sc, self->dv_xname); 4627 if (sc->tulip_ih == NULL) { 4628 printf(": couldn't establish interrupt"); 4629 if (intrstr != NULL) 4630 printf(" at %s", intrstr); 4631 printf("\n"); 4632 return; 4633 } 4634 4635 printf(", %s%s pass %d.%d%s: %s, address %s\n", 4636 sc->tulip_boardid, 4637 tulip_chipdescs[sc->tulip_chipid], 4638 (sc->tulip_revinfo & 0xF0) >> 4, 4639 sc->tulip_revinfo & 0x0F, 4640 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM)) 4641 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "", 4642 intrstr, ether_sprintf(sc->tulip_enaddr)); 4643 } 4644 4645 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; 4646 ifp->if_ioctl = tulip_ifioctl; 4647 ifp->if_start = tulip_ifstart; 4648 ifp->if_watchdog = tulip_ifwatchdog; 4649 ifp->if_timer = 1; 4650 4651 (*sc->tulip_boardsw->bd_media_probe)(sc); 4652 ifmedia_init(&sc->tulip_ifmedia, 0, 4653 tulip_ifmedia_change, tulip_ifmedia_status); 4654 sc->tulip_flags &= ~TULIP_DEVICEPROBE; 4655 tulip_ifmedia_add(sc); 4656 4657 tulip_reset(sc); 4658 4659 IFQ_SET_READY(&ifp->if_snd); 4660 if_attach(ifp); 4661 ether_ifattach(ifp); 4662 } 4663} 4664