if_de.c revision 1.128
1/* $OpenBSD: if_de.c,v 1.128 2015/11/23 23:34:42 dlg 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 /* 3055 * Free all the mbufs that were on the transmit ring. 3056 */ 3057 for (;;) { 3058 bus_dmamap_t map; 3059 struct mbuf *m; 3060 m = ml_dequeue(&sc->tulip_txq); 3061 if (m == NULL) 3062 break; 3063 map = TULIP_GETCTX(m, bus_dmamap_t); 3064 bus_dmamap_unload(sc->tulip_dmatag, map); 3065 tulip_free_txmap(sc, map); 3066 m_freem(m); 3067 } 3068 3069 ri = &sc->tulip_txinfo; 3070 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3071 ri->ri_free = ri->ri_max; 3072 for (di = ri->ri_first; di < ri->ri_last; di++) 3073 di->d_status = 0; 3074 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap, 3075 0, sc->tulip_txdescmap->dm_mapsize, 3076 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3077 3078 /* 3079 * We need to collect all the mbufs were on the 3080 * receive ring before we reinit it either to put 3081 * them back on or to know if we have to allocate 3082 * more. 3083 */ 3084 ri = &sc->tulip_rxinfo; 3085 ri->ri_nextin = ri->ri_nextout = ri->ri_first; 3086 ri->ri_free = ri->ri_max; 3087 for (di = ri->ri_first; di < ri->ri_last; di++) { 3088 di->d_status = 0; 3089 di->d_length1 = 0; di->d_addr1 = 0; 3090 di->d_length2 = 0; di->d_addr2 = 0; 3091 } 3092 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap, 3093 0, sc->tulip_rxdescmap->dm_mapsize, 3094 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); 3095 for (;;) { 3096 bus_dmamap_t map; 3097 struct mbuf *m; 3098 m = ml_dequeue(&sc->tulip_rxq); 3099 if (m == NULL) 3100 break; 3101 map = TULIP_GETCTX(m, bus_dmamap_t); 3102 bus_dmamap_unload(sc->tulip_dmatag, map); 3103 tulip_free_rxmap(sc, map); 3104 m_freem(m); 3105 } 3106 3107 /* 3108 * If tulip_reset is being called recurisvely, exit quickly knowing 3109 * that when the outer tulip_reset returns all the right stuff will 3110 * have happened. 3111 */ 3112 if (inreset) 3113 return; 3114 3115 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 3116 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 3117 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE 3118 |TULIP_STS_RXSTOPPED; 3119 3120 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) 3121 (*sc->tulip_boardsw->bd_media_select)(sc); 3122#if defined(TULIP_DEBUG) 3123 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET) 3124 printf(TULIP_PRINTF_FMT ": tulip_reset: additional reset needed?!?\n", 3125 TULIP_PRINTF_ARGS); 3126#endif 3127 tulip_media_print(sc); 3128 if (sc->tulip_features & TULIP_HAVE_DUALSENSE) 3129 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status)); 3130 3131 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET 3132 |TULIP_RXACT); 3133 tulip_addr_filter(sc); 3134} 3135 3136void 3137tulip_init(tulip_softc_t * const sc) 3138{ 3139 if (sc->tulip_if.if_flags & IFF_UP) { 3140 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) { 3141 /* initialize the media */ 3142 tulip_reset(sc); 3143 } 3144 sc->tulip_if.if_flags |= IFF_RUNNING; 3145 if (sc->tulip_if.if_flags & IFF_PROMISC) { 3146 sc->tulip_flags |= TULIP_PROMISC; 3147 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 3148 sc->tulip_intrmask |= TULIP_STS_TXINTR; 3149 } else { 3150 sc->tulip_flags &= ~TULIP_PROMISC; 3151 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 3152 if (sc->tulip_flags & TULIP_ALLMULTI) 3153 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 3154 else 3155 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 3156 } 3157 sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 3158 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) { 3159 tulip_rx_intr(sc); 3160 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3161 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3162 } else { 3163 sc->tulip_if.if_flags |= IFF_OACTIVE; 3164 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 3165 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 3166 } 3167 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3168 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3169 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 3170 tulip_txput_setup(sc); 3171 } else { 3172 sc->tulip_if.if_flags &= ~IFF_RUNNING; 3173 tulip_reset(sc); 3174 } 3175} 3176 3177void 3178tulip_rx_intr(tulip_softc_t * const sc) 3179{ 3180 TULIP_PERFSTART(rxintr) 3181 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; 3182 struct ifnet * const ifp = &sc->tulip_if; 3183 struct mbuf_list ml = MBUF_LIST_INITIALIZER(); 3184 int fillok = 1; 3185#if defined(TULIP_DEBUG) 3186 int cnt = 0; 3187#endif 3188 3189 for (;;) { 3190 TULIP_PERFSTART(rxget) 3191 tulip_desc_t *eop = ri->ri_nextin; 3192 int total_len = 0, last_offset = 0; 3193 struct mbuf *ms = NULL, *me = NULL; 3194 int accept = 0; 3195 bus_dmamap_t map; 3196 int error; 3197 3198 if (fillok && ml_len(&sc->tulip_rxq) < TULIP_RXQ_TARGET) 3199 goto queue_mbuf; 3200 3201#if defined(TULIP_DEBUG) 3202 if (cnt == ri->ri_max) 3203 break; 3204#endif 3205 /* 3206 * If the TULIP has no descriptors, there can't be any receive 3207 * descriptors to process. 3208 */ 3209 if (eop == ri->ri_nextout) 3210 break; 3211 3212 /* 3213 * 90% of the packets will fit in one descriptor. So we optimize 3214 * for that case. 3215 */ 3216 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3217 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) { 3218#ifdef DIAGNOSTIC 3219 if (ml_empty(&sc->tulip_rxq)) 3220 panic("%s: tulip_rxq empty", sc->tulip_if.if_xname); 3221#endif 3222 ms = ml_dequeue(&sc->tulip_rxq); 3223 me = ms; 3224 } else { 3225 /* 3226 * If still owned by the TULIP, don't touch it. 3227 */ 3228 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 3229 break; 3230 3231 /* 3232 * It is possible (though improbable unless MCLBYTES < 1518) for 3233 * a received packet to cross more than one receive descriptor. 3234 */ 3235 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { 3236 if (++eop == ri->ri_last) 3237 eop = ri->ri_first; 3238 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); 3239 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) { 3240 TULIP_PERFEND(rxget); 3241 goto out; 3242 } 3243 total_len++; 3244 } 3245 3246 /* 3247 * Dequeue the first buffer for the start of the packet. Hopefully 3248 * this will be the only one we need to dequeue. However, if the 3249 * packet consumed multiple descriptors, then we need to dequeue 3250 * those buffers and chain to the starting mbuf. All buffers but 3251 * the last buffer have the same length so we can set that now. 3252 * (we add to last_offset instead of multiplying since we normally 3253 * won't go into the loop and thereby saving a ourselves from 3254 * doing a multiplication by 0 in the normal case). 3255 */ 3256 ms = ml_dequeue(&sc->tulip_rxq); 3257 for (me = ms; total_len > 0; total_len--) { 3258 map = TULIP_GETCTX(me, bus_dmamap_t); 3259 TULIP_RXMAP_POSTSYNC(sc, map); 3260 bus_dmamap_unload(sc->tulip_dmatag, map); 3261 tulip_free_rxmap(sc, map); 3262 me->m_len = TULIP_RX_BUFLEN; 3263 last_offset += TULIP_RX_BUFLEN; 3264 me->m_next = ml_dequeue(&sc->tulip_rxq); 3265 me = me->m_next; 3266 } 3267 } 3268 3269 /* 3270 * Now get the size of received packet (minus the CRC). 3271 */ 3272 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; 3273 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0 3274 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0)) { 3275 me->m_len = total_len - last_offset; 3276 3277 map = TULIP_GETCTX(me, bus_dmamap_t); 3278 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len, 3279 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); 3280 bus_dmamap_unload(sc->tulip_dmatag, map); 3281 tulip_free_rxmap(sc, map); 3282 sc->tulip_flags |= TULIP_RXACT; 3283 accept = 1; 3284 } else { 3285 ifp->if_ierrors++; 3286 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) 3287 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3288 else { 3289#ifdef TULIP_DEBUG 3290 const char *error = NULL; 3291 if (eop->d_status & TULIP_DSTS_RxTOOLONG) { 3292 sc->tulip_dot3stats.dot3StatsFrameTooLongs++; 3293 error = "frame too long"; 3294 } 3295 if (eop->d_status & TULIP_DSTS_RxBADCRC) { 3296 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) { 3297 sc->tulip_dot3stats.dot3StatsAlignmentErrors++; 3298 error = "alignment error"; 3299 } else { 3300 sc->tulip_dot3stats.dot3StatsFCSErrors++; 3301 error = "bad crc"; 3302 } 3303 } 3304 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) { 3305 printf(TULIP_PRINTF_FMT ": receive: %s: %s\n", 3306 TULIP_PRINTF_ARGS, 3307 ether_sprintf(mtod(ms, u_char *) + 6), 3308 error); 3309 sc->tulip_flags |= TULIP_NOMESSAGES; 3310 } 3311#endif 3312 } 3313 3314 map = TULIP_GETCTX(me, bus_dmamap_t); 3315 bus_dmamap_unload(sc->tulip_dmatag, map); 3316 tulip_free_rxmap(sc, map); 3317 } 3318#if defined(TULIP_DEBUG) 3319 cnt++; 3320#endif 3321 if (++eop == ri->ri_last) 3322 eop = ri->ri_first; 3323 ri->ri_nextin = eop; 3324 queue_mbuf: 3325 /* 3326 * Either we are priming the TULIP with mbufs (m == NULL) 3327 * or we are about to accept an mbuf for the upper layers 3328 * so we need to allocate an mbuf to replace it. If we 3329 * can't replace it, send up it anyways. This may cause 3330 * us to drop packets in the future but that's better than 3331 * being caught in livelock. 3332 * 3333 * Note that if this packet crossed multiple descriptors 3334 * we don't even try to reallocate all the mbufs here. 3335 * Instead we rely on the test of the beginning of 3336 * the loop to refill for the extra consumed mbufs. 3337 */ 3338 if (accept || ms == NULL) { 3339 struct mbuf *m0; 3340 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3341 if (m0 != NULL) { 3342#if defined(TULIP_COPY_RXDATA) 3343 if (!accept || total_len >= (MHLEN - 2)) { 3344#endif 3345 MCLGET(m0, M_DONTWAIT); 3346 if ((m0->m_flags & M_EXT) == 0) { 3347 m_freem(m0); 3348 m0 = NULL; 3349 } 3350#if defined(TULIP_COPY_RXDATA) 3351 } 3352#endif 3353 } 3354 if (accept 3355#if defined(TULIP_COPY_RXDATA) 3356 && m0 != NULL 3357#endif 3358 ) { 3359#if !defined(TULIP_COPY_RXDATA) 3360 ms->m_pkthdr.len = total_len; 3361 ml_enqueue(&ml, ms); 3362#else 3363 m0->m_data += 2; /* align data after header */ 3364 m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); 3365 m0->m_len = m0->m_pkthdr.len = total_len; 3366 ml_enqueue(&ml, m0); 3367 m0 = ms; 3368#endif 3369 } 3370 ms = m0; 3371 } 3372 if (ms == NULL) { 3373 /* 3374 * Couldn't allocate a new buffer. Don't bother 3375 * trying to replenish the receive queue. 3376 */ 3377 fillok = 0; 3378 sc->tulip_flags |= TULIP_RXBUFSLOW; 3379#if defined(TULIP_DEBUG) 3380 sc->tulip_dbg.dbg_rxlowbufs++; 3381#endif 3382 TULIP_PERFEND(rxget); 3383 continue; 3384 } 3385 /* 3386 * Now give the buffer(s) to the TULIP and save in our 3387 * receive queue. 3388 */ 3389 do { 3390 tulip_desc_t * const nextout = ri->ri_nextout; 3391 if (sc->tulip_num_free_rxmaps > 0) { 3392 map = tulip_alloc_rxmap(sc); 3393 } else { 3394 m_freem(ms); 3395 sc->tulip_flags |= TULIP_RXBUFSLOW; 3396#if defined(TULIP_DEBUG) 3397 sc->tulip_dbg.dbg_rxlowbufs++; 3398#endif 3399 break; 3400 } 3401 TULIP_SETCTX(ms, map); 3402 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *), 3403 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT); 3404 if (error) { 3405 printf(TULIP_PRINTF_FMT ": unable to load rx map, " 3406 "error = %d\n", TULIP_PRINTF_ARGS, error); 3407 panic("tulip_rx_intr"); /* XXX */ 3408 } 3409 nextout->d_addr1 = map->dm_segs[0].ds_addr; 3410 nextout->d_length1 = map->dm_segs[0].ds_len; 3411 if (map->dm_nsegs == 2) { 3412 nextout->d_addr2 = map->dm_segs[1].ds_addr; 3413 nextout->d_length2 = map->dm_segs[1].ds_len; 3414 } else { 3415 nextout->d_addr2 = 0; 3416 nextout->d_length2 = 0; 3417 } 3418 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout)); 3419 nextout->d_status = TULIP_DSTS_OWNER; 3420 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t)); 3421 if (++ri->ri_nextout == ri->ri_last) 3422 ri->ri_nextout = ri->ri_first; 3423 me = ms->m_next; 3424 ms->m_next = NULL; 3425 ml_enqueue(&sc->tulip_rxq, ms); 3426 } while ((ms = me) != NULL); 3427 3428 if (ml_len(&sc->tulip_rxq) >= TULIP_RXQ_TARGET) 3429 sc->tulip_flags &= ~TULIP_RXBUFSLOW; 3430 TULIP_PERFEND(rxget); 3431 } 3432out: 3433 if_input(ifp, &ml); 3434 3435#if defined(TULIP_DEBUG) 3436 sc->tulip_dbg.dbg_rxintrs++; 3437 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; 3438#endif 3439 TULIP_PERFEND(rxintr); 3440} 3441 3442int 3443tulip_tx_intr(tulip_softc_t * const sc) 3444{ 3445 TULIP_PERFSTART(txintr) 3446 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3447 struct mbuf *m; 3448 int xmits = 0; 3449 int descs = 0; 3450 3451 while (ri->ri_free < ri->ri_max) { 3452 u_int32_t d_flag; 3453 3454 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin)); 3455 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 3456 break; 3457 3458 ri->ri_free++; 3459 descs++; 3460 d_flag = ri->ri_nextin->d_flag; 3461 if (d_flag & TULIP_DFLAG_TxLASTSEG) { 3462 if (d_flag & TULIP_DFLAG_TxSETUPPKT) { 3463 /* 3464 * We've just finished processing a setup packet. 3465 * Mark that we finished it. If there's not 3466 * another pending, startup the TULIP receiver. 3467 * Make sure we ack the RXSTOPPED so we won't get 3468 * an abormal interrupt indication. 3469 */ 3470 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap); 3471 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY); 3472 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT) 3473 sc->tulip_flags |= TULIP_HASHONLY; 3474 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) { 3475 tulip_rx_intr(sc); 3476 sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 3477 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 3478 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3479 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3480 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3481 } 3482 } else { 3483 const u_int32_t d_status = ri->ri_nextin->d_status; 3484 m = ml_dequeue(&sc->tulip_txq); 3485 if (m != NULL) { 3486 bus_dmamap_t map = TULIP_GETCTX(m, bus_dmamap_t); 3487 TULIP_TXMAP_POSTSYNC(sc, map); 3488 tulip_free_txmap(sc, map); 3489#if NBPFILTER > 0 3490 if (sc->tulip_bpf != NULL) 3491 bpf_mtap(sc->tulip_if.if_bpf, m, BPF_DIRECTION_OUT); 3492#endif 3493 m_freem(m); 3494 } 3495 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 3496 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; 3497 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { 3498#if defined(TULIP_DEBUG) 3499 if (d_status & TULIP_DSTS_TxNOCARR) 3500 sc->tulip_dbg.dbg_txprobe_nocarr++; 3501 if (d_status & TULIP_DSTS_TxEXCCOLL) 3502 sc->tulip_dbg.dbg_txprobe_exccoll++; 3503#endif 3504 event = TULIP_MEDIAPOLL_TXPROBE_FAILED; 3505 } 3506 (*sc->tulip_boardsw->bd_media_poll)(sc, event); 3507 /* 3508 * Escape from the loop before media poll has reset the TULIP! 3509 */ 3510 break; 3511 } else { 3512 xmits++; 3513 if (d_status & TULIP_DSTS_ERRSUM) { 3514 sc->tulip_if.if_oerrors++; 3515 if (d_status & TULIP_DSTS_TxEXCCOLL) 3516 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; 3517 if (d_status & TULIP_DSTS_TxLATECOLL) 3518 sc->tulip_dot3stats.dot3StatsLateCollisions++; 3519 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) 3520 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; 3521 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) 3522 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; 3523 if (d_status & TULIP_DSTS_TxUNDERFLOW) 3524 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; 3525 if (d_status & TULIP_DSTS_TxBABBLE) 3526 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; 3527 } else { 3528 u_int32_t collisions = 3529 (d_status & TULIP_DSTS_TxCOLLMASK) 3530 >> TULIP_DSTS_V_TxCOLLCNT; 3531 sc->tulip_if.if_collisions += collisions; 3532 if (collisions == 1) 3533 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; 3534 else if (collisions > 1) 3535 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; 3536 else if (d_status & TULIP_DSTS_TxDEFERRED) 3537 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; 3538 /* 3539 * SQE is only valid for 10baseT/BNC/AUI when not 3540 * running in full-duplex. In order to speed up the 3541 * test, the corresponding bit in tulip_flags needs to 3542 * set as well to get us to count SQE Test Errors. 3543 */ 3544 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) 3545 sc->tulip_dot3stats.dot3StatsSQETestErrors++; 3546 } 3547 } 3548 } 3549 } 3550 3551 if (++ri->ri_nextin == ri->ri_last) 3552 ri->ri_nextin = ri->ri_first; 3553 3554 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3555 sc->tulip_if.if_flags &= ~IFF_OACTIVE; 3556 } 3557 /* 3558 * If nothing left to transmit, disable the timer. 3559 * Else if progress, reset the timer back to 2 ticks. 3560 */ 3561 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE)) 3562 sc->tulip_txtimer = 0; 3563 else if (xmits > 0) 3564 sc->tulip_txtimer = TULIP_TXTIMER; 3565 sc->tulip_if.if_opackets += xmits; 3566 TULIP_PERFEND(txintr); 3567 return (descs); 3568} 3569 3570void 3571tulip_print_abnormal_interrupt(tulip_softc_t * const sc, u_int32_t csr) 3572{ 3573#ifdef TULIP_DEBUG 3574 const char * const *msgp = tulip_status_bits; 3575 const char *sep; 3576 u_int32_t mask; 3577 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024\0"; 3578 3579 csr &= (1 << (nitems(tulip_status_bits))) - 1; 3580 printf(TULIP_PRINTF_FMT ": abnormal interrupt:", TULIP_PRINTF_ARGS); 3581 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { 3582 if ((csr & mask) && *msgp != NULL) { 3583 printf("%s%s", sep, *msgp); 3584 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { 3585 sc->tulip_flags &= ~TULIP_NEWTXTHRESH; 3586 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) 3587 printf(" (switching to store-and-forward mode)"); 3588 else { 3589 printf(" (raising TX threshold to %s)", 3590 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); 3591 } 3592 } 3593 sep = ", "; 3594 } 3595 } 3596 printf("\n"); 3597#endif 3598} 3599 3600void 3601tulip_intr_handler(tulip_softc_t * const sc, int *progress_p) 3602{ 3603 TULIP_PERFSTART(intr) 3604 u_int32_t csr; 3605 3606 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { 3607 *progress_p = 1; 3608 TULIP_CSR_WRITE(sc, csr_status, csr); 3609 3610 if (csr & TULIP_STS_SYSERROR) { 3611 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT; 3612 if (sc->tulip_flags & TULIP_NOMESSAGES) 3613 sc->tulip_flags |= TULIP_SYSTEMERROR; 3614 else { 3615#if defined(TULIP_DEBUG) 3616 printf(TULIP_PRINTF_FMT ": system error: %s\n", 3617 TULIP_PRINTF_ARGS, 3618 tulip_system_errors[sc->tulip_last_system_error]); 3619#endif 3620 } 3621 sc->tulip_flags |= TULIP_NEEDRESET; 3622 sc->tulip_system_errors++; 3623 break; 3624 } 3625 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) { 3626#if defined(TULIP_DEBUG) 3627 sc->tulip_dbg.dbg_link_intrs++; 3628#endif 3629 if (sc->tulip_boardsw->bd_media_poll != NULL) { 3630 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL 3631 ? TULIP_MEDIAPOLL_LINKFAIL 3632 : TULIP_MEDIAPOLL_LINKPASS); 3633 csr &= ~TULIP_STS_ABNRMLINTR; 3634 } 3635 tulip_media_print(sc); 3636 } 3637 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) { 3638 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames); 3639 if (csr & TULIP_STS_RXNOBUF) 3640 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF; 3641 /* 3642 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data 3643 * on receive overflows. 3644 */ 3645 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) { 3646 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; 3647 /* 3648 * Stop the receiver process and spin until it's stopped. 3649 * Tell rx_intr to drop the packets it dequeues. 3650 */ 3651 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN); 3652 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0) 3653 ; 3654 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); 3655 sc->tulip_flags |= TULIP_RXIGNORE; 3656 } 3657 tulip_rx_intr(sc); 3658 if (sc->tulip_flags & TULIP_RXIGNORE) { 3659 /* 3660 * Restart the receiver. 3661 */ 3662 sc->tulip_flags &= ~TULIP_RXIGNORE; 3663 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3664 } 3665 } 3666 if (csr & TULIP_STS_ABNRMLINTR) { 3667 u_int32_t tmp = csr & sc->tulip_intrmask 3668 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); 3669 if (csr & TULIP_STS_TXUNDERFLOW) { 3670#if defined(TULIP_DEBUG) 3671 printf ("Underflow interrupt\n"); 3672#endif 3673 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { 3674 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; 3675 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3676 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { 3677 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 3678 sc->tulip_flags |= TULIP_NEWTXTHRESH; 3679 } 3680 } 3681 if (sc->tulip_flags & TULIP_NOMESSAGES) 3682 sc->tulip_statusbits |= tmp; 3683 else { 3684 tulip_print_abnormal_interrupt(sc, tmp); 3685 sc->tulip_flags |= TULIP_NOMESSAGES; 3686 } 3687 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); 3688 } 3689 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { 3690 tulip_tx_intr(sc); 3691 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) 3692 tulip_ifstart(&sc->tulip_if); 3693 } 3694 } 3695 if (sc->tulip_flags & TULIP_NEEDRESET) { 3696 tulip_reset(sc); 3697 tulip_init(sc); 3698 } 3699 TULIP_PERFEND(intr); 3700} 3701 3702int 3703tulip_intr_shared(void *arg) 3704{ 3705 tulip_softc_t * sc = arg; 3706 int progress = 0; 3707 3708 for (; sc != NULL; sc = sc->tulip_slaves) { 3709#if defined(TULIP_DEBUG) 3710 sc->tulip_dbg.dbg_intrs++; 3711#endif 3712 tulip_intr_handler(sc, &progress); 3713 } 3714 return (progress); 3715} 3716 3717int 3718tulip_intr_normal(void *arg) 3719{ 3720 tulip_softc_t * sc = (tulip_softc_t *) arg; 3721 int progress = 0; 3722 3723#if defined(TULIP_DEBUG) 3724 sc->tulip_dbg.dbg_intrs++; 3725#endif 3726 tulip_intr_handler(sc, &progress); 3727 3728 return (progress); 3729} 3730 3731struct mbuf * 3732tulip_mbuf_compress(struct mbuf *m) 3733{ 3734 struct mbuf *m0; 3735#if MCLBYTES >= ETHERMTU + 18 3736 MGETHDR(m0, M_DONTWAIT, MT_DATA); 3737 if (m0 != NULL) { 3738 if (m->m_pkthdr.len > MHLEN) { 3739 MCLGET(m0, M_DONTWAIT); 3740 if ((m0->m_flags & M_EXT) == 0) { 3741 m_freem(m); 3742 m_freem(m0); 3743 return (NULL); 3744 } 3745 } 3746 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 3747 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 3748 } 3749#else 3750 int mlen = MHLEN; 3751 int len = m->m_pkthdr.len; 3752 struct mbuf **mp = &m0; 3753 3754 while (len > 0) { 3755 if (mlen == MHLEN) 3756 MGETHDR(*mp, M_DONTWAIT, MT_DATA); 3757 else 3758 MGET(*mp, M_DONTWAIT, MT_DATA); 3759 if (*mp == NULL) { 3760 m_freem(m0); 3761 m0 = NULL; 3762 break; 3763 } 3764 if (len > MLEN) { 3765 MCLGET(*mp, M_DONTWAIT); 3766 if (((*mp)->m_flags & M_EXT) == 0) { 3767 m_freem(m0); 3768 m0 = NULL; 3769 break; 3770 } 3771 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; 3772 else 3773 (*mp)->m_len = len <= mlen ? len : mlen; 3774 m_copydata(m, m->m_pkthdr.len - len, 3775 (*mp)->m_len, mtod((*mp), caddr_t)); 3776 len -= (*mp)->m_len; 3777 mp = &(*mp)->m_next; 3778 mlen = MLEN; 3779 } 3780#endif 3781 m_freem(m); 3782 return (m0); 3783} 3784 3785struct mbuf * 3786tulip_txput(tulip_softc_t * const sc, struct mbuf *m, int notonqueue) 3787{ 3788 TULIP_PERFSTART(txput) 3789 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 3790 tulip_desc_t *eop, *nextout; 3791 int segcnt, freedescs; 3792 u_int32_t d_status; 3793 bus_dmamap_t map; 3794 struct ifnet *ifp = &sc->tulip_if; 3795 3796#if defined(TULIP_DEBUG) 3797 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 3798 printf(TULIP_PRINTF_FMT ": txput%s: tx not running\n", 3799 TULIP_PRINTF_ARGS, 3800 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); 3801 sc->tulip_flags |= TULIP_WANTTXSTART; 3802 sc->tulip_dbg.dbg_txput_finishes[0]++; 3803 goto finish; 3804 } 3805#endif 3806 3807 /* 3808 * Now we try to fill in our transmit descriptors. This is 3809 * a bit reminiscent of going on the Ark two by two 3810 * since each descriptor for the TULIP can describe 3811 * two buffers. So we advance through packet filling 3812 * each of the two entries at a time to to fill each 3813 * descriptor. Clear the first and last segment bits 3814 * in each descriptor (actually just clear everything 3815 * but the end-of-ring or chain bits) to make sure 3816 * we don't get messed up by previously sent packets. 3817 * 3818 * We may fail to put the entire packet on the ring if 3819 * there is either not enough ring entries free or if the 3820 * packet has more than MAX_TXSEG segments. In the former 3821 * case we will just wait for the ring to empty. In the 3822 * latter case we have to recopy. 3823 */ 3824 d_status = 0; 3825 eop = nextout = ri->ri_nextout; 3826 segcnt = 0; 3827 freedescs = ri->ri_free; 3828 3829 /* 3830 * Reclaim some DMA maps from if we are out. 3831 */ 3832 if (sc->tulip_num_free_txmaps == 0) { 3833#if defined(TULIP_DEBUG) 3834 sc->tulip_dbg.dbg_no_txmaps++; 3835#endif 3836 freedescs += tulip_tx_intr(sc); 3837 } 3838 if (sc->tulip_num_free_txmaps > 0) 3839 map = tulip_alloc_txmap(sc); 3840 else { 3841 sc->tulip_flags |= TULIP_WANTTXSTART; 3842#if defined(TULIP_DEBUG) 3843 sc->tulip_dbg.dbg_txput_finishes[1]++; 3844#endif 3845 goto finish; 3846 } 3847 switch (bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT)) { 3848 case 0: 3849 break; 3850 case EFBIG: 3851 /* 3852 * The packet exceeds the number of transmit buffer 3853 * entries that we can use for one packet, so we have 3854 * to recopy it into one mbuf and then try again. 3855 */ 3856 if (m_defrag(m, M_DONTWAIT) == 0 && 3857 bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT) == 0) 3858 break; 3859 /* FALLTHROUGH */ 3860 default: 3861 tulip_free_txmap(sc, map); 3862 goto finish; 3863 } 3864 3865 if ((freedescs -= (map->dm_nsegs + 1) / 2) <= 0 3866 /* 3867 * See if there's any unclaimed space in the transmit ring. 3868 */ 3869 && (freedescs += tulip_tx_intr(sc)) <= 0) { 3870 /* 3871 * There's no more room but since nothing 3872 * has been committed at this point, just 3873 * show output is active, put back the 3874 * mbuf and return. 3875 */ 3876 sc->tulip_flags |= TULIP_WANTTXSTART; 3877#if defined(TULIP_DEBUG) 3878 sc->tulip_dbg.dbg_txput_finishes[4]++; 3879#endif 3880 bus_dmamap_unload(sc->tulip_dmatag, map); 3881 tulip_free_txmap(sc, map); 3882 goto finish; 3883 } 3884 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) { 3885 eop = nextout; 3886 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 3887 eop->d_status = d_status; 3888 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 3889 eop->d_length1 = map->dm_segs[segcnt].ds_len; 3890 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr; 3891 eop->d_length2 = map->dm_segs[segcnt+1].ds_len; 3892 d_status = TULIP_DSTS_OWNER; 3893 if (++nextout == ri->ri_last) 3894 nextout = ri->ri_first; 3895 } 3896 if (segcnt < map->dm_nsegs) { 3897 eop = nextout; 3898 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 3899 eop->d_status = d_status; 3900 eop->d_addr1 = map->dm_segs[segcnt].ds_addr; 3901 eop->d_length1 = map->dm_segs[segcnt].ds_len; 3902 eop->d_addr2 = 0; 3903 eop->d_length2 = 0; 3904 if (++nextout == ri->ri_last) 3905 nextout = ri->ri_first; 3906 } 3907 TULIP_TXMAP_PRESYNC(sc, map); 3908 3909 /* 3910 * The descriptors have been filled in. Now get ready 3911 * to transmit. 3912 */ 3913 if (!notonqueue) 3914 ifq_deq_commit(&ifp->if_snd, m); 3915 3916 TULIP_SETCTX(m, map); 3917 map = NULL; 3918 3919 ml_enqueue(&sc->tulip_txq, m); 3920 m = NULL; 3921 3922 /* 3923 * Make sure the next descriptor after this packet is owned 3924 * by us since it may have been set up above if we ran out 3925 * of room in the ring. 3926 */ 3927 nextout->d_status = 0; 3928 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 3929 3930 /* 3931 * Mark the last and first segments, indicate we want a transmit 3932 * complete interrupt, and tell it to transmit! 3933 */ 3934 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 3935 3936 /* 3937 * Note that ri->ri_nextout is still the start of the packet 3938 * and until we set the OWNER bit, we can still back out of 3939 * everything we have done. 3940 */ 3941 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 3942 if (eop < ri->ri_nextout) { 3943 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 3944 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout); 3945 TULIP_TXDESC_PRESYNC(sc, ri->ri_first, 3946 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first); 3947 } else { 3948 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, 3949 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout); 3950 } 3951 ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 3952 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 3953 3954 /* 3955 * This advances the ring for us. 3956 */ 3957 ri->ri_nextout = nextout; 3958 ri->ri_free = freedescs; 3959 3960 TULIP_PERFEND(txput); 3961 3962 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { 3963 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 3964 sc->tulip_if.if_flags |= IFF_OACTIVE; 3965 sc->tulip_if.if_start = tulip_ifstart; 3966 TULIP_PERFEND(txput); 3967 return (NULL); 3968 } 3969 3970 /* 3971 * switch back to the single queueing ifstart. 3972 */ 3973 sc->tulip_flags &= ~TULIP_WANTTXSTART; 3974 if (sc->tulip_txtimer == 0) 3975 sc->tulip_txtimer = TULIP_TXTIMER; 3976#if defined(TULIP_DEBUG) 3977 sc->tulip_dbg.dbg_txput_finishes[5]++; 3978#endif 3979 3980 /* 3981 * If we want a txstart, there must be not enough space in the 3982 * transmit ring. So we want to enable transmit done interrupts 3983 * so we can immediately reclaim some space. When the transmit 3984 * interrupt is posted, the interrupt handler will call tx_intr 3985 * to reclaim space and then txstart (since WANTTXSTART is set). 3986 * txstart will move the packet into the transmit ring and clear 3987 * WANTTXSTART thereby causing TXINTR to be cleared. 3988 */ 3989 finish: 3990#if defined(TULIP_DEBUG) 3991 sc->tulip_dbg.dbg_txput_finishes[6]++; 3992#endif 3993 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { 3994 sc->tulip_if.if_flags |= IFF_OACTIVE; 3995 sc->tulip_if.if_start = tulip_ifstart; 3996 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 3997 sc->tulip_intrmask |= TULIP_STS_TXINTR; 3998 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 3999 } 4000 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { 4001 if (sc->tulip_intrmask & TULIP_STS_TXINTR) { 4002 sc->tulip_intrmask &= ~TULIP_STS_TXINTR; 4003 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4004 } 4005 } 4006 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4007 TULIP_PERFEND(txput); 4008 return (m); 4009} 4010 4011void 4012tulip_txput_setup(tulip_softc_t * const sc) 4013{ 4014 tulip_ringinfo_t * const ri = &sc->tulip_txinfo; 4015 tulip_desc_t *nextout; 4016 4017 /* 4018 * We will transmit, at most, one setup packet per call to ifstart. 4019 */ 4020 4021#if defined(TULIP_DEBUG) 4022 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { 4023 printf(TULIP_PRINTF_FMT ": txput_setup: tx not running\n", 4024 TULIP_PRINTF_ARGS); 4025 sc->tulip_flags |= TULIP_WANTTXSTART; 4026 sc->tulip_if.if_start = tulip_ifstart; 4027 return; 4028 } 4029#endif 4030 /* 4031 * Try to reclaim some free descriptors.. 4032 */ 4033 if (ri->ri_free < 2) 4034 tulip_tx_intr(sc); 4035 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 4036 sc->tulip_flags |= TULIP_WANTTXSTART; 4037 sc->tulip_if.if_start = tulip_ifstart; 4038 return; 4039 } 4040 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 4041 sizeof(sc->tulip_setupdata)); 4042 /* 4043 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is 4044 * set and DOINGSETUP is clear doing an XOR of the two will DTRT. 4045 */ 4046 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; 4047 ri->ri_free--; 4048 nextout = ri->ri_nextout; 4049 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 4050 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 4051 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 4052 if (sc->tulip_flags & TULIP_WANTHASHPERFECT) 4053 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 4054 else if (sc->tulip_flags & TULIP_WANTHASHONLY) 4055 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; 4056 4057 nextout->d_length2 = 0; 4058 nextout->d_addr2 = 0; 4059 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len; 4060 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr; 4061 if (sc->tulip_setupmap->dm_nsegs == 2) { 4062 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len; 4063 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr; 4064 } 4065 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap); 4066 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout)); 4067 4068 /* 4069 * Advance the ring for the next transmit packet. 4070 */ 4071 if (++ri->ri_nextout == ri->ri_last) 4072 ri->ri_nextout = ri->ri_first; 4073 4074 /* 4075 * Make sure the next descriptor is owned by us since it 4076 * may have been set up above if we ran out of room in the 4077 * ring. 4078 */ 4079 ri->ri_nextout->d_status = 0; 4080 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); 4081 nextout->d_status = TULIP_DSTS_OWNER; 4082 /* 4083 * Flush the ownwership of the current descriptor 4084 */ 4085 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); 4086 TULIP_CSR_WRITE(sc, csr_txpoll, 1); 4087 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { 4088 sc->tulip_intrmask |= TULIP_STS_TXINTR; 4089 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); 4090 } 4091} 4092 4093/* 4094 * This routine is entered at splnet(). 4095 */ 4096int 4097tulip_ifioctl(struct ifnet * ifp, u_long cmd, caddr_t data) 4098{ 4099 TULIP_PERFSTART(ifioctl) 4100 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4101 struct ifreq *ifr = (struct ifreq *) data; 4102 int s; 4103 int error = 0; 4104 4105 s = splnet(); 4106 4107 switch (cmd) { 4108 case SIOCSIFADDR: { 4109 ifp->if_flags |= IFF_UP; 4110 tulip_init(sc); 4111 break; 4112 } 4113 4114 case SIOCSIFFLAGS: { 4115 tulip_init(sc); 4116 break; 4117 } 4118 4119 case SIOCSIFMEDIA: 4120 case SIOCGIFMEDIA: { 4121 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd); 4122 break; 4123 } 4124 4125 default: 4126 error = ether_ioctl(ifp, &sc->tulip_ac, cmd, data); 4127 } 4128 4129 if (error == ENETRESET) { 4130 if (ifp->if_flags & IFF_RUNNING) { 4131 tulip_addr_filter(sc); /* reset multicast filtering */ 4132 tulip_init(sc); 4133 } 4134 error = 0; 4135 } 4136 4137 splx(s); 4138 TULIP_PERFEND(ifioctl); 4139 return (error); 4140} 4141 4142/* 4143 * the original dequeueing policy is dequeue-and-prepend if something 4144 * goes wrong. 4145 * the modification becomes a bit complicated since tulip_txput() might 4146 * copy and modify the mbuf passed. 4147 */ 4148 4149void 4150tulip_ifstart(struct ifnet * const ifp) 4151{ 4152 TULIP_PERFSTART(ifstart) 4153 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4154 struct mbuf *m, *m0; 4155 4156 if (sc->tulip_if.if_flags & IFF_RUNNING) { 4157 4158 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) 4159 tulip_txput_setup(sc); 4160 4161 for (;;) { 4162 m = ifq_deq_begin(&sc->tulip_if.if_snd); 4163 if (m == NULL) 4164 break; 4165 m0 = tulip_txput(sc, m, 0); 4166 if (m0 != NULL) { 4167 KASSERT(m == m0); 4168 ifq_deq_rollback(&sc->tulip_if.if_snd, m); 4169 break; 4170 } 4171 } 4172 } 4173 4174 TULIP_PERFEND(ifstart); 4175} 4176 4177void 4178tulip_ifwatchdog(struct ifnet *ifp) 4179{ 4180 TULIP_PERFSTART(ifwatchdog) 4181 tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); 4182 4183#if defined(TULIP_DEBUG) 4184 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs; 4185 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz) 4186 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs; 4187 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs; 4188#endif /* TULIP_DEBUG */ 4189 4190 sc->tulip_if.if_timer = 1; 4191 /* 4192 * These should be rare so do a bulk test up front so we can just skip 4193 * them if needed. 4194 */ 4195 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) { 4196 /* 4197 * If the number of receive buffer is low, try to refill 4198 */ 4199 if (sc->tulip_flags & TULIP_RXBUFSLOW) 4200 tulip_rx_intr(sc); 4201 4202#if defined(TULIP_DEBUG) 4203 if (sc->tulip_flags & TULIP_SYSTEMERROR) { 4204 printf(TULIP_PRINTF_FMT ": %d system errors: last was %s\n", 4205 TULIP_PRINTF_ARGS, sc->tulip_system_errors, 4206 tulip_system_errors[sc->tulip_last_system_error]); 4207 } 4208#endif 4209 if (sc->tulip_statusbits) { 4210 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits); 4211 sc->tulip_statusbits = 0; 4212 } 4213 4214 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); 4215 } 4216 4217 if (sc->tulip_txtimer) 4218 tulip_tx_intr(sc); 4219 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { 4220 printf(TULIP_PRINTF_FMT ": transmission timeout\n", TULIP_PRINTF_ARGS); 4221 if (TULIP_DO_AUTOSENSE(sc)) { 4222 sc->tulip_media = TULIP_MEDIA_UNKNOWN; 4223 sc->tulip_probe_state = TULIP_PROBE_INACTIVE; 4224 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP); 4225 } 4226 tulip_reset(sc); 4227 tulip_init(sc); 4228 } 4229 4230 TULIP_PERFEND(ifwatchdog); 4231 TULIP_PERFMERGE(sc, perf_intr_cycles); 4232 TULIP_PERFMERGE(sc, perf_ifstart_cycles); 4233 TULIP_PERFMERGE(sc, perf_ifioctl_cycles); 4234 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); 4235 TULIP_PERFMERGE(sc, perf_timeout_cycles); 4236 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); 4237 TULIP_PERFMERGE(sc, perf_txput_cycles); 4238 TULIP_PERFMERGE(sc, perf_txintr_cycles); 4239 TULIP_PERFMERGE(sc, perf_rxintr_cycles); 4240 TULIP_PERFMERGE(sc, perf_rxget_cycles); 4241 TULIP_PERFMERGE(sc, perf_intr); 4242 TULIP_PERFMERGE(sc, perf_ifstart); 4243 TULIP_PERFMERGE(sc, perf_ifioctl); 4244 TULIP_PERFMERGE(sc, perf_ifwatchdog); 4245 TULIP_PERFMERGE(sc, perf_timeout); 4246 TULIP_PERFMERGE(sc, perf_ifstart_one); 4247 TULIP_PERFMERGE(sc, perf_txput); 4248 TULIP_PERFMERGE(sc, perf_txintr); 4249 TULIP_PERFMERGE(sc, perf_rxintr); 4250 TULIP_PERFMERGE(sc, perf_rxget); 4251} 4252 4253/* 4254 * All printf's are real as of now! 4255 */ 4256#ifdef printf 4257#undef printf 4258#endif 4259 4260int 4261tulip_busdma_allocmem(tulip_softc_t * const sc, size_t size, 4262 bus_dmamap_t *map_p, tulip_desc_t **desc_p) 4263{ 4264 bus_dma_segment_t segs[1]; 4265 int nsegs, error; 4266 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE, 4267 segs, sizeof(segs)/sizeof(segs[0]), 4268 &nsegs, BUS_DMA_NOWAIT); 4269 if (error == 0) { 4270 void *desc; 4271 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size, 4272 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); 4273 if (error == 0) { 4274 bus_dmamap_t map; 4275 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0, 4276 BUS_DMA_NOWAIT, &map); 4277 if (error == 0) { 4278 error = bus_dmamap_load(sc->tulip_dmatag, map, desc, 4279 size, NULL, BUS_DMA_NOWAIT); 4280 if (error) 4281 bus_dmamap_destroy(sc->tulip_dmatag, map); 4282 else 4283 *map_p = map; 4284 } 4285 if (error) 4286 bus_dmamem_unmap(sc->tulip_dmatag, desc, size); 4287 } 4288 if (error) 4289 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs); 4290 else 4291 *desc_p = desc; 4292 } 4293 return (error); 4294} 4295 4296int 4297tulip_busdma_init(tulip_softc_t * const sc) 4298{ 4299 int error = 0; 4300 4301 /* 4302 * Allocate space and dmamap for setup descriptor 4303 */ 4304 error = tulip_busdma_allocmem(sc, sizeof(sc->tulip_setupdata), 4305 &sc->tulip_setupmap, &sc->tulip_setupbuf); 4306 4307 /* 4308 * Allocate space and dmamap for transmit ring 4309 */ 4310 if (error == 0) { 4311 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS, 4312 &sc->tulip_txdescmap, 4313 &sc->tulip_txdescs); 4314 } 4315 4316 /* 4317 * Allocate dmamaps for each transmit descriptor, and place on the 4318 * free list. 4319 */ 4320 if (error == 0) { 4321 while (error == 0 && sc->tulip_num_free_txmaps < TULIP_TXDESCS) { 4322 bus_dmamap_t map; 4323 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0) 4324 tulip_free_txmap(sc, map); 4325 } 4326 if (error) { 4327 while (sc->tulip_num_free_txmaps > 0) 4328 bus_dmamap_destroy(sc->tulip_dmatag, tulip_alloc_txmap(sc)); 4329 } 4330 } 4331 4332 /* 4333 * Allocate space and dmamap for receive ring 4334 */ 4335 if (error == 0) { 4336 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS, 4337 &sc->tulip_rxdescmap, 4338 &sc->tulip_rxdescs); 4339 } 4340 4341 /* 4342 * Allocate dmamaps for each receive descriptor, and place on the 4343 * free list. 4344 */ 4345 if (error == 0) { 4346 while (error == 0 && sc->tulip_num_free_rxmaps < TULIP_RXDESCS) { 4347 bus_dmamap_t map; 4348 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0) 4349 tulip_free_rxmap(sc, map); 4350 } 4351 if (error) { 4352 while (sc->tulip_num_free_rxmaps > 0) 4353 bus_dmamap_destroy(sc->tulip_dmatag, tulip_alloc_rxmap(sc)); 4354 } 4355 } 4356 return (error); 4357} 4358 4359void 4360tulip_initcsrs(tulip_softc_t * const sc, bus_addr_t csr_base, size_t csr_size) 4361{ 4362 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; 4363 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; 4364 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; 4365 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; 4366 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; 4367 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; 4368 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; 4369 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; 4370 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size; 4371 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size; 4372 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size; 4373 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size; 4374 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size; 4375 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size; 4376 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size; 4377 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size; 4378} 4379 4380void 4381tulip_initring(tulip_softc_t * const sc, tulip_ringinfo_t * const ri, 4382 tulip_desc_t *descs, int ndescs) 4383{ 4384 ri->ri_max = ndescs; 4385 ri->ri_first = descs; 4386 ri->ri_last = ri->ri_first + ri->ri_max; 4387 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 4388 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 4389} 4390 4391int 4392tulip_probe(struct device *parent, void *match, void *aux) 4393{ 4394 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 4395 4396 if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID) 4397 return (0); 4398 if (PCI_CHIPID(pa->pa_id) == CHIPID_21040 4399 || PCI_CHIPID(pa->pa_id) == CHIPID_21041 4400 || PCI_CHIPID(pa->pa_id) == CHIPID_21140 4401 || PCI_CHIPID(pa->pa_id) == CHIPID_21142) 4402 return (2); 4403 4404 return (0); 4405} 4406 4407void 4408tulip_attach(struct device * const parent, struct device * const self, void * const aux) 4409{ 4410 tulip_softc_t * const sc = (tulip_softc_t *) self; 4411 struct pci_attach_args * const pa = (struct pci_attach_args *) aux; 4412 struct ifnet * const ifp = &sc->tulip_if; 4413 const int unit = sc->tulip_dev.dv_unit; 4414 int retval, idx; 4415 u_int32_t revinfo, cfdainfo, id; 4416 unsigned csroffset = TULIP_PCI_CSROFFSET; 4417 unsigned csrsize = TULIP_PCI_CSRSIZE; 4418 bus_addr_t csr_base; 4419 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN; 4420 4421 if (unit >= TULIP_MAX_DEVICES) { 4422 printf(": not configured; limit of %d reached or exceeded\n", 4423 TULIP_MAX_DEVICES); 4424 return; 4425 } 4426 4427 ml_init(&sc->tulip_txq); 4428 ml_init(&sc->tulip_rxq); 4429 4430 revinfo = PCI_CONF_READ(PCI_CFRV) & 0xFF; 4431 id = PCI_CONF_READ(PCI_CFID); 4432 cfdainfo = PCI_CONF_READ(PCI_CFDA); 4433 4434 if (PCI_VENDORID(id) == DEC_VENDORID) { 4435 if (PCI_CHIPID(id) == CHIPID_21040) 4436 chipid = TULIP_21040; 4437 else if (PCI_CHIPID(id) == CHIPID_21041) 4438 chipid = TULIP_21041; 4439 else if (PCI_CHIPID(id) == CHIPID_21140) 4440 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140; 4441 else if (PCI_CHIPID(id) == CHIPID_21142) 4442 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142; 4443 } 4444 4445 if (chipid == TULIP_CHIPID_UNKNOWN) 4446 return; 4447 4448 if ((chipid == TULIP_21040 || chipid == TULIP_DE425) && revinfo < 0x20) { 4449 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n", 4450 revinfo >> 4, revinfo & 0x0f); 4451 return; 4452 } else if (chipid == TULIP_21140 && revinfo < 0x11) { 4453 printf(": not configured; 21140 pass 1.1 required (%d.%d found)\n", 4454 revinfo >> 4, revinfo & 0x0f); 4455 return; 4456 } 4457 4458 PCI_GETBUSDEVINFO(sc); 4459 sc->tulip_chipid = chipid; 4460 sc->tulip_flags |= TULIP_DEVICEPROBE; 4461 if (chipid == TULIP_21140 || chipid == TULIP_21140A) 4462 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD; 4463 if (chipid == TULIP_21140A && revinfo <= 0x22) 4464 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW; 4465 if (chipid == TULIP_21140) 4466 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH; 4467 if (chipid != TULIP_21040 && chipid != TULIP_DE425 && chipid != TULIP_21140) 4468 sc->tulip_features |= TULIP_HAVE_POWERMGMT; 4469 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) { 4470 sc->tulip_features |= TULIP_HAVE_DUALSENSE; 4471 if (chipid != TULIP_21041 || revinfo >= 0x20) 4472 sc->tulip_features |= TULIP_HAVE_SIANWAY; 4473 if (chipid != TULIP_21041) 4474 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD; 4475 if (chipid != TULIP_21041 && revinfo >= 0x20) 4476 sc->tulip_features |= TULIP_HAVE_SIA100; 4477 } 4478 4479 if (sc->tulip_features & TULIP_HAVE_POWERMGMT 4480 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) { 4481 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE); 4482 PCI_CONF_WRITE(PCI_CFDA, cfdainfo); 4483 DELAY(11*1000); 4484 } 4485 4486 if (sc->tulip_features & TULIP_HAVE_STOREFWD) 4487 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; 4488 4489 bcopy(self->dv_xname, sc->tulip_if.if_xname, IFNAMSIZ); 4490 sc->tulip_if.if_softc = sc; 4491 sc->tulip_pc = pa->pa_pc; 4492 sc->tulip_dmatag = pa->pa_dmat; 4493 sc->tulip_revinfo = revinfo; 4494 4495 timeout_set(&sc->tulip_stmo, tulip_timeout_callback, sc); 4496 4497 csr_base = 0; 4498 { 4499 bus_space_tag_t iot, memt; 4500 bus_space_handle_t ioh, memh; 4501 int ioh_valid, memh_valid; 4502 4503 ioh_valid = (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 4504 &iot, &ioh, NULL, NULL, 0) == 0); 4505 memh_valid = (pci_mapreg_map(pa, PCI_CBMA, 4506 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, 4507 &memt, &memh, NULL, NULL, 0) == 0); 4508 4509 if (memh_valid) { 4510 sc->tulip_bustag = memt; 4511 sc->tulip_bushandle = memh; 4512 } else if (ioh_valid) { 4513 sc->tulip_bustag = iot; 4514 sc->tulip_bushandle = ioh; 4515 } else { 4516 printf(": unable to map device registers\n"); 4517 return; 4518 } 4519 } 4520 4521 tulip_initcsrs(sc, csr_base + csroffset, csrsize); 4522 4523 if ((retval = tulip_busdma_init(sc)) != 0) { 4524 printf(": error initing bus_dma: %d\n", retval); 4525 return; 4526 } 4527 4528 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS); 4529 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS); 4530 4531 /* 4532 * Make sure there won't be any interrupts or such... 4533 */ 4534 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); 4535 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at 4536 33MHz that comes to two microseconds but wait a 4537 bit longer anyways) */ 4538 4539 if ((retval = tulip_read_macaddr(sc)) < 0) { 4540 printf(", %s%s pass %d.%d", sc->tulip_boardid, 4541 tulip_chipdescs[sc->tulip_chipid], 4542 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F); 4543 printf(": can't read ENET ROM (why=%d) (", retval); 4544 for (idx = 0; idx < 32; idx++) 4545 printf("%02x", sc->tulip_rombuf[idx]); 4546 printf(", address unknown\n"); 4547 } else { 4548 int (*intr_rtn)(void *) = tulip_intr_normal; 4549 4550 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR) 4551 intr_rtn = tulip_intr_shared; 4552 4553 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) { 4554 pci_intr_handle_t intrhandle; 4555 const char *intrstr; 4556 4557 if (pci_intr_map(pa, &intrhandle)) { 4558 printf(": couldn't map interrupt\n"); 4559 return; 4560 } 4561 4562 intrstr = pci_intr_string(pa->pa_pc, intrhandle); 4563 sc->tulip_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, 4564 intr_rtn, sc, self->dv_xname); 4565 if (sc->tulip_ih == NULL) { 4566 printf(": couldn't establish interrupt"); 4567 if (intrstr != NULL) 4568 printf(" at %s", intrstr); 4569 printf("\n"); 4570 return; 4571 } 4572 4573 printf(", %s%s pass %d.%d%s: %s, address %s\n", 4574 sc->tulip_boardid, 4575 tulip_chipdescs[sc->tulip_chipid], 4576 (sc->tulip_revinfo & 0xF0) >> 4, 4577 sc->tulip_revinfo & 0x0F, 4578 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM)) 4579 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "", 4580 intrstr, ether_sprintf(sc->tulip_enaddr)); 4581 } 4582 4583 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; 4584 ifp->if_ioctl = tulip_ifioctl; 4585 ifp->if_start = tulip_ifstart; 4586 ifp->if_watchdog = tulip_ifwatchdog; 4587 ifp->if_timer = 1; 4588 4589 (*sc->tulip_boardsw->bd_media_probe)(sc); 4590 ifmedia_init(&sc->tulip_ifmedia, 0, 4591 tulip_ifmedia_change, tulip_ifmedia_status); 4592 sc->tulip_flags &= ~TULIP_DEVICEPROBE; 4593 tulip_ifmedia_add(sc); 4594 4595 tulip_reset(sc); 4596 4597 IFQ_SET_READY(&ifp->if_snd); 4598 if_attach(ifp); 4599 ether_ifattach(ifp); 4600 } 4601} 4602