The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/pci/if_devar.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 20db1a409db9a5894a33a835c3fe3cf8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.