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/ic/dp83932var.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: dp83932var.h,v 1.11 2008/04/28 20:23:49 martin Exp $   */
    2 
    3 /*-
    4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Jason R. Thorpe.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #ifndef _DEV_IC_DP83932VAR_H_
   33 #define _DEV_IC_DP83932VAR_H_
   34 
   35 /*
   36  * Data structure definitions for the National Semiconductor DP83932
   37  * Systems-Oriented Network Interface Controller (SONIC).
   38  */
   39 
   40 /*
   41  * NOTE: The control data for the SONIC must not cross a 64k boundary,
   42  * so we have to be careful about how we size things.
   43  *
   44  * Also, since the SONIC is only a 10Mb/s chip, and systems on which
   45  * it is present tend to be low on memory, we try to keep the data
   46  * structure sizes small.
   47  */
   48 
   49 /*
   50  * Transmit descriptor list size.
   51  */
   52 #define SONIC_NTXDESC           32
   53 #define SONIC_NTXDESC_MASK      (SONIC_NTXDESC - 1)
   54 #define SONIC_NEXTTX(x)         (((x) + 1) & SONIC_NTXDESC_MASK)
   55 
   56 /*
   57  * Receive descriptor list size.
   58  */
   59 #define SONIC_NRXDESC           32
   60 #define SONIC_NRXDESC_MASK      (SONIC_NRXDESC - 1)
   61 #define SONIC_NEXTRX(x)         (((x) + 1) & SONIC_NRXDESC_MASK)
   62 #define SONIC_PREVRX(x)         (((x) - 1) & SONIC_NRXDESC_MASK)
   63 #define SONIC_RXSEQ_TO_DESC(x)  ((x) & SONIC_NRXDESC_MASK)
   64 
   65 /*
   66  * Number of CAM entries.
   67  */
   68 #define SONIC_NCAMENT           16
   69 
   70 /*
   71  * Control structures are DMA'd to the SONIC chip.  We allocate them in
   72  * a single clump that maps to a single DMA segment to make several things
   73  * easier.
   74  */
   75 struct sonic_control_data16 {
   76         /*
   77          * The transmit descriptors.
   78          */
   79         struct sonic_tda16 scd_txdescs[SONIC_NTXDESC];
   80 
   81         /*
   82          * The receive descriptors.
   83          */
   84         struct sonic_rda16 scd_rxdescs[SONIC_NRXDESC];
   85 
   86         /*
   87          * The receive resource descriptors.
   88          */
   89         struct sonic_rra16 scd_rxbufs[SONIC_NRXDESC];
   90 
   91         /*
   92          * The CAM descriptors.
   93          */
   94         struct sonic_cda16 scd_cam[SONIC_NCAMENT];
   95         uint16_t scd_camenable;
   96 };
   97 
   98 #define SONIC_CDOFF16(x)        offsetof(struct sonic_control_data16, x)
   99 #define SONIC_CDTXOFF16(x)      SONIC_CDOFF16(scd_txdescs[(x)])
  100 #define SONIC_CDRXOFF16(x)      SONIC_CDOFF16(scd_rxdescs[(x)])
  101 #define SONIC_CDRROFF16(x)      SONIC_CDOFF16(scd_rxbufs[(x)])
  102 #define SONIC_CDCAMOFF16        SONIC_CDOFF16(scd_cam)
  103 #define SONIC_CDCAMSIZE16       \
  104         (sizeof(struct sonic_cda16) * SONIC_NCAMENT + sizeof(uint16_t))
  105 
  106 struct sonic_control_data32 {
  107         /*
  108          * The transmit descriptors.
  109          */
  110         struct sonic_tda32 scd_txdescs[SONIC_NTXDESC];
  111 
  112         /*
  113          * The receive descriptors.
  114          */
  115         struct sonic_rda32 scd_rxdescs[SONIC_NRXDESC];
  116 
  117         /*
  118          * The receive resource descriptors.
  119          */
  120         struct sonic_rra32 scd_rxbufs[SONIC_NRXDESC];
  121 
  122         /*
  123          * The CAM descriptors.
  124          */
  125         struct sonic_cda32 scd_cam[SONIC_NCAMENT];
  126         uint32_t scd_camenable;
  127 };
  128 
  129 #define SONIC_CDOFF32(x)        offsetof(struct sonic_control_data32, x)
  130 #define SONIC_CDTXOFF32(x)      SONIC_CDOFF32(scd_txdescs[(x)])
  131 #define SONIC_CDRXOFF32(x)      SONIC_CDOFF32(scd_rxdescs[(x)])
  132 #define SONIC_CDRROFF32(x)      SONIC_CDOFF32(scd_rxbufs[(x)])
  133 #define SONIC_CDCAMOFF32        SONIC_CDOFF32(scd_cam)
  134 #define SONIC_CDCAMSIZE32       \
  135         (sizeof(struct sonic_cda32) * SONIC_NCAMENT + sizeof(uint32_t))
  136 
  137 /*
  138  * Software state for transmit and receive descriptors.
  139  */
  140 struct sonic_descsoft {
  141         struct mbuf *ds_mbuf;           /* head of mbuf chain */
  142         bus_dmamap_t ds_dmamap;         /* our DMA map */
  143 };
  144 
  145 /*
  146  * Software state per device.
  147  */
  148 struct sonic_softc {
  149         device_t sc_dev;                /* generic device information */
  150         bus_space_tag_t sc_st;          /* bus space tag */
  151         bus_space_handle_t sc_sh;       /* bus space handle */
  152         bus_dma_tag_t sc_dmat;          /* bus DMA tag */
  153         struct ethercom sc_ethercom;    /* ethernet common data */
  154         void *sc_sdhook;                /* shutdown hook */
  155 
  156         int sc_32bit;                   /* use 32-bit mode */
  157         int sc_bigendian;               /* BMODE -> Vcc */
  158 
  159         /* Our register map. */
  160         bus_addr_t sc_regmap[SONIC_NREGS];
  161 
  162         bus_dmamap_t sc_cddmamap;       /* control data DMA map */
  163 #define sc_cddma        sc_cddmamap->dm_segs[0].ds_addr
  164         bus_dmamap_t sc_nulldmamap;     /* DMA map for the pad buffer */
  165 #define sc_nulldma     sc_nulldmamap->dm_segs[0].ds_addr
  166 
  167         /*
  168          * Software state for transmit and receive descriptors.
  169          */
  170         struct sonic_descsoft sc_txsoft[SONIC_NTXDESC];
  171         struct sonic_descsoft sc_rxsoft[SONIC_NRXDESC];
  172 
  173         /*
  174          * Control data structures.
  175          */
  176         union {
  177                 struct sonic_control_data16 *cdun_16;
  178                 struct sonic_control_data32 *cdun_32;
  179         } sc_cdun;
  180 #define sc_cdata16      sc_cdun.cdun_16
  181 #define sc_cdata32      sc_cdun.cdun_32
  182 
  183 #define sc_tda16        sc_cdun.cdun_16->scd_txdescs
  184 #define sc_rda16        sc_cdun.cdun_16->scd_rxdescs
  185 #define sc_rra16        sc_cdun.cdun_16->scd_rxbufs
  186 #define sc_cda16        sc_cdun.cdun_16->scd_cam
  187 #define sc_cdaenable16  sc_cdun.cdun_16->scd_camenable
  188 
  189 #define sc_tda32        sc_cdun.cdun_32->scd_txdescs
  190 #define sc_rda32        sc_cdun.cdun_32->scd_rxdescs
  191 #define sc_rra32        sc_cdun.cdun_32->scd_rxbufs
  192 #define sc_cda32        sc_cdun.cdun_32->scd_cam
  193 #define sc_cdaenable32  sc_cdun.cdun_32->scd_camenable
  194 
  195         int     sc_txpending;           /* number of Tx requests pending */
  196         int     sc_txdirty;             /* first dirty Tx descriptor */
  197         int     sc_txlast;              /* last used Tx descriptor */
  198 
  199         int     sc_rxptr;               /* next ready Rx descriptor */
  200 
  201         uint16_t sc_imr;                /* prototype IMR */
  202         uint16_t sc_dcr;                /* prototype DCR */
  203         uint16_t sc_dcr2;               /* prototype DCR2 */
  204 };
  205 
  206 #define CSR_READ(sc, reg)                                               \
  207         bus_space_read_2((sc)->sc_st, (sc)->sc_sh,                      \
  208             (sc)->sc_regmap[(reg)])
  209 
  210 #define CSR_WRITE(sc, reg, val)                                         \
  211         bus_space_write_2((sc)->sc_st, (sc)->sc_sh,                     \
  212             (sc)->sc_regmap[(reg)], (val))
  213 
  214 #define SONIC_CDTXADDR16(sc, x)                                         \
  215         ((sc)->sc_cddma + SONIC_CDTXOFF16((x)))
  216 
  217 #define SONIC_CDTXADDR32(sc, x)                                         \
  218         ((sc)->sc_cddma + SONIC_CDTXOFF32((x)))
  219 
  220 #define SONIC_CDTXADDR(sc, x)                                           \
  221         ((sc)->sc_32bit ? SONIC_CDTXADDR32((sc), (x)) :                 \
  222             SONIC_CDTXADDR16((sc), (x)))
  223 
  224 #define SONIC_CDRXADDR16(sc, x)                                         \
  225         ((sc)->sc_cddma + SONIC_CDRXOFF16((x)))
  226 
  227 #define SONIC_CDRXADDR32(sc, x)                                         \
  228         ((sc)->sc_cddma + SONIC_CDRXOFF32((x)))
  229 
  230 #define SONIC_CDRXADDR(sc, x)                                           \
  231         ((sc)->sc_32bit ? SONIC_CDRXADDR32((sc), (x)) :                 \
  232             SONIC_CDRXADDR16((sc), (x)))
  233 
  234 #define SONIC_CDRRADDR(sc, x)                                           \
  235         ((sc)->sc_cddma +                                               \
  236          ((sc)->sc_32bit ? SONIC_CDRROFF32((x)) : SONIC_CDRROFF16((x))))
  237 
  238 #define SONIC_CDCAMADDR(sc)                                             \
  239         ((sc)->sc_cddma +                                               \
  240          ((sc)->sc_32bit ? SONIC_CDCAMOFF32 : SONIC_CDCAMOFF16))
  241 
  242 #define SONIC_CDTXSYNC16(sc, x, ops)                                    \
  243         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  244             SONIC_CDTXOFF16((x)), sizeof(struct sonic_tda16), (ops))
  245 
  246 #define SONIC_CDTXSYNC32(sc, x, ops)                                    \
  247         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  248             SONIC_CDTXOFF32((x)), sizeof(struct sonic_tda32), (ops))
  249 
  250 #define SONIC_CDRXSYNC16(sc, x, ops)                                    \
  251         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  252             SONIC_CDRXOFF16((x)), sizeof(struct sonic_rda16), (ops))
  253 
  254 #define SONIC_CDRXSYNC32(sc, x, ops)                                    \
  255         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  256             SONIC_CDRXOFF32((x)), sizeof(struct sonic_rda32), (ops))
  257 
  258 #define SONIC_CDRRSYNC16(sc, x, ops)                                    \
  259         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  260             SONIC_CDRROFF16((x)), sizeof(struct sonic_rra16), (ops))
  261 
  262 #define SONIC_CDRRSYNC32(sc, x, ops)                                    \
  263         bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,               \
  264             SONIC_CDRROFF32((x)), sizeof(struct sonic_rra32), (ops))
  265 
  266 #define SONIC_CDCAMSYNC(sc, ops)                                        \
  267 do {                                                                    \
  268         if ((sc)->sc_32bit)                                             \
  269                 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,       \
  270                     SONIC_CDCAMOFF32, SONIC_CDCAMSIZE32,                \
  271                     (ops));                                             \
  272         else                                                            \
  273                 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,       \
  274                     SONIC_CDCAMOFF16, SONIC_CDCAMSIZE16,                \
  275                     (ops));                                             \
  276 } while (/*CONSTCOND*/0)
  277 
  278 #define SONIC_INIT_RXDESC(sc, x)                                        \
  279 do {                                                                    \
  280         struct sonic_descsoft *__ds = &(sc)->sc_rxsoft[(x)];            \
  281         struct mbuf *__m = __ds->ds_mbuf;                               \
  282                                                                         \
  283         if ((sc)->sc_32bit) {                                           \
  284                 /*                                                      \
  285                  * Unfortuantely, in 32-bit mode, the Rx buffer must    \
  286                  * be 32-bit aligned.                                   \
  287                  */                                                     \
  288                 struct sonic_rda32 *__rda = &(sc)->sc_rda32[(x)];       \
  289                 struct sonic_rda32 *__prda =                            \
  290                     &(sc)->sc_rda32[SONIC_PREVRX((x))];                 \
  291                 struct sonic_rra32 *__rra = &(sc)->sc_rra32[(x)];       \
  292                                                                         \
  293                 __m->m_data = __m->m_ext.ext_buf;                       \
  294                                                                         \
  295                 __rra->rra_ptr1 =                                       \
  296                     __ds->ds_dmamap->dm_segs[0].ds_addr >> 16;          \
  297                 __rra->rra_ptr0 =                                       \
  298                     __ds->ds_dmamap->dm_segs[0].ds_addr & 0xffff;       \
  299                 __rra->rra_wc1 = 0;                                     \
  300                 __rra->rra_wc0 = (ETHER_MAX_LEN + 6) / 2;               \
  301                                                                         \
  302                 __rda->rda_link =                                       \
  303                     (SONIC_CDRXADDR32((sc), SONIC_NEXTRX((x))) & 0xffff) |\
  304                     RDA_LINK_EOL;                                       \
  305                 __rda->rda_inuse = 1;                                   \
  306                                                                         \
  307                 __prda->rda_link = SONIC_CDRXADDR32((sc), (x));         \
  308                                                                         \
  309                 SONIC_CDRRSYNC32((sc), (x), BUS_DMASYNC_PREWRITE);      \
  310                 SONIC_CDRXSYNC32((sc), (x),                             \
  311                     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);          \
  312                 SONIC_CDRXSYNC32((sc), SONIC_PREVRX(x),                 \
  313                     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);          \
  314         } else {                                                        \
  315                 /*                                                      \
  316                  * In 16-bit mode, we scoot the packet forward 2 bytes  \
  317                  * so that the payload after the Ethernet header is     \
  318                  * suitably aligned.                                    \
  319                  */                                                     \
  320                 struct sonic_rda16 *__rda = &(sc)->sc_rda16[(x)];       \
  321                 struct sonic_rda16 *__prda =                            \
  322                     &(sc)->sc_rda16[SONIC_PREVRX((x))];                 \
  323                 struct sonic_rra16 *__rra = &(sc)->sc_rra16[(x)];       \
  324                                                                         \
  325                 __m->m_data = __m->m_ext.ext_buf + 2;                   \
  326                                                                         \
  327                 __rra->rra_ptr1 =                                       \
  328                     __ds->ds_dmamap->dm_segs[0].ds_addr >> 16;          \
  329                 __rra->rra_ptr0 =                                       \
  330                     (__ds->ds_dmamap->dm_segs[0].ds_addr + 2) & 0xffff; \
  331                 __rra->rra_wc1 = 0;                                     \
  332                 __rra->rra_wc0 = (ETHER_MAX_LEN + 2) / 2;               \
  333                                                                         \
  334                 __rda->rda_link =                                       \
  335                     (SONIC_CDRXADDR16((sc), SONIC_NEXTRX((x))) & 0xffff) |\
  336                     RDA_LINK_EOL;                                       \
  337                 __rda->rda_inuse = 1;                                   \
  338                                                                         \
  339                 __prda->rda_link = SONIC_CDRXADDR16((sc), (x));         \
  340                                                                         \
  341                 SONIC_CDRRSYNC16((sc), (x), BUS_DMASYNC_PREWRITE);      \
  342                 SONIC_CDRXSYNC16((sc), (x),                             \
  343                     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);          \
  344                 SONIC_CDRXSYNC16((sc), SONIC_PREVRX(x),                 \
  345                     BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);          \
  346         }                                                               \
  347 } while (/*CONSTCOND*/0)
  348 
  349 static __inline uint16_t __unused
  350 htosonic16(struct sonic_softc *sc, uint16_t val)
  351 {
  352 
  353         if (sc->sc_bigendian)
  354                 return (htobe16(val));
  355         return (htole16(val));
  356 }
  357 
  358 static __inline uint16_t __unused
  359 sonic16toh(struct sonic_softc *sc, uint16_t val)
  360 {
  361 
  362         if (sc->sc_bigendian)
  363                 return (be16toh(val));
  364         return (le16toh(val));
  365 }
  366 
  367 static __inline uint32_t __unused
  368 htosonic32(struct sonic_softc *sc, uint32_t val)
  369 {
  370 
  371         if (sc->sc_bigendian)
  372                 return (htobe32(val));
  373         return (htole32(val));
  374 }
  375 
  376 static __inline uint32_t __unused
  377 sonic32toh(struct sonic_softc *sc, uint32_t val)
  378 {
  379 
  380         if (sc->sc_bigendian)
  381                 return (be32toh(val));
  382         return (le32toh(val));
  383 }
  384 
  385 #ifdef _KERNEL
  386 void    sonic_attach(struct sonic_softc *, const uint8_t *);
  387 int     sonic_intr(void *);
  388 #endif /* _KERNEL */
  389 
  390 #endif /* _DEV_IC_DP83932VAR_H_ */

Cache object: 78e1865962bacee5f9ea11b5d85a3a54


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