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

Cache object: 1144e6ebf77f926e57c489849998cd7b


[ 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.