| 1 | /* $NetBSD: if_devar.h,v 1.32 1999/04/01 14:55:25 tsubai Exp $ */ |
| 2 | |
| 3 | /* $FreeBSD: src/sys/pci/if_devar.h,v 1.23.2.1 2000/08/04 23:25:10 peter Exp $ */ |
| 4 | /* $DragonFly: src/sys/dev/netif/de/if_devar.h,v 1.10 2005/02/21 04:58:34 joerg Exp $ */ |
| 5 | |
| 6 | /*- |
| 7 | * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * 2. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software withough specific prior written permission |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * Id: if_devar.h,v 1.28 1997/07/03 16:55:07 thomas Exp |
| 30 | */ |
| 31 | |
| 32 | #if !defined(_DEVAR_H) |
| 33 | #define _DEVAR_H |
| 34 | |
| 35 | typedef bus_addr_t tulip_csrptr_t; |
| 36 | |
| 37 | #define TULIP_PCI_CSRSIZE 8 |
| 38 | #define TULIP_PCI_CSROFFSET 0 |
| 39 | |
| 40 | #define TULIP_CSR_READ(sc, csr) \ |
| 41 | bus_space_read_4((sc)->tulip_csrs_bst, \ |
| 42 | (sc)->tulip_csrs_bsh, \ |
| 43 | (sc)->tulip_csrs.csr) |
| 44 | #define TULIP_CSR_WRITE(sc, csr, val) \ |
| 45 | bus_space_write_4((sc)->tulip_csrs_bst, \ |
| 46 | (sc)->tulip_csrs_bsh, \ |
| 47 | (sc)->tulip_csrs.csr, val) |
| 48 | |
| 49 | #define TULIP_CSR_READBYTE(sc, csr) \ |
| 50 | bus_space_read_1((sc)->tulip_csrs_bst, \ |
| 51 | (sc)->tulip_csrs_bsh, \ |
| 52 | (sc)->tulip_csrs.csr) |
| 53 | #define TULIP_CSR_WRITEBYTE(sc, csr, val) \ |
| 54 | bus_space_write_1((sc)->tulip_csrs_bst, \ |
| 55 | (sc)->tulip_csrs_bsh, \ |
| 56 | (sc)->tulip_csrs.csr, val) |
| 57 | |
| 58 | /* |
| 59 | * This structure contains "pointers" for the registers on |
| 60 | * the various 21x4x chips. CSR0 through CSR8 are common |
| 61 | * to all chips. After that, it gets messy... |
| 62 | */ |
| 63 | typedef struct { |
| 64 | tulip_csrptr_t csr_busmode; /* CSR0 */ |
| 65 | tulip_csrptr_t csr_txpoll; /* CSR1 */ |
| 66 | tulip_csrptr_t csr_rxpoll; /* CSR2 */ |
| 67 | tulip_csrptr_t csr_rxlist; /* CSR3 */ |
| 68 | tulip_csrptr_t csr_txlist; /* CSR4 */ |
| 69 | tulip_csrptr_t csr_status; /* CSR5 */ |
| 70 | tulip_csrptr_t csr_command; /* CSR6 */ |
| 71 | tulip_csrptr_t csr_intr; /* CSR7 */ |
| 72 | tulip_csrptr_t csr_missed_frames; /* CSR8 */ |
| 73 | tulip_csrptr_t csr_9; /* CSR9 */ |
| 74 | tulip_csrptr_t csr_10; /* CSR10 */ |
| 75 | tulip_csrptr_t csr_11; /* CSR11 */ |
| 76 | tulip_csrptr_t csr_12; /* CSR12 */ |
| 77 | tulip_csrptr_t csr_13; /* CSR13 */ |
| 78 | tulip_csrptr_t csr_14; /* CSR14 */ |
| 79 | tulip_csrptr_t csr_15; /* CSR15 */ |
| 80 | } tulip_regfile_t; |
| 81 | |
| 82 | #define csr_enetrom csr_9 /* 21040 */ |
| 83 | #define csr_reserved csr_10 /* 21040 */ |
| 84 | #define csr_full_duplex csr_11 /* 21040 */ |
| 85 | #define csr_bootrom csr_10 /* 21041/21140A/?? */ |
| 86 | #define csr_gp csr_12 /* 21140* */ |
| 87 | #define csr_watchdog csr_15 /* 21140* */ |
| 88 | #define csr_gp_timer csr_11 /* 21041/21140* */ |
| 89 | #define csr_srom_mii csr_9 /* 21041/21140* */ |
| 90 | #define csr_sia_status csr_12 /* 2104x */ |
| 91 | #define csr_sia_connectivity csr_13 /* 2104x */ |
| 92 | #define csr_sia_tx_rx csr_14 /* 2104x */ |
| 93 | #define csr_sia_general csr_15 /* 2104x */ |
| 94 | |
| 95 | /* |
| 96 | * While 21x4x allows chaining of its descriptors, this driver |
| 97 | * doesn't take advantage of it. We keep the descriptors in a |
| 98 | * traditional FIFO ring. |
| 99 | */ |
| 100 | typedef struct { |
| 101 | tulip_desc_t *ri_first; /* first entry in ring */ |
| 102 | tulip_desc_t *ri_last; /* one after last entry */ |
| 103 | tulip_desc_t *ri_nextin; /* next to processed by host */ |
| 104 | tulip_desc_t *ri_nextout; /* next to processed by adapter */ |
| 105 | int ri_max; |
| 106 | int ri_free; |
| 107 | } tulip_ringinfo_t; |
| 108 | |
| 109 | /* |
| 110 | * The 21040 has a stupid restriction in that the receive |
| 111 | * buffers must be longword aligned. But since Ethernet |
| 112 | * headers are not a multiple of longwords in size this forces |
| 113 | * the data to non-longword aligned. Since IP requires the |
| 114 | * data to be longword aligned, we need to copy it after it has |
| 115 | * been DMA'ed in our memory. |
| 116 | * |
| 117 | * Since we have to copy it anyways, we might as well as allocate |
| 118 | * dedicated receive space for the input. This allows to use a |
| 119 | * small receive buffer size and more ring entries to be able to |
| 120 | * better keep with a flood of tiny Ethernet packets. |
| 121 | * |
| 122 | * The receive space MUST ALWAYS be a multiple of the page size. |
| 123 | * And the number of receive descriptors multiplied by the size |
| 124 | * of the receive buffers must equal the recevive space. This |
| 125 | * is so that we can manipulate the page tables so that even if a |
| 126 | * packet wraps around the end of the receive space, we can |
| 127 | * treat it as virtually contiguous. |
| 128 | * |
| 129 | * The above used to be true (the stupid restriction is still true) |
| 130 | * but we gone to directly DMA'ing into MBUFs (unless it's on an |
| 131 | * architecture which can't handle unaligned accesses) because with |
| 132 | * 100Mb/s cards the copying is just too much of a hit. |
| 133 | */ |
| 134 | #if !defined(__i386__) |
| 135 | #define TULIP_COPY_RXDATA 1 |
| 136 | #endif |
| 137 | |
| 138 | #define TULIP_DATA_PER_DESC 2032 |
| 139 | #define TULIP_TXTIMER 4 |
| 140 | #define TULIP_RXDESCS 48 |
| 141 | #define TULIP_TXDESCS 128 |
| 142 | #define TULIP_RXQ_TARGET 32 |
| 143 | #if TULIP_RXQ_TARGET >= TULIP_RXDESCS |
| 144 | #error TULIP_RXQ_TARGET must be less than TULIP_RXDESCS |
| 145 | #endif |
| 146 | #define TULIP_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16) |
| 147 | |
| 148 | /* |
| 149 | * Forward reference to make C happy. |
| 150 | */ |
| 151 | typedef struct _tulip_softc_t tulip_softc_t; |
| 152 | |
| 153 | /* |
| 154 | * The various controllers support. |
| 155 | */ |
| 156 | |
| 157 | typedef enum { |
| 158 | TULIP_21040, |
| 159 | TULIP_21041, |
| 160 | TULIP_21140, TULIP_21140A, TULIP_21142, |
| 161 | TULIP_21143, |
| 162 | TULIP_CHIPID_UNKNOWN |
| 163 | } tulip_chipid_t; |
| 164 | |
| 165 | /* |
| 166 | * Various physical media types supported. |
| 167 | * BNCAUI is BNC or AUI since on the 21040 you can't really tell |
| 168 | * which is in use. |
| 169 | */ |
| 170 | typedef enum { |
| 171 | TULIP_MEDIA_UNKNOWN, |
| 172 | TULIP_MEDIA_10BASET, |
| 173 | TULIP_MEDIA_10BASET_FD, |
| 174 | TULIP_MEDIA_BNC, |
| 175 | TULIP_MEDIA_AUI, |
| 176 | TULIP_MEDIA_EXTSIA, |
| 177 | TULIP_MEDIA_AUIBNC, |
| 178 | TULIP_MEDIA_100BASETX, |
| 179 | TULIP_MEDIA_100BASETX_FD, |
| 180 | TULIP_MEDIA_100BASET4, |
| 181 | TULIP_MEDIA_100BASEFX, |
| 182 | TULIP_MEDIA_100BASEFX_FD, |
| 183 | TULIP_MEDIA_MAX |
| 184 | } tulip_media_t; |
| 185 | |
| 186 | #define TULIP_BIT(b) (1L << ((int)(b))) |
| 187 | #define TULIP_FDBIT(m) (1L << ((int)TULIP_MEDIA_ ## m ## _FD)) |
| 188 | #define TULIP_MBIT(m) (1L << ((int)TULIP_MEDIA_ ## m )) |
| 189 | #define TULIP_IS_MEDIA_FD(m) (TULIP_BIT(m) & \ |
| 190 | (TULIP_FDBIT(10BASET) \ |
| 191 | |TULIP_FDBIT(100BASETX) \ |
| 192 | |TULIP_FDBIT(100BASEFX))) |
| 193 | #define TULIP_CAN_MEDIA_FD(m) (TULIP_BIT(m) & \ |
| 194 | (TULIP_MBIT(10BASET) \ |
| 195 | |TULIP_MBIT(100BASETX) \ |
| 196 | |TULIP_MBIT(100BASEFX))) |
| 197 | #define TULIP_FD_MEDIA_OF(m) ((tulip_media_t)((m) + 1)) |
| 198 | #define TULIP_HD_MEDIA_OF(m) ((tulip_media_t)((m) - 1)) |
| 199 | #define TULIP_IS_MEDIA_100MB(m) ((m) >= TULIP_MEDIA_100BASETX) |
| 200 | #define TULIP_IS_MEDIA_TP(m) ((TULIP_BIT(m) & \ |
| 201 | (TULIP_MBIT(BNC) \ |
| 202 | |TULIP_MBIT(AUI) \ |
| 203 | |TULIP_MBIT(AUIBNC) \ |
| 204 | |TULIP_MBIT(EXTSIA))) == 0) |
| 205 | |
| 206 | #define TULIP_SROM_ATTR_MII 0x0100 |
| 207 | #define TULIP_SROM_ATTR_NWAY 0x0200 |
| 208 | #define TULIP_SROM_ATTR_AUTOSENSE 0x0400 |
| 209 | #define TULIP_SROM_ATTR_POWERUP 0x0800 |
| 210 | #define TULIP_SROM_ATTR_NOLINKPASS 0x1000 |
| 211 | |
| 212 | typedef struct { |
| 213 | enum { |
| 214 | TULIP_MEDIAINFO_NONE, |
| 215 | TULIP_MEDIAINFO_SIA, |
| 216 | TULIP_MEDIAINFO_GPR, |
| 217 | TULIP_MEDIAINFO_MII, |
| 218 | TULIP_MEDIAINFO_RESET, |
| 219 | TULIP_MEDIAINFO_SYM |
| 220 | } mi_type; |
| 221 | union { |
| 222 | struct { |
| 223 | u_int16_t sia_connectivity; |
| 224 | u_int16_t sia_tx_rx; |
| 225 | u_int16_t sia_general; |
| 226 | u_int32_t sia_gp_control; /* 21142/21143 */ |
| 227 | u_int32_t sia_gp_data; /* 21142/21143 */ |
| 228 | } un_sia; |
| 229 | struct { |
| 230 | u_int32_t gpr_cmdmode; |
| 231 | u_int32_t gpr_gpcontrol; /* 21142/21143 */ |
| 232 | u_int32_t gpr_gpdata; |
| 233 | u_int8_t gpr_actmask; |
| 234 | u_int8_t gpr_actdata; |
| 235 | u_int gpr_default : 1; |
| 236 | } un_gpr; |
| 237 | struct { |
| 238 | u_int32_t mii_mediamask; |
| 239 | u_int16_t mii_capabilities; |
| 240 | u_int16_t mii_advertisement; |
| 241 | u_int16_t mii_full_duplex; |
| 242 | u_int16_t mii_tx_threshold; |
| 243 | u_int16_t mii_interrupt; /* 21142/21143 */ |
| 244 | u_int8_t mii_phyaddr; |
| 245 | u_int8_t mii_gpr_length; |
| 246 | u_int8_t mii_gpr_offset; |
| 247 | u_int8_t mii_reset_length; |
| 248 | u_int8_t mii_reset_offset; |
| 249 | u_int32_t mii_phyid; |
| 250 | } un_mii; |
| 251 | } mi_un; |
| 252 | } tulip_media_info_t; |
| 253 | |
| 254 | #define mi_sia_connectivity mi_un.un_sia.sia_connectivity |
| 255 | #define mi_sia_tx_rx mi_un.un_sia.sia_tx_rx |
| 256 | #define mi_sia_general mi_un.un_sia.sia_general |
| 257 | #define mi_sia_gp_control mi_un.un_sia.sia_gp_control |
| 258 | #define mi_sia_gp_data mi_un.un_sia.sia_gp_data |
| 259 | |
| 260 | #define mi_gpcontrol mi_un.un_gpr.gpr_gpcontrol |
| 261 | #define mi_gpdata mi_un.un_gpr.gpr_gpdata |
| 262 | #define mi_actmask mi_un.un_gpr.gpr_actmask |
| 263 | #define mi_actdata mi_un.un_gpr.gpr_actdata |
| 264 | #define mi_default mi_un.un_gpr.gpr_default |
| 265 | #define mi_cmdmode mi_un.un_gpr.gpr_cmdmode |
| 266 | |
| 267 | #define mi_phyaddr mi_un.un_mii.mii_phyaddr |
| 268 | #define mi_gpr_length mi_un.un_mii.mii_gpr_length |
| 269 | #define mi_gpr_offset mi_un.un_mii.mii_gpr_offset |
| 270 | #define mi_reset_length mi_un.un_mii.mii_reset_length |
| 271 | #define mi_reset_offset mi_un.un_mii.mii_reset_offset |
| 272 | #define mi_capabilities mi_un.un_mii.mii_capabilities |
| 273 | #define mi_advertisement mi_un.un_mii.mii_advertisement |
| 274 | #define mi_full_duplex mi_un.un_mii.mii_full_duplex |
| 275 | #define mi_tx_threshold mi_un.un_mii.mii_tx_threshold |
| 276 | #define mi_mediamask mi_un.un_mii.mii_mediamask |
| 277 | #define mi_mii_interrupt mi_un.un_mii.mii_interrupt |
| 278 | #define mi_phyid mi_un.un_mii.mii_phyid |
| 279 | |
| 280 | #define TULIP_MEDIAINFO_SIA_INIT(sc, mi, chipid, media) do { \ |
| 281 | (mi)->mi_type = TULIP_MEDIAINFO_SIA; \ |
| 282 | sc->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ |
| 283 | (mi)->mi_sia_connectivity = TULIP_ ## chipid ## _SIACONN_ ## media; \ |
| 284 | (mi)->mi_sia_tx_rx = TULIP_ ## chipid ## _SIATXRX_ ## media; \ |
| 285 | (mi)->mi_sia_general = TULIP_ ## chipid ## _SIAGEN_ ## media; \ |
| 286 | } while (0) |
| 287 | |
| 288 | #define TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, media) do { \ |
| 289 | if ((sc)->tulip_mediums[TULIP_MEDIA_ ## media] == NULL \ |
| 290 | && ((mi)->mi_capabilities & PHYSTS_ ## media)) { \ |
| 291 | (sc)->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ |
| 292 | (mi)->mi_mediamask |= TULIP_BIT(TULIP_MEDIA_ ## media); \ |
| 293 | } \ |
| 294 | } while (0) |
| 295 | |
| 296 | #define TULIP_MII_NOPHY 32 |
| 297 | /* |
| 298 | * Some boards need to treated specially. The following enumeration |
| 299 | * identifies the cards with quirks (or those we just want to single |
| 300 | * out for special merit or scorn). |
| 301 | */ |
| 302 | typedef enum { |
| 303 | TULIP_21040_GENERIC, /* Generic 21040 (works with most any board) */ |
| 304 | TULIP_21140_ISV, /* Digital Semicondutor 21140 ISV SROM Format */ |
| 305 | TULIP_21142_ISV, /* Digital Semicondutor 21142 ISV SROM Format */ |
| 306 | TULIP_21143_ISV, /* Digital Semicondutor 21143 ISV SROM Format */ |
| 307 | TULIP_21140_DEC_EB, /* Digital Semicondutor 21140 Evaluation Board */ |
| 308 | TULIP_21140_MII, /* 21140[A] with MII */ |
| 309 | TULIP_21140_DEC_DE500, /* Digital DE500-?? 10/100 */ |
| 310 | TULIP_21140_SMC_9332, /* SMC 9332 */ |
| 311 | TULIP_21140_COGENT_EM100, /* Cogent EM100 100 only */ |
| 312 | TULIP_21140_ZNYX_ZX34X, /* ZNYX ZX342 10/100 */ |
| 313 | TULIP_21140_ASANTE, /* AsanteFast 10/100 */ |
| 314 | TULIP_21140_EN1207, /* Accton EN2107 10/100 BNC */ |
| 315 | TULIP_21041_GENERIC /* Generic 21041 card */ |
| 316 | } tulip_board_t; |
| 317 | |
| 318 | typedef enum { |
| 319 | TULIP_MEDIAPOLL_TIMER, /* 100ms timer fired */ |
| 320 | TULIP_MEDIAPOLL_FASTTIMER, /* <100ms timer fired */ |
| 321 | TULIP_MEDIAPOLL_LINKFAIL, /* called from interrupt routine */ |
| 322 | TULIP_MEDIAPOLL_LINKPASS, /* called from interrupt routine */ |
| 323 | TULIP_MEDIAPOLL_START, /* start a media probe (called from reset) */ |
| 324 | TULIP_MEDIAPOLL_TXPROBE_OK, /* txprobe succeeded */ |
| 325 | TULIP_MEDIAPOLL_TXPROBE_FAILED, /* txprobe failed */ |
| 326 | TULIP_MEDIAPOLL_MAX |
| 327 | } tulip_mediapoll_event_t; |
| 328 | |
| 329 | typedef enum { |
| 330 | TULIP_LINK_DOWN, /* Link is down */ |
| 331 | TULIP_LINK_UP, /* link is ok */ |
| 332 | TULIP_LINK_UNKNOWN /* we can't tell either way */ |
| 333 | } tulip_link_status_t; |
| 334 | |
| 335 | |
| 336 | /* |
| 337 | * This data structure is used to abstract out the quirks. |
| 338 | * media_probe = tries to determine the media type. |
| 339 | * media_select = enables the current media (or autosenses) |
| 340 | * media_poll = autosenses media |
| 341 | * media_preset = 21140, etal requires bit to set before the |
| 342 | * the software reset; hence pre-set. Should be |
| 343 | * pre-reset but that's ugly. |
| 344 | */ |
| 345 | |
| 346 | typedef struct { |
| 347 | tulip_board_t bd_type; |
| 348 | void (*bd_media_probe)(tulip_softc_t * const sc); |
| 349 | void (*bd_media_select)(tulip_softc_t * const sc); |
| 350 | void (*bd_media_poll)(tulip_softc_t * const sc, tulip_mediapoll_event_t event); |
| 351 | void (*bd_media_preset)(tulip_softc_t * const sc); |
| 352 | } tulip_boardsw_t; |
| 353 | |
| 354 | /* |
| 355 | * The next few declarations are for MII/PHY based board. |
| 356 | * |
| 357 | * The first enumeration identifies a superset of various datums |
| 358 | * that can be obtained from various PHY chips. Not all PHYs will |
| 359 | * support all datums. |
| 360 | * The modedata structure indicates what register contains |
| 361 | * a datum, what mask is applied the register contents, and what the |
| 362 | * result should be. |
| 363 | * The attr structure records information about a supported PHY. |
| 364 | * The phy structure records information about a PHY instance. |
| 365 | */ |
| 366 | |
| 367 | typedef enum { |
| 368 | PHY_MODE_10T, |
| 369 | PHY_MODE_100TX, |
| 370 | PHY_MODE_100T4, |
| 371 | PHY_MODE_FULLDUPLEX, |
| 372 | PHY_MODE_MAX |
| 373 | } tulip_phy_mode_t; |
| 374 | |
| 375 | typedef struct { |
| 376 | u_int16_t pm_regno; |
| 377 | u_int16_t pm_mask; |
| 378 | u_int16_t pm_value; |
| 379 | } tulip_phy_modedata_t; |
| 380 | |
| 381 | typedef struct { |
| 382 | u_int32_t attr_id; |
| 383 | u_int16_t attr_flags; |
| 384 | #define PHY_NEED_HARD_RESET 0x0001 |
| 385 | #define PHY_DUAL_CYCLE_TA 0x0002 |
| 386 | tulip_phy_modedata_t attr_modes[PHY_MODE_MAX]; |
| 387 | #ifdef TULIP_DEBUG |
| 388 | const char *attr_name; |
| 389 | #endif |
| 390 | } tulip_phy_attr_t; |
| 391 | |
| 392 | /* |
| 393 | * Various probe states used when trying to autosense the media. |
| 394 | */ |
| 395 | |
| 396 | typedef enum { |
| 397 | TULIP_PROBE_INACTIVE, |
| 398 | TULIP_PROBE_PHYRESET, |
| 399 | TULIP_PROBE_PHYAUTONEG, |
| 400 | TULIP_PROBE_GPRTEST, |
| 401 | TULIP_PROBE_MEDIATEST, |
| 402 | TULIP_PROBE_FAILED |
| 403 | } tulip_probe_state_t; |
| 404 | |
| 405 | typedef struct { |
| 406 | /* |
| 407 | * Transmit Statistics |
| 408 | */ |
| 409 | u_int32_t dot3StatsSingleCollisionFrames; |
| 410 | u_int32_t dot3StatsMultipleCollisionFrames; |
| 411 | u_int32_t dot3StatsSQETestErrors; |
| 412 | u_int32_t dot3StatsDeferredTransmissions; |
| 413 | u_int32_t dot3StatsLateCollisions; |
| 414 | u_int32_t dot3StatsExcessiveCollisions; |
| 415 | u_int32_t dot3StatsCarrierSenseErrors; |
| 416 | u_int32_t dot3StatsInternalMacTransmitErrors; |
| 417 | u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */ |
| 418 | u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */ |
| 419 | /* |
| 420 | * Receive Statistics |
| 421 | */ |
| 422 | u_int32_t dot3StatsMissedFrames; /* not in rfc1650! */ |
| 423 | u_int32_t dot3StatsAlignmentErrors; |
| 424 | u_int32_t dot3StatsFCSErrors; |
| 425 | u_int32_t dot3StatsFrameTooLongs; |
| 426 | u_int32_t dot3StatsInternalMacReceiveErrors; |
| 427 | } tulip_dot3_stats_t; |
| 428 | |
| 429 | /* |
| 430 | * Now to important stuff. This is softc structure (where does softc |
| 431 | * come from??? No idea) for the tulip device. |
| 432 | */ |
| 433 | struct _tulip_softc_t { |
| 434 | struct ifmedia tulip_ifmedia; |
| 435 | struct callout tulip_timer, tulip_fast_timer; |
| 436 | struct arpcom tulip_ac; |
| 437 | bus_space_tag_t tulip_csrs_bst; |
| 438 | bus_space_handle_t tulip_csrs_bsh; |
| 439 | tulip_regfile_t tulip_csrs; |
| 440 | u_int32_t tulip_flags; |
| 441 | #define TULIP_WANTSETUP 0x00000001 |
| 442 | #define TULIP_WANTHASHPERFECT 0x00000002 |
| 443 | #define TULIP_WANTHASHONLY 0x00000004 |
| 444 | #define TULIP_DOINGSETUP 0x00000008 |
| 445 | #define TULIP_PRINTMEDIA 0x00000010 |
| 446 | #define TULIP_TXPROBE_ACTIVE 0x00000020 |
| 447 | #define TULIP_ALLMULTI 0x00000040 |
| 448 | #define TULIP_WANTRXACT 0x00000080 |
| 449 | #define TULIP_RXACT 0x00000100 |
| 450 | #define TULIP_INRESET 0x00000200 |
| 451 | #define TULIP_NEEDRESET 0x00000400 |
| 452 | #define TULIP_SQETEST 0x00000800 |
| 453 | #define TULIP_xxxxxx0 0x00001000 |
| 454 | #define TULIP_xxxxxx1 0x00002000 |
| 455 | #define TULIP_WANTTXSTART 0x00004000 |
| 456 | #define TULIP_NEWTXTHRESH 0x00008000 |
| 457 | #define TULIP_NOAUTOSENSE 0x00010000 |
| 458 | #define TULIP_PRINTLINKUP 0x00020000 |
| 459 | #define TULIP_LINKUP 0x00040000 |
| 460 | #define TULIP_RXBUFSLOW 0x00080000 |
| 461 | #define TULIP_NOMESSAGES 0x00100000 |
| 462 | #define TULIP_SYSTEMERROR 0x00200000 |
| 463 | #define TULIP_TIMEOUTPENDING 0x00400000 |
| 464 | #define TULIP_xxxxxx2 0x00800000 |
| 465 | #define TULIP_TRYNWAY 0x01000000 |
| 466 | #define TULIP_DIDNWAY 0x02000000 |
| 467 | #define TULIP_RXIGNORE 0x04000000 |
| 468 | #define TULIP_PROBE1STPASS 0x08000000 |
| 469 | #define TULIP_DEVICEPROBE 0x10000000 |
| 470 | #define TULIP_PROMISC 0x20000000 |
| 471 | #define TULIP_HASHONLY 0x40000000 |
| 472 | #define TULIP_xxxxxx3 0x80000000 |
| 473 | /* only 4 bits left! */ |
| 474 | u_int32_t tulip_features; /* static bits indicating features of chip */ |
| 475 | #define TULIP_HAVE_GPR 0x00000001 /* have gp register (140[A]) */ |
| 476 | #define TULIP_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */ |
| 477 | #define TULIP_HAVE_POWERMGMT 0x00000004 /* Snooze/sleep modes */ |
| 478 | #define TULIP_HAVE_MII 0x00000008 /* Some medium on MII */ |
| 479 | #define TULIP_HAVE_SIANWAY 0x00000010 /* SIA does NWAY */ |
| 480 | #define TULIP_HAVE_DUALSENSE 0x00000020 /* SIA senses both AUI & TP */ |
| 481 | #define TULIP_HAVE_SIAGP 0x00000040 /* SIA has a GP port */ |
| 482 | #define TULIP_HAVE_BROKEN_HASH 0x00000080 /* Broken Multicast Hash */ |
| 483 | #define TULIP_HAVE_ISVSROM 0x00000100 /* uses ISV SROM Format */ |
| 484 | #define TULIP_HAVE_BASEROM 0x00000200 /* Board ROM can be cloned */ |
| 485 | #define TULIP_HAVE_SLAVEDROM 0x00000400 /* Board ROM cloned */ |
| 486 | #define TULIP_HAVE_SLAVEDINTR 0x00000800 /* Board slaved interrupt */ |
| 487 | #define TULIP_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */ |
| 488 | #define TULIP_HAVE_OKROM 0x00002000 /* ROM was recognized */ |
| 489 | #define TULIP_HAVE_NOMEDIA 0x00004000 /* did not detect any media */ |
| 490 | #define TULIP_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */ |
| 491 | #define TULIP_HAVE_SIA100 0x00010000 /* has LS100 in SIA status */ |
| 492 | #define TULIP_HAVE_OKSROM 0x00020000 /* SROM CRC is OK */ |
| 493 | u_int32_t tulip_intrmask; /* our copy of csr_intr */ |
| 494 | u_int32_t tulip_cmdmode; /* our copy of csr_cmdmode */ |
| 495 | u_int32_t tulip_last_system_error : 3; /* last system error (only value is TULIP_SYSTEMERROR is also set) */ |
| 496 | u_int32_t tulip_txtimer : 2; /* transmission timer */ |
| 497 | u_int32_t tulip_system_errors; /* number of system errors encountered */ |
| 498 | u_int32_t tulip_statusbits; /* status bits from CSR5 that may need to be printed */ |
| 499 | |
| 500 | tulip_media_info_t *tulip_mediums[TULIP_MEDIA_MAX]; /* indexes into mediainfo */ |
| 501 | tulip_media_t tulip_media; /* current media type */ |
| 502 | u_int32_t tulip_abilities; /* remote system's abiltities (as defined in IEEE 802.3u) */ |
| 503 | |
| 504 | u_int8_t tulip_revinfo; /* revision of chip */ |
| 505 | u_int8_t tulip_phyaddr; /* 0..31 -- address of current phy */ |
| 506 | u_int8_t tulip_gpinit; /* active pins on 21140 */ |
| 507 | u_int8_t tulip_gpdata; /* default gpdata for 21140 */ |
| 508 | |
| 509 | struct { |
| 510 | u_int8_t probe_count; /* count of probe operations */ |
| 511 | int32_t probe_timeout; /* time in ms of probe timeout */ |
| 512 | tulip_probe_state_t probe_state; /* current media probe state */ |
| 513 | tulip_media_t probe_media; /* current media being probed */ |
| 514 | u_int32_t probe_mediamask; /* medias checked */ |
| 515 | u_int32_t probe_passes; /* times autosense failed */ |
| 516 | u_int32_t probe_txprobes; /* txprobes attempted */ |
| 517 | } tulip_probe; |
| 518 | #define tulip_probe_count tulip_probe.probe_count |
| 519 | #define tulip_probe_timeout tulip_probe.probe_timeout |
| 520 | #define tulip_probe_state tulip_probe.probe_state |
| 521 | #define tulip_probe_media tulip_probe.probe_media |
| 522 | #define tulip_probe_mediamask tulip_probe.probe_mediamask |
| 523 | #define tulip_probe_passes tulip_probe.probe_passes |
| 524 | |
| 525 | tulip_chipid_t tulip_chipid; /* type of chip we are using */ |
| 526 | const tulip_boardsw_t *tulip_boardsw; /* board/chip characteristics */ |
| 527 | tulip_softc_t *tulip_slaves; /* slaved devices (ZX3xx) */ |
| 528 | #if defined(TULIP_DEBUG) |
| 529 | /* |
| 530 | * Debugging/Statistical information |
| 531 | */ |
| 532 | struct { |
| 533 | tulip_media_t dbg_last_media; |
| 534 | u_int32_t dbg_intrs; |
| 535 | u_int32_t dbg_media_probes; |
| 536 | u_int32_t dbg_txprobe_nocarr; |
| 537 | u_int32_t dbg_txprobe_exccoll; |
| 538 | u_int32_t dbg_link_downed; |
| 539 | u_int32_t dbg_link_suspected; |
| 540 | u_int32_t dbg_link_intrs; |
| 541 | u_int32_t dbg_link_pollintrs; |
| 542 | u_int32_t dbg_link_failures; |
| 543 | u_int32_t dbg_nway_starts; |
| 544 | u_int32_t dbg_nway_failures; |
| 545 | u_int16_t dbg_phyregs[32][4]; |
| 546 | u_int32_t dbg_rxlowbufs; |
| 547 | u_int32_t dbg_rxintrs; |
| 548 | u_int32_t dbg_last_rxintrs; |
| 549 | u_int32_t dbg_high_rxintrs_hz; |
| 550 | u_int32_t dbg_no_txmaps; |
| 551 | u_int32_t dbg_txput_finishes[8]; |
| 552 | u_int32_t dbg_txprobes_ok[TULIP_MEDIA_MAX]; |
| 553 | u_int32_t dbg_txprobes_failed[TULIP_MEDIA_MAX]; |
| 554 | u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX]; |
| 555 | u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS]; |
| 556 | } tulip_dbg; |
| 557 | #endif |
| 558 | struct ifqueue tulip_txq; |
| 559 | struct ifqueue tulip_rxq; |
| 560 | tulip_dot3_stats_t tulip_dot3stats; |
| 561 | tulip_ringinfo_t tulip_rxinfo; |
| 562 | tulip_ringinfo_t tulip_txinfo; |
| 563 | tulip_media_info_t tulip_mediainfo[10]; |
| 564 | /* |
| 565 | * The setup buffers for sending the setup frame to the chip. |
| 566 | * one is the one being sent while the other is the one being |
| 567 | * filled. |
| 568 | */ |
| 569 | u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)]; |
| 570 | u_int32_t tulip_setupdata[192/sizeof(u_int32_t)]; |
| 571 | char tulip_boardid[16]; /* buffer for board ID */ |
| 572 | u_int8_t tulip_rombuf[128]; |
| 573 | u_int8_t tulip_pci_busno; /* needed for multiport boards */ |
| 574 | u_int8_t tulip_pci_devno; /* needed for multiport boards */ |
| 575 | u_int8_t tulip_connidx; |
| 576 | tulip_srom_connection_t tulip_conntype; |
| 577 | tulip_desc_t *tulip_rxdescs; |
| 578 | tulip_desc_t *tulip_txdescs; |
| 579 | }; |
| 580 | |
| 581 | #define TULIP_DO_AUTOSENSE(sc) (IFM_SUBTYPE((sc)->tulip_ifmedia.ifm_media) == IFM_AUTO) |
| 582 | |
| 583 | |
| 584 | static const char * const tulip_chipdescs[] = { |
| 585 | "21040 [10Mb/s]", |
| 586 | "21041 [10Mb/s]", |
| 587 | "21140 [10-100Mb/s]", |
| 588 | "21140A [10-100Mb/s]", |
| 589 | "21142 [10-100Mb/s]", |
| 590 | "21143 [10-100Mb/s]", |
| 591 | }; |
| 592 | |
| 593 | static const char * const tulip_mediums[] = { |
| 594 | "unknown", /* TULIP_MEDIA_UNKNOWN */ |
| 595 | "10baseT", /* TULIP_MEDIA_10BASET */ |
| 596 | "Full Duplex 10baseT", /* TULIP_MEDIA_10BASET_FD */ |
| 597 | "BNC", /* TULIP_MEDIA_BNC */ |
| 598 | "AUI", /* TULIP_MEDIA_AUI */ |
| 599 | "External SIA", /* TULIP_MEDIA_EXTSIA */ |
| 600 | "AUI/BNC", /* TULIP_MEDIA_AUIBNC */ |
| 601 | "100baseTX", /* TULIP_MEDIA_100BASET */ |
| 602 | "Full Duplex 100baseTX", /* TULIP_MEDIA_100BASET_FD */ |
| 603 | "100baseT4", /* TULIP_MEDIA_100BASET4 */ |
| 604 | "100baseFX", /* TULIP_MEDIA_100BASEFX */ |
| 605 | "Full Duplex 100baseFX", /* TULIP_MEDIA_100BASEFX_FD */ |
| 606 | }; |
| 607 | |
| 608 | static const int tulip_media_to_ifmedia[] = { |
| 609 | IFM_ETHER | IFM_NONE, /* TULIP_MEDIA_UNKNOWN */ |
| 610 | IFM_ETHER | IFM_10_T, /* TULIP_MEDIA_10BASET */ |
| 611 | IFM_ETHER | IFM_10_T | IFM_FDX, /* TULIP_MEDIA_10BASET_FD */ |
| 612 | IFM_ETHER | IFM_10_2, /* TULIP_MEDIA_BNC */ |
| 613 | IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUI */ |
| 614 | IFM_ETHER | IFM_MANUAL, /* TULIP_MEDIA_EXTSIA */ |
| 615 | IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUIBNC */ |
| 616 | IFM_ETHER | IFM_100_TX, /* TULIP_MEDIA_100BASET */ |
| 617 | IFM_ETHER | IFM_100_TX | IFM_FDX, /* TULIP_MEDIA_100BASET_FD */ |
| 618 | IFM_ETHER | IFM_100_T4, /* TULIP_MEDIA_100BASET4 */ |
| 619 | IFM_ETHER | IFM_100_FX, /* TULIP_MEDIA_100BASEFX */ |
| 620 | IFM_ETHER | IFM_100_FX | IFM_FDX, /* TULIP_MEDIA_100BASEFX_FD */ |
| 621 | }; |
| 622 | |
| 623 | static const char * const tulip_system_errors[] = { |
| 624 | "parity error", |
| 625 | "master abort", |
| 626 | "target abort", |
| 627 | "reserved #3", |
| 628 | "reserved #4", |
| 629 | "reserved #5", |
| 630 | "reserved #6", |
| 631 | "reserved #7", |
| 632 | }; |
| 633 | |
| 634 | static const char * const tulip_status_bits[] = { |
| 635 | NULL, |
| 636 | "transmit process stopped", |
| 637 | NULL, |
| 638 | "transmit jabber timeout", |
| 639 | |
| 640 | NULL, |
| 641 | "transmit underflow", |
| 642 | NULL, |
| 643 | "receive underflow", |
| 644 | |
| 645 | "receive process stopped", |
| 646 | "receive watchdog timeout", |
| 647 | NULL, |
| 648 | NULL, |
| 649 | |
| 650 | "link failure", |
| 651 | NULL, |
| 652 | NULL, |
| 653 | }; |
| 654 | |
| 655 | static const struct { |
| 656 | tulip_srom_connection_t sc_type; |
| 657 | tulip_media_t sc_media; |
| 658 | u_int32_t sc_attrs; |
| 659 | } tulip_srom_conninfo[] = { |
| 660 | { TULIP_SROM_CONNTYPE_10BASET, TULIP_MEDIA_10BASET }, |
| 661 | { TULIP_SROM_CONNTYPE_BNC, TULIP_MEDIA_BNC }, |
| 662 | { TULIP_SROM_CONNTYPE_AUI, TULIP_MEDIA_AUI }, |
| 663 | { TULIP_SROM_CONNTYPE_100BASETX, TULIP_MEDIA_100BASETX }, |
| 664 | { TULIP_SROM_CONNTYPE_100BASET4, TULIP_MEDIA_100BASET4 }, |
| 665 | { TULIP_SROM_CONNTYPE_100BASEFX, TULIP_MEDIA_100BASEFX }, |
| 666 | { TULIP_SROM_CONNTYPE_MII_10BASET, TULIP_MEDIA_10BASET, |
| 667 | TULIP_SROM_ATTR_MII }, |
| 668 | { TULIP_SROM_CONNTYPE_MII_100BASETX, TULIP_MEDIA_100BASETX, |
| 669 | TULIP_SROM_ATTR_MII }, |
| 670 | { TULIP_SROM_CONNTYPE_MII_100BASET4, TULIP_MEDIA_100BASET4, |
| 671 | TULIP_SROM_ATTR_MII }, |
| 672 | { TULIP_SROM_CONNTYPE_MII_100BASEFX, TULIP_MEDIA_100BASEFX, |
| 673 | TULIP_SROM_ATTR_MII }, |
| 674 | { TULIP_SROM_CONNTYPE_10BASET_NWAY, TULIP_MEDIA_10BASET, |
| 675 | TULIP_SROM_ATTR_NWAY }, |
| 676 | { TULIP_SROM_CONNTYPE_10BASET_FD, TULIP_MEDIA_10BASET_FD }, |
| 677 | { TULIP_SROM_CONNTYPE_MII_10BASET_FD, TULIP_MEDIA_10BASET_FD, |
| 678 | TULIP_SROM_ATTR_MII }, |
| 679 | { TULIP_SROM_CONNTYPE_100BASETX_FD, TULIP_MEDIA_100BASETX_FD }, |
| 680 | { TULIP_SROM_CONNTYPE_MII_100BASETX_FD, TULIP_MEDIA_100BASETX_FD, |
| 681 | TULIP_SROM_ATTR_MII }, |
| 682 | { TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS, TULIP_MEDIA_10BASET, |
| 683 | TULIP_SROM_ATTR_NOLINKPASS }, |
| 684 | { TULIP_SROM_CONNTYPE_AUTOSENSE, TULIP_MEDIA_UNKNOWN, |
| 685 | TULIP_SROM_ATTR_AUTOSENSE }, |
| 686 | { TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP, TULIP_MEDIA_UNKNOWN, |
| 687 | TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_POWERUP }, |
| 688 | { TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY, TULIP_MEDIA_UNKNOWN, |
| 689 | TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_NWAY }, |
| 690 | { TULIP_SROM_CONNTYPE_NOT_USED, TULIP_MEDIA_UNKNOWN } |
| 691 | }; |
| 692 | #define TULIP_SROM_LASTCONNIDX \ |
| 693 | (sizeof(tulip_srom_conninfo)/sizeof(tulip_srom_conninfo[0]) - 1) |
| 694 | |
| 695 | static const struct { |
| 696 | tulip_media_t sm_type; |
| 697 | tulip_srom_media_t sm_srom_type; |
| 698 | } tulip_srom_mediums[] = { |
| 699 | { TULIP_MEDIA_100BASEFX_FD, TULIP_SROM_MEDIA_100BASEFX_FD }, |
| 700 | { TULIP_MEDIA_100BASEFX, TULIP_SROM_MEDIA_100BASEFX }, |
| 701 | { TULIP_MEDIA_100BASET4, TULIP_SROM_MEDIA_100BASET4 }, |
| 702 | { TULIP_MEDIA_100BASETX_FD, TULIP_SROM_MEDIA_100BASETX_FD }, |
| 703 | { TULIP_MEDIA_100BASETX, TULIP_SROM_MEDIA_100BASETX }, |
| 704 | { TULIP_MEDIA_10BASET_FD, TULIP_SROM_MEDIA_10BASET_FD }, |
| 705 | { TULIP_MEDIA_AUI, TULIP_SROM_MEDIA_AUI }, |
| 706 | { TULIP_MEDIA_BNC, TULIP_SROM_MEDIA_BNC }, |
| 707 | { TULIP_MEDIA_10BASET, TULIP_SROM_MEDIA_10BASET }, |
| 708 | { TULIP_MEDIA_UNKNOWN } |
| 709 | }; |
| 710 | |
| 711 | /* |
| 712 | * This driver supports a maximum of 32 tulip boards. |
| 713 | * This should be enough for the forseeable future. |
| 714 | */ |
| 715 | #define TULIP_MAX_DEVICES 32 |
| 716 | |
| 717 | #define TULIP_RXDESC_PRESYNC(sc, di, s) do { } while (0) |
| 718 | #define TULIP_RXDESC_POSTSYNC(sc, di, s) do { } while (0) |
| 719 | #define TULIP_RXMAP_PRESYNC(sc, map) do { } while (0) |
| 720 | #define TULIP_RXMAP_POSTSYNC(sc, map) do { } while (0) |
| 721 | #define TULIP_RXMAP_CREATE(sc, mapp) do { } while (0) |
| 722 | |
| 723 | #define TULIP_TXDESC_PRESYNC(sc, di, s) do { } while (0) |
| 724 | #define TULIP_TXDESC_POSTSYNC(sc, di, s) do { } while (0) |
| 725 | #define TULIP_TXMAP_PRESYNC(sc, map) do { } while (0) |
| 726 | #define TULIP_TXMAP_POSTSYNC(sc, map) do { } while (0) |
| 727 | #define TULIP_TXMAP_CREATE(sc, mapp) do { } while (0) |
| 728 | |
| 729 | #ifdef notyet |
| 730 | #define SIOCGADDRROM _IOW('i', 240, struct ifreq) /* get 128 bytes of ROM */ |
| 731 | #define SIOCGCHIPID _IOWR('i', 241, struct ifreq) /* get chipid */ |
| 732 | #endif |
| 733 | |
| 734 | static tulip_softc_t *tulips[TULIP_MAX_DEVICES]; |
| 735 | |
| 736 | #define loudprintf if (bootverbose) printf |
| 737 | |
| 738 | #ifndef tulip_if |
| 739 | #define tulip_if tulip_ac.ac_if |
| 740 | #endif |
| 741 | #ifndef tulip_unit |
| 742 | #define tulip_unit tulip_if.if_dunit |
| 743 | #endif |
| 744 | #define tulip_name tulip_if.if_dname |
| 745 | #ifndef tulip_enaddr |
| 746 | #define tulip_enaddr tulip_ac.ac_enaddr |
| 747 | #endif |
| 748 | |
| 749 | #if !defined(TULIP_KVATOPHYS) |
| 750 | #define TULIP_KVATOPHYS(sc, va) vtophys(va) |
| 751 | #endif |
| 752 | |
| 753 | #define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ |
| 754 | #define TULIP_MAX_TXSEG 30 |
| 755 | |
| 756 | #define TULIP_ADDREQUAL(a1, a2) \ |
| 757 | (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \ |
| 758 | && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \ |
| 759 | && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2]) |
| 760 | #define TULIP_ADDRBRDCST(a1) \ |
| 761 | (((u_int16_t *)a1)[0] == 0xFFFFU \ |
| 762 | && ((u_int16_t *)a1)[1] == 0xFFFFU \ |
| 763 | && ((u_int16_t *)a1)[2] == 0xFFFFU) |
| 764 | |
| 765 | #endif /* !defined(_DEVAR_H) */ |