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