if_devar.h revision 1.8
1/* $OpenBSD: if_devar.h,v 1.8 1998/10/08 05:51:19 jason Exp $ */ 2/* $NetBSD: if_devar.h,v 1.13 1997/06/08 18:46:36 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 withough specific prior written permission 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * Id: if_devar.h,v 1.23 1997/06/03 18:51:16 thomas Exp 28 */ 29 30#if !defined(_DEVAR_H) 31#define _DEVAR_H 32 33#if defined(__OpenBSD__) 34#define __BROKEN_INDIRECT_CONFIG 35#endif 36 37#if defined(__NetBSD__) || defined(__OpenBSD__) 38 39typedef bus_addr_t tulip_csrptr_t; 40 41#define TULIP_CSR_READ(sc, csr) \ 42 bus_space_read_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr) 43#define TULIP_CSR_WRITE(sc, csr, val) \ 44 bus_space_write_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val)) 45 46#define TULIP_CSR_READBYTE(sc, csr) \ 47 bus_space_read_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr) 48#define TULIP_CSR_WRITEBYTE(sc, csr, val) \ 49 bus_space_write_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val)) 50#endif /* __NetBSD__ */ 51 52#ifdef TULIP_IOMAPPED 53#define TULIP_EISA_CSRSIZE 16 54#define TULIP_EISA_CSROFFSET 0 55#define TULIP_PCI_CSRSIZE 8 56#define TULIP_PCI_CSROFFSET 0 57 58#if !defined(__NetBSD__) && !defined(__OpenBSD__) 59typedef u_int16_t tulip_csrptr_t; 60 61#define TULIP_CSR_READ(sc, csr) (inl((sc)->tulip_csrs.csr)) 62#define TULIP_CSR_WRITE(sc, csr, val) outl((sc)->tulip_csrs.csr, val) 63 64#define TULIP_CSR_READBYTE(sc, csr) (inb((sc)->tulip_csrs.csr)) 65#define TULIP_CSR_WRITEBYTE(sc, csr, val) outb((sc)->tulip_csrs.csr, val) 66#endif /* __NetBSD__ */ 67 68#else /* TULIP_IOMAPPED */ 69 70#define TULIP_PCI_CSRSIZE 8 71#define TULIP_PCI_CSROFFSET 0 72 73#if !defined(__NetBSD__) && !defined(__OpenBSD__) 74typedef volatile u_int32_t *tulip_csrptr_t; 75 76/* 77 * macros to read and write CSRs. Note that the "0 +" in 78 * READ_CSR is to prevent the macro from being an lvalue 79 * and WRITE_CSR shouldn't be assigned from. 80 */ 81#define TULIP_CSR_READ(sc, csr) (0 + *(sc)->tulip_csrs.csr) 82#define TULIP_CSR_WRITE(sc, csr, val) ((void)(*(sc)->tulip_csrs.csr = (val))) 83#endif /* __NetBSD__ */ 84 85#endif /* TULIP_IOMAPPED */ 86 87/* 88 * Swap macro to access certain data types. 89 */ 90#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN 91__inline__ static u_int32_t FILT_BO(u_int32_t); 92__inline__ static u_int32_t DESC_BO(u_int32_t); 93 94__inline__ static u_int32_t 95FILT_BO(x) 96 u_int32_t x; 97{ 98 u_int32_t s; 99 100 s = (x & 0xffff) << 16 | ((x & 0xff) << 8) | ((x & 0xff00) >> 8); 101 return s; 102} 103 104__inline__ static u_int32_t 105DESC_BO(x) 106 u_int32_t x; 107{ 108 u_int32_t s; 109 110 s = x; 111 x = (((s) >> 24) | (((s) >> 8) & 0xff00) | 112 ((s) << 24) | (((s) & 0xff00) << 8)); 113 return x; 114} 115 116#else 117#define FILT_BO(x) (x) 118#define DESC_BO(x) (x) 119#endif 120 121/* 122 * This structure contains "pointers" for the registers on 123 * the various 21x4x chips. CSR0 through CSR8 are common 124 * to all chips. After that, it gets messy... 125 */ 126typedef struct { 127 tulip_csrptr_t csr_busmode; /* CSR0 */ 128 tulip_csrptr_t csr_txpoll; /* CSR1 */ 129 tulip_csrptr_t csr_rxpoll; /* CSR2 */ 130 tulip_csrptr_t csr_rxlist; /* CSR3 */ 131 tulip_csrptr_t csr_txlist; /* CSR4 */ 132 tulip_csrptr_t csr_status; /* CSR5 */ 133 tulip_csrptr_t csr_command; /* CSR6 */ 134 tulip_csrptr_t csr_intr; /* CSR7 */ 135 tulip_csrptr_t csr_missed_frames; /* CSR8 */ 136 tulip_csrptr_t csr_9; /* CSR9 */ 137 tulip_csrptr_t csr_10; /* CSR10 */ 138 tulip_csrptr_t csr_11; /* CSR11 */ 139 tulip_csrptr_t csr_12; /* CSR12 */ 140 tulip_csrptr_t csr_13; /* CSR13 */ 141 tulip_csrptr_t csr_14; /* CSR14 */ 142 tulip_csrptr_t csr_15; /* CSR15 */ 143 tulip_csrptr_t csr_19; /* CSR19 - PNIC */ 144 tulip_csrptr_t csr_20; /* CSR20 - PNIC */ 145 tulip_csrptr_t csr_23; /* CSR23 - PNIC */ 146} tulip_regfile_t; 147 148#define csr_enetrom csr_9 /* 21040 */ 149#define csr_reserved csr_10 /* 21040 */ 150#define csr_full_duplex csr_11 /* 21040 */ 151#define csr_bootrom csr_10 /* 21041/21140A/?? */ 152#define csr_gp csr_12 /* 21140* */ 153#define csr_watchdog csr_15 /* 21140* */ 154#define csr_gp_timer csr_11 /* 21041/21140* */ 155#define csr_srom_mii csr_9 /* 21041/21140* */ 156#define csr_sia_status csr_12 /* 2104x */ 157#define csr_sia_connectivity csr_13 /* 2104x */ 158#define csr_sia_tx_rx csr_14 /* 2104x */ 159#define csr_sia_general csr_15 /* 2104x */ 160 161/* 162 * While 21x4x allows chaining of its descriptors, this driver 163 * doesn't take advantage of it. We keep the descriptors in a 164 * traditional FIFO ring. 165 */ 166typedef struct { 167 tulip_desc_t *ri_first; /* first entry in ring */ 168 tulip_desc_t *ri_last; /* one after last entry */ 169 tulip_desc_t *ri_nextin; /* next to processed by host */ 170 tulip_desc_t *ri_nextout; /* next to processed by adapter */ 171 int ri_max; 172 int ri_free; 173} tulip_ringinfo_t; 174 175/* 176 * The 21040 has a stupid restriction in that the receive 177 * buffers must be longword aligned. But since Ethernet 178 * headers are not a multiple of longwords in size this forces 179 * the data to non-longword aligned. Since IP requires the 180 * data to be longword aligned, we need to copy it after it has 181 * been DMA'ed in our memory. 182 * 183 * Since we have to copy it anyways, we might as well as allocate 184 * dedicated receive space for the input. This allows to use a 185 * small receive buffer size and more ring entries to be able to 186 * better keep with a flood of tiny Ethernet packets. 187 * 188 * The receive space MUST ALWAYS be a multiple of the page size. 189 * And the number of receive descriptors multiplied by the size 190 * of the receive buffers must equal the recevive space. This 191 * is so that we can manipulate the page tables so that even if a 192 * packet wraps around the end of the receive space, we can 193 * treat it as virtually contiguous. 194 * 195 * The above used to be true (the stupid restriction is still true) 196 * but we gone to directly DMA'ing into MBUFs (unless it's on an 197 * architecture which can't handle unaligned accesses) because with 198 * 100Mb/s cards the copying is just too much of a hit. 199 */ 200#if defined(__alpha__) || defined(__mips__) 201#define TULIP_COPY_RXDATA 1 202#endif 203 204#define TULIP_TXTIMER 4 205#define TULIP_RXDESCS 48 206#define TULIP_TXDESCS 128 207#define TULIP_RXQ_TARGET 32 208#if TULIP_RXQ_TARGET >= TULIP_RXDESCS 209#error TULIP_RXQ_TARGET must be less than TULIP_RXDESCS 210#endif 211#define TULIP_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16) 212 213/* 214 * Forward reference to make C happy. 215 */ 216typedef struct _tulip_softc_t tulip_softc_t; 217 218/* 219 * The various controllers support. Technically the DE425 is just 220 * a 21040 on EISA. But since it remarkably difference from normal 221 * 21040s, we give it its own chip id. 222 */ 223 224typedef enum { 225 TULIP_21040, TULIP_DE425, 226 TULIP_21041, 227 TULIP_21140, TULIP_21140A, TULIP_21142, 228 TULIP_21143, 229 TULIP_LC82C168, 230 TULIP_CHIPID_UNKNOWN 231} tulip_chipid_t; 232 233/* 234 * Various physical media types supported. 235 * BNCAUI is BNC or AUI since on the 21040 you can't really tell 236 * which is in use. 237 */ 238typedef enum { 239 TULIP_MEDIA_UNKNOWN, 240 TULIP_MEDIA_10BASET, 241 TULIP_MEDIA_10BASET_FD, 242 TULIP_MEDIA_BNC, 243 TULIP_MEDIA_AUI, 244 TULIP_MEDIA_EXTSIA, 245 TULIP_MEDIA_AUIBNC, 246 TULIP_MEDIA_100BASETX, 247 TULIP_MEDIA_100BASETX_FD, 248 TULIP_MEDIA_100BASET4, 249 TULIP_MEDIA_100BASEFX, 250 TULIP_MEDIA_100BASEFX_FD, 251 TULIP_MEDIA_MAX 252} tulip_media_t; 253 254#define TULIP_BIT(b) (1L << ((int)(b))) 255#define TULIP_FDBIT(m) (1L << ((int)TULIP_MEDIA_ ## m ## _FD)) 256#define TULIP_MBIT(m) (1L << ((int)TULIP_MEDIA_ ## m )) 257#define TULIP_IS_MEDIA_FD(m) (TULIP_BIT(m) & \ 258 (TULIP_FDBIT(10BASET) \ 259 |TULIP_FDBIT(100BASETX) \ 260 |TULIP_FDBIT(100BASEFX))) 261#define TULIP_CAN_MEDIA_FD(m) (TULIP_BIT(m) & \ 262 (TULIP_MBIT(10BASET) \ 263 |TULIP_MBIT(100BASETX) \ 264 |TULIP_MBIT(100BASEFX))) 265#define TULIP_FD_MEDIA_OF(m) ((tulip_media_t)((m) + 1)) 266#define TULIP_HD_MEDIA_OF(m) ((tulip_media_t)((m) - 1)) 267#define TULIP_IS_MEDIA_100MB(m) ((m) >= TULIP_MEDIA_100BASETX) 268#define TULIP_IS_MEDIA_TP(m) ((TULIP_BIT(m) & \ 269 (TULIP_MBIT(BNC) \ 270 |TULIP_MBIT(AUI) \ 271 |TULIP_MBIT(AUIBNC) \ 272 |TULIP_MBIT(EXTSIA))) == 0) 273 274#define TULIP_SROM_ATTR_MII 0x0100 275#define TULIP_SROM_ATTR_NWAY 0x0200 276#define TULIP_SROM_ATTR_AUTOSENSE 0x0400 277#define TULIP_SROM_ATTR_POWERUP 0x0800 278#define TULIP_SROM_ATTR_NOLINKPASS 0x1000 279 280typedef struct { 281 enum { 282 TULIP_MEDIAINFO_NONE, 283 TULIP_MEDIAINFO_SIA, 284 TULIP_MEDIAINFO_GPR, 285 TULIP_MEDIAINFO_MII, 286 TULIP_MEDIAINFO_RESET, 287 TULIP_MEDIAINFO_SYM 288 } mi_type; 289 union { 290 struct { 291 u_int16_t sia_connectivity; 292 u_int16_t sia_tx_rx; 293 u_int16_t sia_general; 294 u_int32_t sia_gp_control; /* 21142/21143 */ 295 u_int32_t sia_gp_data; /* 21142/21143 */ 296 } un_sia; 297 struct { 298 u_int32_t gpr_cmdmode; 299 u_int32_t gpr_gpcontrol; /* 21142/21143 */ 300 u_int32_t gpr_gpdata; 301 u_int8_t gpr_actmask; 302 u_int8_t gpr_actdata; 303 u_int8_t gpr_default : 1; 304 } un_gpr; 305 struct { 306 u_int32_t mii_mediamask; 307 u_int16_t mii_capabilities; 308 u_int16_t mii_advertisement; 309 u_int16_t mii_full_duplex; 310 u_int16_t mii_tx_threshold; 311 u_int16_t mii_interrupt; /* 21142/21143 */ 312 u_int8_t mii_phyaddr; 313 u_int8_t mii_gpr_length; 314 u_int8_t mii_gpr_offset; 315 u_int8_t mii_reset_length; 316 u_int8_t mii_reset_offset; 317 u_int32_t mii_phyid; 318 } un_mii; 319 } mi_un; 320} tulip_media_info_t; 321 322#define mi_sia_connectivity mi_un.un_sia.sia_connectivity 323#define mi_sia_tx_rx mi_un.un_sia.sia_tx_rx 324#define mi_sia_general mi_un.un_sia.sia_general 325#define mi_sia_gp_control mi_un.un_sia.sia_gp_control 326#define mi_sia_gp_data mi_un.un_sia.sia_gp_data 327 328#define mi_gpcontrol mi_un.un_gpr.gpr_gpcontrol 329#define mi_gpdata mi_un.un_gpr.gpr_gpdata 330#define mi_actmask mi_un.un_gpr.gpr_actmask 331#define mi_actdata mi_un.un_gpr.gpr_actdata 332#define mi_default mi_un.un_gpr.gpr_default 333#define mi_cmdmode mi_un.un_gpr.gpr_cmdmode 334 335#define mi_phyaddr mi_un.un_mii.mii_phyaddr 336#define mi_gpr_length mi_un.un_mii.mii_gpr_length 337#define mi_gpr_offset mi_un.un_mii.mii_gpr_offset 338#define mi_reset_length mi_un.un_mii.mii_reset_length 339#define mi_reset_offset mi_un.un_mii.mii_reset_offset 340#define mi_capabilities mi_un.un_mii.mii_capabilities 341#define mi_advertisement mi_un.un_mii.mii_advertisement 342#define mi_full_duplex mi_un.un_mii.mii_full_duplex 343#define mi_tx_threshold mi_un.un_mii.mii_tx_threshold 344#define mi_mediamask mi_un.un_mii.mii_mediamask 345#define mi_mii_interrupt mi_un.un_mii.mii_interrupt 346#define mi_phyid mi_un.un_mii.mii_phyid 347 348#define TULIP_MEDIAINFO_SIA_INIT(sc, mi, chipid, media) do { \ 349 (mi)->mi_type = TULIP_MEDIAINFO_SIA; \ 350 sc->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ 351 (mi)->mi_sia_connectivity = TULIP_ ## chipid ## _SIACONN_ ## media; \ 352 (mi)->mi_sia_tx_rx = TULIP_ ## chipid ## _SIATXRX_ ## media; \ 353 (mi)->mi_sia_general = TULIP_ ## chipid ## _SIAGEN_ ## media; \ 354} while (0) 355 356#define TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, media) do { \ 357 if ((sc)->tulip_mediums[TULIP_MEDIA_ ## media] == NULL \ 358 && ((mi)->mi_capabilities & PHYSTS_ ## media)) { \ 359 (sc)->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ 360 (mi)->mi_mediamask |= TULIP_BIT(TULIP_MEDIA_ ## media); \ 361 } \ 362} while (0) 363 364#define TULIP_MII_NOPHY 32 365/* 366 * Some boards need to treated specially. The following enumeration 367 * identifies the cards with quirks (or those we just want to single 368 * out for special merit or scorn). 369 */ 370typedef enum { 371 TULIP_21040_GENERIC, /* Generic 21040 (works with most any board) */ 372 TULIP_21140_ISV, /* Digital Semicondutor 21140 ISV SROM Format */ 373 TULIP_21142_ISV, /* Digital Semicondutor 21142 ISV SROM Format */ 374 TULIP_21143_ISV, /* Digital Semicondutor 21143 ISV SROM Format */ 375 TULIP_21140_DEC_EB, /* Digital Semicondutor 21140 Evaluation Board */ 376 TULIP_21140_MII, /* 21140[A] with MII */ 377 TULIP_21140_DEC_DE500, /* Digital DE500-?? 10/100 */ 378 TULIP_21140_SMC_9332, /* SMC 9332 */ 379 TULIP_21140_COGENT_EM100, /* Cogent EM100 100 only */ 380 TULIP_21140_ZNYX_ZX34X, /* ZNYX ZX342 10/100 */ 381 TULIP_21140_ASANTE, /* AsanteFast 10/100 */ 382 TULIP_21140_EN1207, /* Accton EN2107 10/100 BNC */ 383 TULIP_21041_GENERIC /* Generic 21041 card */ 384} tulip_board_t; 385 386typedef enum { 387 TULIP_MEDIAPOLL_TIMER, /* 100ms timer fired */ 388 TULIP_MEDIAPOLL_FASTTIMER, /* <100ms timer fired */ 389 TULIP_MEDIAPOLL_LINKFAIL, /* called from interrupt routine */ 390 TULIP_MEDIAPOLL_LINKPASS, /* called from interrupt routine */ 391 TULIP_MEDIAPOLL_START, /* start a media probe (called from reset) */ 392 TULIP_MEDIAPOLL_TXPROBE_OK, /* txprobe succeeded */ 393 TULIP_MEDIAPOLL_TXPROBE_FAILED, /* txprobe failed */ 394 TULIP_MEDIAPOLL_MAX 395} tulip_mediapoll_event_t; 396 397typedef enum { 398 TULIP_LINK_DOWN, /* Link is down */ 399 TULIP_LINK_UP, /* link is ok */ 400 TULIP_LINK_UNKNOWN /* we can't tell either way */ 401} tulip_link_status_t; 402 403 404/* 405 * This data structure is used to abstract out the quirks. 406 * media_probe = tries to determine the media type. 407 * media_select = enables the current media (or autosenses) 408 * media_poll = autosenses media 409 * media_preset = 21140, etal requires bit to set before the 410 * the software reset; hence pre-set. Should be 411 * pre-reset but that's ugly. 412 */ 413 414typedef struct { 415 tulip_board_t bd_type; 416 void (*bd_media_probe)(tulip_softc_t * const sc); 417 void (*bd_media_select)(tulip_softc_t * const sc); 418 void (*bd_media_poll)(tulip_softc_t * const sc, tulip_mediapoll_event_t event); 419 void (*bd_media_preset)(tulip_softc_t * const sc); 420#if defined(__bsdi__) && _BSDI_VERSION >= 199701 421 struct ifmedia_entry *bd_media_list; 422 int bd_media_cnt; 423 int bd_media_options_mask; 424#endif 425} tulip_boardsw_t; 426 427/* 428 * The next few declarations are for MII/PHY based board. 429 * 430 * The first enumeration identifies a superset of various datums 431 * that can be obtained from various PHY chips. Not all PHYs will 432 * support all datums. 433 * The modedata structure indicates what register contains 434 * a datum, what mask is applied the register contents, and what the 435 * result should be. 436 * The attr structure records information about a supported PHY. 437 * The phy structure records information about a PHY instance. 438 */ 439 440typedef enum { 441 PHY_MODE_10T, 442 PHY_MODE_100TX, 443 PHY_MODE_100T4, 444 PHY_MODE_FULLDUPLEX, 445 PHY_MODE_MAX 446} tulip_phy_mode_t; 447 448typedef struct { 449 u_int16_t pm_regno; 450 u_int16_t pm_mask; 451 u_int16_t pm_value; 452} tulip_phy_modedata_t; 453 454typedef struct { 455 u_int32_t attr_id; 456 u_int16_t attr_flags; 457#define PHY_NEED_HARD_RESET 0x0001 458#define PHY_DUAL_CYCLE_TA 0x0002 459 tulip_phy_modedata_t attr_modes[PHY_MODE_MAX]; 460#ifdef TULIP_DEBUG 461 const char *attr_name; 462#endif 463} tulip_phy_attr_t; 464 465/* 466 * Various probe states used when trying to autosense the media. 467 */ 468 469typedef enum { 470 TULIP_PROBE_INACTIVE, 471 TULIP_PROBE_PHYRESET, 472 TULIP_PROBE_PHYAUTONEG, 473 TULIP_PROBE_GPRTEST, 474 TULIP_PROBE_MEDIATEST, 475 TULIP_PROBE_FAILED 476} tulip_probe_state_t; 477 478typedef struct { 479 /* 480 * Transmit Statistics 481 */ 482 u_int32_t dot3StatsSingleCollisionFrames; 483 u_int32_t dot3StatsMultipleCollisionFrames; 484 u_int32_t dot3StatsSQETestErrors; 485 u_int32_t dot3StatsDeferredTransmissions; 486 u_int32_t dot3StatsLateCollisions; 487 u_int32_t dot3StatsExcessiveCollisions; 488 u_int32_t dot3StatsCarrierSenseErrors; 489 u_int32_t dot3StatsInternalMacTransmitErrors; 490 u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */ 491 u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */ 492 /* 493 * Receive Statistics 494 */ 495 u_int32_t dot3StatsMissedFrames; /* not in rfc1650! */ 496 u_int32_t dot3StatsAlignmentErrors; 497 u_int32_t dot3StatsFCSErrors; 498 u_int32_t dot3StatsFrameTooLongs; 499 u_int32_t dot3StatsInternalMacReceiveErrors; 500} tulip_dot3_stats_t; 501 502/* 503 * Now to important stuff. This is softc structure (where does softc 504 * come from??? No idea) for the tulip device. 505 * 506 */ 507struct _tulip_softc_t { 508#if defined(__bsdi__) 509 struct device tulip_dev; /* base device */ 510 struct isadev tulip_id; /* ISA device */ 511 struct intrhand tulip_ih; /* intrrupt vectoring */ 512 struct atshutdown tulip_ats; /* shutdown hook */ 513#if _BSDI_VERSION < 199401 514 caddr_t tulip_bpf; /* for BPF */ 515#else 516 prf_t tulip_pf; /* printf function */ 517#if _BSDI_VERSION >= 199701 518 struct mii_data tulip_mii; /* Generic MII and media data */ 519#define tulip_ifmedia tulip_mii.mii_media 520#endif /* _BSDI_VERSION >= 199701 */ 521#endif /* _BSDI_VERSION < 199401 */ 522#endif /* __bsdi__ */ 523#if defined(__NetBSD__) || defined(__OpenBSD__) 524 struct device tulip_dev; /* base device */ 525 void *tulip_ih; /* intrrupt vectoring */ 526 void *tulip_ats; /* shutdown hook */ 527 528 bus_space_tag_t tulip_bustag; /* tag of CSR region being used */ 529 bus_space_handle_t tulip_bushandle; /* handle for CSR region being used */ 530 pci_chipset_tag_t tulip_pc; 531#if !defined(__OpenBSD__) 532 struct ethercom tulip_ec; 533#endif 534 u_int8_t tulip_enaddr[ETHER_ADDR_LEN]; 535#endif 536#if !defined(tulip_ifmedia) && defined(IFM_ETHER) 537 struct ifmedia tulip_ifmedia; 538#endif 539#if !defined(__NetBSD__) 540 struct arpcom tulip_ac; 541#endif 542 tulip_regfile_t tulip_csrs; 543 u_int32_t tulip_flags; 544#define TULIP_WANTSETUP 0x00000001 545#define TULIP_WANTHASHPERFECT 0x00000002 546#define TULIP_WANTHASHONLY 0x00000004 547#define TULIP_DOINGSETUP 0x00000008 548#define TULIP_PRINTMEDIA 0x00000010 549#define TULIP_TXPROBE_ACTIVE 0x00000020 550#define TULIP_ALLMULTI 0x00000040 551#define TULIP_WANTRXACT 0x00000080 552#define TULIP_RXACT 0x00000100 553#define TULIP_INRESET 0x00000200 554#define TULIP_NEEDRESET 0x00000400 555#define TULIP_SQETEST 0x00000800 556#define TULIP_xxxxxx0 0x00001000 557#define TULIP_xxxxxx1 0x00002000 558#define TULIP_WANTTXSTART 0x00004000 559#define TULIP_NEWTXTHRESH 0x00008000 560#define TULIP_NOAUTOSENSE 0x00010000 561#define TULIP_PRINTLINKUP 0x00020000 562#define TULIP_LINKUP 0x00040000 563#define TULIP_RXBUFSLOW 0x00080000 564#define TULIP_NOMESSAGES 0x00100000 565#define TULIP_SYSTEMERROR 0x00200000 566#define TULIP_TIMEOUTPENDING 0x00400000 567#define TULIP_xxxxxx2 0x00800000 568#define TULIP_TRYNWAY 0x01000000 569#define TULIP_DIDNWAY 0x02000000 570#define TULIP_RXIGNORE 0x04000000 571#define TULIP_PROBE1STPASS 0x08000000 572#define TULIP_DEVICEPROBE 0x10000000 573#define TULIP_PROMISC 0x20000000 574#define TULIP_HASHONLY 0x40000000 575#define TULIP_xxxxxx3 0x80000000 576 /* only 4 bits left! */ 577 u_int32_t tulip_features; /* static bits indicating features of chip */ 578#define TULIP_HAVE_GPR 0x00000001 /* have gp register (140[A]) */ 579#define TULIP_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */ 580#define TULIP_HAVE_POWERMGMT 0x00000004 /* Snooze/sleep modes */ 581#define TULIP_HAVE_MII 0x00000008 /* Some medium on MII */ 582#define TULIP_HAVE_SIANWAY 0x00000010 /* SIA does NWAY */ 583#define TULIP_HAVE_DUALSENSE 0x00000020 /* SIA senses both AUI & TP */ 584#define TULIP_HAVE_SIAGP 0x00000040 /* SIA has a GP port */ 585#define TULIP_HAVE_BROKEN_HASH 0x00000080 /* Broken Multicast Hash */ 586#define TULIP_HAVE_ISVSROM 0x00000100 /* uses ISV SROM Format */ 587#define TULIP_HAVE_BASEROM 0x00000200 /* Board ROM can be cloned */ 588#define TULIP_HAVE_SLAVEDROM 0x00000400 /* Board ROM cloned */ 589#define TULIP_HAVE_SLAVEDINTR 0x00000800 /* Board slaved interrupt */ 590#define TULIP_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */ 591#define TULIP_HAVE_OKROM 0x00002000 /* ROM was recognized */ 592#define TULIP_HAVE_NOMEDIA 0x00004000 /* did not detect any media */ 593#define TULIP_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */ 594#define TULIP_HAVE_SIA100 0x00010000 /* has LS100 in SIA status */ 595#define TULIP_HAVE_OKSROM 0x00020000 /* SROM CRC is OK */ 596 u_int32_t tulip_intrmask; /* our copy of csr_intr */ 597 u_int32_t tulip_cmdmode; /* our copy of csr_cmdmode */ 598 u_int32_t tulip_last_system_error : 3; /* last system error (only value is TULIP_SYSTEMERROR is also set) */ 599 u_int32_t tulip_txtimer : 2; /* transmission timer */ 600 u_int32_t tulip_system_errors; /* number of system errors encountered */ 601 u_int32_t tulip_statusbits; /* status bits from CSR5 that may need to be printed */ 602 603 tulip_media_info_t *tulip_mediums[TULIP_MEDIA_MAX]; /* indexes into mediainfo */ 604 tulip_media_t tulip_media; /* current media type */ 605 u_int32_t tulip_abilities; /* remote system's abiltities (as defined in IEEE 802.3u) */ 606 607 u_int8_t tulip_revinfo; /* revision of chip */ 608 u_int8_t tulip_phyaddr; /* 0..31 -- address of current phy */ 609 u_int8_t tulip_gpinit; /* active pins on 21140 */ 610 u_int8_t tulip_gpdata; /* default gpdata for 21140 */ 611 612 struct { 613 u_int8_t probe_count; /* count of probe operations */ 614 int32_t probe_timeout; /* time in ms of probe timeout */ 615 tulip_probe_state_t probe_state; /* current media probe state */ 616 tulip_media_t probe_media; /* current media being probed */ 617 u_int32_t probe_mediamask; /* medias checked */ 618 u_int32_t probe_passes; /* times autosense failed */ 619 u_int32_t probe_txprobes; /* txprobes attempted */ 620 } tulip_probe; 621#define tulip_probe_count tulip_probe.probe_count 622#define tulip_probe_timeout tulip_probe.probe_timeout 623#define tulip_probe_state tulip_probe.probe_state 624#define tulip_probe_media tulip_probe.probe_media 625#define tulip_probe_mediamask tulip_probe.probe_mediamask 626#define tulip_probe_passes tulip_probe.probe_passes 627 628 tulip_chipid_t tulip_chipid; /* type of chip we are using */ 629 const tulip_boardsw_t *tulip_boardsw; /* board/chip characteristics */ 630 tulip_softc_t *tulip_slaves; /* slaved devices (ZX3xx) */ 631#if defined(TULIP_DEBUG) 632 /* 633 * Debugging/Statistical information 634 */ 635 struct { 636 tulip_media_t dbg_last_media; 637 u_int32_t dbg_intrs; 638 u_int32_t dbg_media_probes; 639 u_int32_t dbg_txprobe_nocarr; 640 u_int32_t dbg_txprobe_exccoll; 641 u_int32_t dbg_link_downed; 642 u_int32_t dbg_link_suspected; 643 u_int32_t dbg_link_intrs; 644 u_int32_t dbg_link_pollintrs; 645 u_int32_t dbg_link_failures; 646 u_int32_t dbg_nway_starts; 647 u_int32_t dbg_nway_failures; 648 u_int16_t dbg_phyregs[32][4]; 649 u_int32_t dbg_rxlowbufs; 650 u_int32_t dbg_rxintrs; 651 u_int32_t dbg_last_rxintrs; 652 u_int32_t dbg_high_rxintrs_hz; 653 u_int32_t dbg_txprobes_ok[TULIP_MEDIA_MAX]; 654 u_int32_t dbg_txprobes_failed[TULIP_MEDIA_MAX]; 655 u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX]; 656 u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS]; 657 } tulip_dbg; 658#endif 659#if defined(TULIP_PERFSTATS) 660#define TULIP_PERF_CURRENT 0 661#define TULIP_PERF_PREVIOUS 1 662#define TULIP_PERF_TOTAL 2 663#define TULIP_PERF_MAX 3 664 struct tulip_perfstats { 665 u_quad_t perf_intr_cycles; 666 u_quad_t perf_ifstart_cycles; 667 u_quad_t perf_ifstart_one_cycles; 668 u_quad_t perf_ifioctl_cycles; 669 u_quad_t perf_ifwatchdog_cycles; 670 u_quad_t perf_timeout_cycles; 671 u_quad_t perf_txput_cycles; 672 u_quad_t perf_txintr_cycles; 673 u_quad_t perf_rxintr_cycles; 674 u_quad_t perf_rxget_cycles; 675 unsigned perf_intr; 676 unsigned perf_ifstart; 677 unsigned perf_ifstart_one; 678 unsigned perf_ifioctl; 679 unsigned perf_ifwatchdog; 680 unsigned perf_timeout; 681 unsigned perf_txput; 682 unsigned perf_txintr; 683 unsigned perf_rxintr; 684 unsigned perf_rxget; 685 } tulip_perfstats[TULIP_PERF_MAX]; 686#define tulip_curperfstats tulip_perfstats[TULIP_PERF_CURRENT] 687#endif 688 struct ifqueue tulip_txq; 689 struct ifqueue tulip_rxq; 690 tulip_dot3_stats_t tulip_dot3stats; 691 tulip_ringinfo_t tulip_rxinfo; 692 tulip_ringinfo_t tulip_txinfo; 693 tulip_media_info_t tulip_mediainfo[10]; 694 /* 695 * The setup buffers for sending the setup frame to the chip. 696 * one is the one being sent while the other is the one being 697 * filled. 698 */ 699 u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)]; 700 u_int32_t tulip_setupdata[192/sizeof(u_int32_t)]; 701 char tulip_boardid[16]; /* buffer for board ID */ 702 u_int8_t tulip_rombuf[128]; 703#if defined(__NetBSD__) 704 struct device *tulip_pci_busno; /* needed for multiport boards */ 705#else 706 u_int8_t tulip_pci_busno; /* needed for multiport boards */ 707#endif 708 u_int8_t tulip_pci_devno; /* needed for multiport boards */ 709 u_int8_t tulip_connidx; 710 tulip_srom_connection_t tulip_conntype; 711 tulip_desc_t tulip_rxdescs[TULIP_RXDESCS]; 712 tulip_desc_t tulip_txdescs[TULIP_TXDESCS]; 713#if defined(__NetBSD__) && NRND > 0 714 rndsource_element_t tulip_rndsource; 715#endif 716}; 717 718#if defined(IFM_ETHER) 719#define TULIP_DO_AUTOSENSE(sc) (IFM_SUBTYPE((sc)->tulip_ifmedia.ifm_media) == IFM_AUTO) 720#else 721#define TULIP_DO_AUTOSENSE(sc) (((sc)->tulip_flags & TULIP_NOAUTOSENSE) == 0) 722#endif 723 724 725#if defined(TULIP_HDR_DATA) 726static const char * const tulip_chipdescs[] = { 727 "21040 [10Mb/s]", 728#if defined(TULIP_EISA) 729 "DE425 [10Mb/s]", 730#else 731 NULL, 732#endif 733 "21041 [10Mb/s]", 734 "21140 [10-100Mb/s]", 735 "21140A [10-100Mb/s]", 736 "21142 [10-100Mb/s]", 737 "21143 [10-100Mb/s]", 738 "82C168 [10-100Mb/s]", 739}; 740 741static const char * const tulip_mediums[] = { 742 "unknown", /* TULIP_MEDIA_UNKNOWN */ 743 "10baseT", /* TULIP_MEDIA_10BASET */ 744 "Full Duplex 10baseT", /* TULIP_MEDIA_10BASET_FD */ 745 "BNC", /* TULIP_MEDIA_BNC */ 746 "AUI", /* TULIP_MEDIA_AUI */ 747 "External SIA", /* TULIP_MEDIA_EXTSIA */ 748 "AUI/BNC", /* TULIP_MEDIA_AUIBNC */ 749 "100baseTX", /* TULIP_MEDIA_100BASET */ 750 "Full Duplex 100baseTX", /* TULIP_MEDIA_100BASET_FD */ 751 "100baseT4", /* TULIP_MEDIA_100BASET4 */ 752 "100baseFX", /* TULIP_MEDIA_100BASEFX */ 753 "Full Duplex 100baseFX", /* TULIP_MEDIA_100BASEFX_FD */ 754}; 755 756#if defined(IFM_ETHER) 757static const int tulip_media_to_ifmedia[] = { 758 IFM_ETHER | IFM_NONE, /* TULIP_MEDIA_UNKNOWN */ 759 IFM_ETHER | IFM_10_T, /* TULIP_MEDIA_10BASET */ 760 IFM_ETHER | IFM_10_T | IFM_FDX, /* TULIP_MEDIA_10BASET_FD */ 761 IFM_ETHER | IFM_10_2, /* TULIP_MEDIA_BNC */ 762 IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUI */ 763 IFM_ETHER | IFM_MANUAL, /* TULIP_MEDIA_EXTSIA */ 764 IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUIBNC */ 765 IFM_ETHER | IFM_100_TX, /* TULIP_MEDIA_100BASET */ 766 IFM_ETHER | IFM_100_TX | IFM_FDX, /* TULIP_MEDIA_100BASET_FD */ 767 IFM_ETHER | IFM_100_T4, /* TULIP_MEDIA_100BASET4 */ 768 IFM_ETHER | IFM_100_FX, /* TULIP_MEDIA_100BASEFX */ 769 IFM_ETHER | IFM_100_FX | IFM_FDX, /* TULIP_MEDIA_100BASEFX_FD */ 770}; 771#endif /* defined(IFM_ETHER) */ 772 773static const char * const tulip_system_errors[] = { 774 "parity error", 775 "master abort", 776 "target abort", 777 "reserved #3", 778 "reserved #4", 779 "reserved #5", 780 "reserved #6", 781 "reserved #7", 782}; 783 784static const char * const tulip_status_bits[] = { 785 NULL, 786 "transmit process stopped", 787 NULL, 788 "transmit jabber timeout", 789 790 NULL, 791 "transmit underflow", 792 NULL, 793 "receive underflow", 794 795 "receive process stopped", 796 "receive watchdog timeout", 797 NULL, 798 NULL, 799 800 "link failure", 801 NULL, 802 NULL, 803}; 804 805static const struct { 806 tulip_srom_connection_t sc_type; 807 tulip_media_t sc_media; 808 u_int32_t sc_attrs; 809} tulip_srom_conninfo[] = { 810 { TULIP_SROM_CONNTYPE_10BASET, TULIP_MEDIA_10BASET }, 811 { TULIP_SROM_CONNTYPE_BNC, TULIP_MEDIA_BNC }, 812 { TULIP_SROM_CONNTYPE_AUI, TULIP_MEDIA_AUI }, 813 { TULIP_SROM_CONNTYPE_100BASETX, TULIP_MEDIA_100BASETX }, 814 { TULIP_SROM_CONNTYPE_100BASET4, TULIP_MEDIA_100BASET4 }, 815 { TULIP_SROM_CONNTYPE_100BASEFX, TULIP_MEDIA_100BASEFX }, 816 { TULIP_SROM_CONNTYPE_MII_10BASET, TULIP_MEDIA_10BASET, 817 TULIP_SROM_ATTR_MII }, 818 { TULIP_SROM_CONNTYPE_MII_100BASETX, TULIP_MEDIA_100BASETX, 819 TULIP_SROM_ATTR_MII }, 820 { TULIP_SROM_CONNTYPE_MII_100BASET4, TULIP_MEDIA_100BASET4, 821 TULIP_SROM_ATTR_MII }, 822 { TULIP_SROM_CONNTYPE_MII_100BASEFX, TULIP_MEDIA_100BASEFX, 823 TULIP_SROM_ATTR_MII }, 824 { TULIP_SROM_CONNTYPE_10BASET_NWAY, TULIP_MEDIA_10BASET, 825 TULIP_SROM_ATTR_NWAY }, 826 { TULIP_SROM_CONNTYPE_10BASET_FD, TULIP_MEDIA_10BASET_FD }, 827 { TULIP_SROM_CONNTYPE_MII_10BASET_FD, TULIP_MEDIA_10BASET_FD, 828 TULIP_SROM_ATTR_MII }, 829 { TULIP_SROM_CONNTYPE_100BASETX_FD, TULIP_MEDIA_100BASETX_FD }, 830 { TULIP_SROM_CONNTYPE_MII_100BASETX_FD, TULIP_MEDIA_100BASETX_FD, 831 TULIP_SROM_ATTR_MII }, 832 { TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS, TULIP_MEDIA_10BASET, 833 TULIP_SROM_ATTR_NOLINKPASS }, 834 { TULIP_SROM_CONNTYPE_AUTOSENSE, TULIP_MEDIA_UNKNOWN, 835 TULIP_SROM_ATTR_AUTOSENSE }, 836 { TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP, TULIP_MEDIA_UNKNOWN, 837 TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_POWERUP }, 838 { TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY, TULIP_MEDIA_UNKNOWN, 839 TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_NWAY }, 840 { TULIP_SROM_CONNTYPE_NOT_USED, TULIP_MEDIA_UNKNOWN } 841}; 842#define TULIP_SROM_LASTCONNIDX \ 843 (sizeof(tulip_srom_conninfo)/sizeof(tulip_srom_conninfo[0]) - 1) 844 845static const struct { 846 tulip_media_t sm_type; 847 tulip_srom_media_t sm_srom_type; 848} tulip_srom_mediums[] = { 849 { TULIP_MEDIA_100BASEFX_FD, TULIP_SROM_MEDIA_100BASEFX_FD }, 850 { TULIP_MEDIA_100BASEFX, TULIP_SROM_MEDIA_100BASEFX }, 851 { TULIP_MEDIA_100BASET4, TULIP_SROM_MEDIA_100BASET4 }, 852 { TULIP_MEDIA_100BASETX_FD, TULIP_SROM_MEDIA_100BASETX_FD }, 853 { TULIP_MEDIA_100BASETX, TULIP_SROM_MEDIA_100BASETX }, 854 { TULIP_MEDIA_10BASET_FD, TULIP_SROM_MEDIA_10BASET_FD }, 855 { TULIP_MEDIA_AUI, TULIP_SROM_MEDIA_AUI }, 856 { TULIP_MEDIA_BNC, TULIP_SROM_MEDIA_BNC }, 857 { TULIP_MEDIA_10BASET, TULIP_SROM_MEDIA_10BASET }, 858 { TULIP_MEDIA_UNKNOWN } 859}; 860#endif /* TULIP_HDR_DATA */ 861 862/* 863 * This driver supports a maximum of 32 tulip boards. 864 * This should be enough for the forseeable future. 865 */ 866#define TULIP_MAX_DEVICES 32 867 868#if defined(TULIP_USE_SOFTINTR) && defined(TULIP_HDR_DATA) 869static u_int32_t tulip_softintr_mask; 870static int tulip_softintr_last_unit; 871static int tulip_softintr_max_unit; 872static void tulip_softintr(void); 873#endif 874 875#ifdef notyet 876#define SIOCGADDRROM _IOW('i', 240, struct ifreq) /* get 128 bytes of ROM */ 877#define SIOCGCHIPID _IOWR('i', 241, struct ifreq) /* get chipid */ 878#endif 879 880#if defined(__FreeBSD__) 881typedef void ifnet_ret_t; 882typedef int ioctl_cmd_t; 883#if defined(TULIP_HDR_DATA) 884static tulip_softc_t *tulips[TULIP_MAX_DEVICES]; 885#endif 886#if BSD >= 199506 887#define TULIP_IFP_TO_SOFTC(ifp) ((tulip_softc_t *)((ifp)->if_softc)) 888#if NBPFILTER > 0 889#define TULIP_BPF_MTAP(sc, m) bpf_mtap(&(sc)->tulip_if, m) 890#define TULIP_BPF_TAP(sc, p, l) bpf_tap(&(sc)->tulip_if, p, l) 891#define TULIP_BPF_ATTACH(sc) bpfattach(&(sc)->tulip_if, DLT_EN10MB, sizeof(struct ether_header)) 892#endif 893#define tulip_intrfunc_t void 894#define TULIP_VOID_INTRFUNC 895#define IFF_NOTRAILERS 0 896#define CLBYTES PAGE_SIZE 897#if 0 898#define TULIP_KVATOPHYS(sc, va) kvtop(va) 899#endif 900#define TULIP_EADDR_FMT "%6D" 901#define TULIP_EADDR_ARGS(addr) addr, ":" 902#else 903extern int bootverbose; 904#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) 905#include <sys/devconf.h> 906#define TULIP_DEVCONF 907#endif 908#if defined(TULIP_USE_SOFTINTR) 909NETISR_SET(NETISR_DE, tulip_softintr); 910#endif 911#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit]) 912#define TULIP_BURSTSIZE(unit) pci_max_burst_len 913#define loudprintf if (bootverbose) printf 914#endif 915 916#if defined(__bsdi__) 917typedef int ifnet_ret_t; 918typedef u_long ioctl_cmd_t; 919extern struct cfdriver decd; 920#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) 921#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) 922#define TULIP_ETHER_IFATTACH(sc) ether_attach(&(sc)->tulip_if) 923#if _BSDI_VERSION >= 199510 924#if 0 925#define TULIP_BURSTSIZE(unit) log2_burst_size 926#endif 927#define loudprintf aprint_verbose 928#define printf (*sc->tulip_pf) 929#define MCNT(x) (sizeof(x) / sizeof(struct ifmedia_entry)) 930#elif _BSDI_VERSION <= 199401 931#define DRQNONE 0 932#define loudprintf printf 933static void 934arp_ifinit( 935 struct arpcom *ac, 936 struct ifaddr *ifa) 937{ 938 ac->ac_ipaddr = IA_SIN(ifa)->sin_addr; 939 arpwhohas(ac, &ac->ac_ipaddr); 940} 941#endif 942#endif /* __bsdi__ */ 943 944#if defined(__NetBSD__) || defined(__OpenBSD__) 945typedef void ifnet_ret_t; 946typedef u_long ioctl_cmd_t; 947extern struct cfattach de_ca; 948extern struct cfdriver de_cd; 949#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) de_cd.cd_devs[unit]) 950#define TULIP_IFP_TO_SOFTC(ifp) ((tulip_softc_t *)((ifp)->if_softc)) 951#define tulip_unit tulip_dev.dv_unit 952#if defined(__OpenBSD__) 953#define tulip_xname tulip_dev.dv_cfdata->cf_driver->cd_name 954#else 955#define tulip_xname tulip_if.if_xname 956#endif 957 958#define TULIP_RAISESPL() splnet() 959#define TULIP_RAISESOFTSPL() splsoftnet() 960#define TULIP_RESTORESPL(s) splx(s) 961#define loudprintf printf 962 963#if !defined(__OpenBSD__) 964#define tulip_if tulip_ec.ec_if 965#define tulip_enaddr tulip_enaddr 966#define tulip_multicnt tulip_ec.ec_multicnt 967#define TULIP_ETHERCOM(sc) (&(sc)->tulip_ec) 968#define TULIP_ARP_IFINIT(sc, ifa) arp_ifinit(&(sc)->tulip_if, (ifa)) 969#define TULIP_ETHER_IFATTACH(sc) ether_ifattach(&(sc)->tulip_if, (sc)->tulip_enaddr) 970#define TULIP_PRINTF_FMT "%s" 971#define TULIP_PRINTF_ARGS sc->tulip_xname 972#else 973#define TULIP_PRINTF_FMT "%s%d" 974#define TULIP_PRINTF_ARGS sc->tulip_xname, sc->tulip_unit 975#endif 976#endif /* __NetBSD__ */ 977 978#if defined(__alpha__) 979/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */ 980#define TULIP_KVATOPHYS(sc, va) alpha_XXX_dmamap((vm_offset_t)(va)) 981#endif 982 983#ifndef TULIP_PRINTF_FMT 984#define TULIP_PRINTF_FMT "%s%d" 985#endif 986#ifndef TULIP_PRINTF_ARGS 987#define TULIP_PRINTF_ARGS sc->tulip_name, sc->tulip_unit 988#endif 989 990#ifndef TULIP_BURSTSIZE 991#define TULIP_BURSTSIZE(unit) 3 992#endif 993 994#ifndef tulip_if 995#define tulip_if tulip_ac.ac_if 996#endif 997#ifndef tulip_unit 998#define tulip_unit tulip_if.if_unit 999#endif 1000#define tulip_name tulip_if.if_name 1001#ifndef tulip_enaddr 1002#define tulip_enaddr tulip_ac.ac_enaddr 1003#endif 1004#ifndef tulip_multicnt 1005#define tulip_multicnt tulip_ac.ac_multicnt 1006#endif 1007 1008#if !defined(TULIP_ETHERCOM) 1009#define TULIP_ETHERCOM(sc) (&(sc)->tulip_ac) 1010#endif 1011 1012#if !defined(TULIP_ARP_IFINIT) 1013#define TULIP_ARP_IFINIT(sc, ifa) arp_ifinit(TULIP_ETHERCOM(sc), (ifa)) 1014#endif 1015 1016#if !defined(TULIP_ETHER_IFATTACH) 1017#define TULIP_ETHER_IFATTACH(sc) ether_ifattach(&(sc)->tulip_if) 1018#endif 1019 1020#if !defined(tulip_bpf) && (!defined(__bsdi__) || _BSDI_VERSION >= 199401) 1021#define tulip_bpf tulip_if.if_bpf 1022#endif 1023 1024#if !defined(tulip_intrfunc_t) 1025#define tulip_intrfunc_t int 1026#endif 1027 1028#if !defined(TULIP_KVATOPHYS) 1029#define TULIP_KVATOPHYS(sc, va) vtophys(va) 1030#endif 1031 1032#ifndef TULIP_RAISESPL 1033#define TULIP_RAISESPL() splimp() 1034#endif 1035#ifndef TULIP_RAISESOFTSPL 1036#define TULIP_RAISESOFTSPL() splnet() 1037#endif 1038#ifndef TULUP_RESTORESPL 1039#define TULIP_RESTORESPL(s) splx(s) 1040#endif 1041 1042/* 1043 * While I think FreeBSD's 2.2 change to the bpf is a nice simplification, 1044 * it does add yet more conditional code to this driver. Sigh. 1045 */ 1046#if !defined(TULIP_BPF_MTAP) && NBPFILTER > 0 1047#define TULIP_BPF_MTAP(sc, m) bpf_mtap((sc)->tulip_bpf, m) 1048#define TULIP_BPF_TAP(sc, p, l) bpf_tap((sc)->tulip_bpf, p, l) 1049#define TULIP_BPF_ATTACH(sc) bpfattach(&(sc)->tulip_bpf, &(sc)->tulip_if, DLT_EN10MB, sizeof(struct ether_header)) 1050#endif 1051 1052#if defined(TULIP_PERFSTATS) 1053#define TULIP_PERFMERGE(sc, member) \ 1054 do { (sc)->tulip_perfstats[TULIP_PERF_TOTAL].member \ 1055 += (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ 1056 (sc)->tulip_perfstats[TULIP_PERF_PREVIOUS].member \ 1057 = (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ 1058 (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member = 0; } while (0) 1059#define TULIP_PERFSTART(name) const tulip_cycle_t perfstart_ ## name = TULIP_PERFREAD(); 1060#define TULIP_PERFEND(name) do { \ 1061 (sc)->tulip_curperfstats.perf_ ## name ## _cycles += TULIP_PERFDIFF(perfstart_ ## name, TULIP_PERFREAD()); \ 1062 (sc)->tulip_curperfstats.perf_ ## name ++; \ 1063 } while (0) 1064#if defined(__i386__) 1065typedef u_quad_t tulip_cycle_t; 1066static __inline__ tulip_cycle_t 1067TULIP_PERFREAD( 1068 void) 1069{ 1070 tulip_cycle_t x; 1071 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); 1072 return x; 1073} 1074#define TULIP_PERFDIFF(s, f) ((f) - (s)) 1075#elif defined(__alpha__) 1076typedef unsigned long tulip_cycle_t; 1077static __inline__ tulip_cycle_t 1078TULIP_PERFREAD( 1079 void) 1080{ 1081 tulip_cycle_t x; 1082 __asm__ volatile ("rpcc %0" : "=r" (x)); 1083 return x; 1084} 1085#define TULIP_PERFDIFF(s, f) ((unsigned int) ((f) - (s))) 1086#endif 1087#else 1088#define TULIP_PERFSTART(name) 1089#define TULIP_PERFEND(name) do { } while (0) 1090#define TULIP_PERFMERGE(s,n) do { } while (0) 1091#endif /* TULIP_PERFSTATS */ 1092 1093/* 1094 * However, this change to FreeBSD I am much less enamored with. 1095 */ 1096#if !defined(TULIP_EADDR_FMT) 1097#define TULIP_EADDR_FMT "%s" 1098#define TULIP_EADDR_ARGS(addr) ether_sprintf(addr) 1099#endif 1100 1101#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 1102#define TULIP_MAX_TXSEG 30 1103 1104#define TULIP_ADDREQUAL(a1, a2) \ 1105 (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \ 1106 && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \ 1107 && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2]) 1108#define TULIP_ADDRBRDCST(a1) \ 1109 (((u_int16_t *)a1)[0] == 0xFFFFU \ 1110 && ((u_int16_t *)a1)[1] == 0xFFFFU \ 1111 && ((u_int16_t *)a1)[2] == 0xFFFFU) 1112 1113typedef int tulip_spl_t; 1114 1115#endif /* !defined(_DEVAR_H) */ 1116