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/mge/if_mgevar.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 /*-
    2  * SPDX-License-Identifier: BSD-3-Clause
    3  *
    4  * Copyright (C) 2008 MARVELL INTERNATIONAL LTD.
    5  * All rights reserved.
    6  *
    7  * Developed by Semihalf.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. Neither the name of MARVELL nor the names of contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  * $FreeBSD$
   34  */
   35 
   36 #ifndef __IF_MGE_H__
   37 #define __IF_MGE_H__
   38 
   39 #include <arm/mv/mvvar.h>
   40 
   41 #define MGE_INTR_COUNT          5       /* ETH controller occupies 5 IRQ lines */
   42 #define MGE_TX_DESC_NUM         256
   43 #define MGE_RX_DESC_NUM         256
   44 #define MGE_RX_QUEUE_NUM        8
   45 #define MGE_RX_DEFAULT_QUEUE    0
   46 
   47 #define MGE_CHECKSUM_FEATURES   (CSUM_IP | CSUM_TCP | CSUM_UDP)
   48 
   49 /* Interrupt Coalescing types */
   50 #define MGE_IC_RX               0
   51 #define MGE_IC_TX               1
   52 
   53 struct mge_desc {
   54         uint32_t        cmd_status;
   55         uint16_t        buff_size;
   56         uint16_t        byte_count;
   57         bus_addr_t      buffer;
   58         bus_addr_t      next_desc;
   59 };
   60 
   61 struct mge_desc_wrapper {
   62         bus_dmamap_t            desc_dmap;
   63         struct mge_desc*        mge_desc;
   64         bus_addr_t              mge_desc_paddr;
   65         bus_dmamap_t            buffer_dmap;
   66         struct mbuf*            buffer;
   67 };
   68 
   69 struct mge_softc {
   70         struct ifnet    *ifp;           /* per-interface network data */
   71 
   72         phandle_t       node;
   73 
   74         device_t        dev;
   75         device_t        miibus;
   76 
   77         struct mii_data *mii;
   78         struct ifmedia  mge_ifmedia;
   79         struct resource *res[1 + MGE_INTR_COUNT];       /* resources */
   80         void            *ih_cookie[MGE_INTR_COUNT];     /* interrupt handlers cookies */
   81         struct mtx      transmit_lock;                  /* transmitter lock */
   82         struct mtx      receive_lock;                   /* receiver lock */
   83 
   84         uint32_t        mge_if_flags;
   85         uint32_t        mge_media_status;
   86 
   87         struct callout  wd_callout;
   88         int             wd_timer;
   89 
   90         bus_dma_tag_t   mge_desc_dtag;
   91         bus_dma_tag_t   mge_tx_dtag;
   92         bus_dma_tag_t   mge_rx_dtag;
   93         bus_addr_t      tx_desc_start;
   94         bus_addr_t      rx_desc_start;
   95         uint32_t        tx_desc_curr;
   96         uint32_t        rx_desc_curr;
   97         uint32_t        tx_desc_used_idx;
   98         uint32_t        tx_desc_used_count;
   99         uint32_t        rx_ic_time;
  100         uint32_t        tx_ic_time;
  101         struct mge_desc_wrapper mge_tx_desc[MGE_TX_DESC_NUM];
  102         struct mge_desc_wrapper mge_rx_desc[MGE_RX_DESC_NUM];
  103 
  104         uint32_t        mge_tfut_ipg_max;               /* TX FIFO Urgent Threshold */
  105         uint32_t        mge_rx_ipg_max;
  106         uint32_t        mge_tx_arb_cfg;
  107         uint32_t        mge_tx_tok_cfg;
  108         uint32_t        mge_tx_tok_cnt;
  109         uint16_t        mge_mtu;
  110         int             mge_ver;
  111         int             mge_intr_cnt;
  112         uint8_t         mge_hw_csum;
  113 
  114         int             phy_attached;
  115         int             switch_attached;
  116         struct mge_softc *phy_sc;
  117 };
  118 
  119 
  120 /* bus access macros */
  121 #define MGE_READ(sc,reg)        bus_read_4((sc)->res[0], (reg))
  122 #define MGE_WRITE(sc,reg,val)   bus_write_4((sc)->res[0], (reg), (val))
  123 
  124 /* Locking macros */
  125 #define MGE_TRANSMIT_LOCK(sc) do {                                              \
  126                         mtx_assert(&(sc)->receive_lock, MA_NOTOWNED);           \
  127                         mtx_lock(&(sc)->transmit_lock);                         \
  128 } while (0)
  129 
  130 #define MGE_TRANSMIT_UNLOCK(sc)         mtx_unlock(&(sc)->transmit_lock)
  131 #define MGE_TRANSMIT_LOCK_ASSERT(sc)    mtx_assert(&(sc)->transmit_lock, MA_OWNED)
  132 
  133 #define MGE_RECEIVE_LOCK(sc) do {                                               \
  134                         mtx_assert(&(sc)->transmit_lock, MA_NOTOWNED);          \
  135                         mtx_lock(&(sc)->receive_lock);                          \
  136 } while (0)
  137 
  138 #define MGE_RECEIVE_UNLOCK(sc)          mtx_unlock(&(sc)->receive_lock)
  139 #define MGE_RECEIVE_LOCK_ASSERT(sc)     mtx_assert(&(sc)->receive_lock, MA_OWNED)
  140 
  141 #define MGE_GLOBAL_LOCK(sc) do {                                                \
  142                         mtx_assert(&(sc)->transmit_lock, MA_NOTOWNED);          \
  143                         mtx_assert(&(sc)->receive_lock, MA_NOTOWNED);           \
  144                         mtx_lock(&(sc)->transmit_lock);                         \
  145                         mtx_lock(&(sc)->receive_lock);                          \
  146 } while (0)
  147 
  148 #define MGE_GLOBAL_UNLOCK(sc) do {                                              \
  149                         MGE_RECEIVE_UNLOCK(sc);                                 \
  150                         MGE_TRANSMIT_UNLOCK(sc);                                \
  151 } while (0)
  152 
  153 #define MGE_GLOBAL_LOCK_ASSERT(sc) do {                                         \
  154                         MGE_TRANSMIT_LOCK_ASSERT(sc);                           \
  155                         MGE_RECEIVE_LOCK_ASSERT(sc);                            \
  156 } while (0)
  157 
  158 #define MGE_SMI_LOCK() do {                             \
  159     sx_assert(&sx_smi, SA_UNLOCKED);                    \
  160     sx_xlock(&sx_smi);                                  \
  161 } while (0)
  162 
  163 #define MGE_SMI_UNLOCK()                sx_unlock(&sx_smi)
  164 #define MGE_SMI_LOCK_ASSERT()           sx_assert(&sx_smi, SA_XLOCKED)
  165 
  166 /* SMI-related macros */
  167 #define MGE_REG_PHYDEV          0x000
  168 #define MGE_REG_SMI             0x004
  169 #define MGE_SMI_READ            (1 << 26)
  170 #define MGE_SMI_WRITE           (0 << 26)
  171 #define MGE_SMI_READVALID       (1 << 27)
  172 #define MGE_SMI_BUSY            (1 << 28)
  173 
  174 #define MGE_SMI_MASK            0x1fffffff
  175 #define MGE_SMI_DATA_MASK       0xffff
  176 #define MGE_SMI_DELAY           1000
  177 
  178 #define MGE_SWITCH_PHYDEV       6
  179 
  180 /* Internal Switch SMI Command */
  181 
  182 #define SW_SMI_READ_CMD(phy, reg)               ((1 << 15) | (1 << 12) | (1 << 11) | (phy << 5) | reg)
  183 #define SW_SMI_WRITE_CMD(phy, reg)              ((1 << 15) | (1 << 12) | (1 << 10) | (phy << 5) | reg)
  184 
  185 /* TODO verify the timings and retries count w/specs */
  186 #define MGE_SMI_READ_RETRIES            1000
  187 #define MGE_SMI_READ_DELAY              100
  188 #define MGE_SMI_WRITE_RETRIES           1000
  189 #define MGE_SMI_WRITE_DELAY             100
  190 
  191 /* MGE registers */
  192 #define MGE_INT_CAUSE           0x080
  193 #define MGE_INT_MASK            0x084
  194 
  195 #define MGE_PORT_CONFIG                 0x400
  196 #define PORT_CONFIG_UPM                 (1 << 0)                /* promiscuous */
  197 #define PORT_CONFIG_DFLT_RXQ(val)       (((val) & 7) << 1)      /* default RX queue */
  198 #define PORT_CONFIG_ARO_RXQ(val)        (((val) & 7) << 4)      /* ARP RX queue */
  199 #define PORT_CONFIG_REJECT_BCAST        (1 << 7) /* reject non-ip and non-arp bcast */
  200 #define PORT_CONFIG_REJECT_IP_BCAST     (1 << 8) /* reject ip bcast */
  201 #define PORT_CONFIG_REJECT_ARP__BCAST   (1 << 9) /* reject arp bcast */
  202 #define PORT_CONFIG_AMNoTxES            (1 << 12) /* Automatic mode not updating Error Summary in Tx descriptor */
  203 #define PORT_CONFIG_TCP_CAP             (1 << 14) /* capture tcp to a different queue */
  204 #define PORT_CONFIG_UDP_CAP             (1 << 15) /* capture udp to a different queue */
  205 #define PORT_CONFIG_TCPQ                (7 << 16) /* queue to capture tcp */
  206 #define PORT_CONFIG_UDPQ                (7 << 19) /* queue to capture udp */
  207 #define PORT_CONFIG_BPDUQ               (7 << 22) /* queue to capture bpdu */
  208 #define PORT_CONFIG_RXCS                (1 << 25) /* calculation Rx TCP checksum include pseudo header */
  209 
  210 #define MGE_PORT_EXT_CONFIG     0x404
  211 #define MGE_MAC_ADDR_L          0x414
  212 #define MGE_MAC_ADDR_H          0x418
  213 
  214 #define MGE_SDMA_CONFIG                 0x41c
  215 #define MGE_SDMA_INT_ON_FRAME_BOUND     (1 << 0)
  216 #define MGE_SDMA_RX_BURST_SIZE(val)     (((val) & 7) << 1)
  217 #define MGE_SDMA_TX_BURST_SIZE(val)     (((val) & 7) << 22)
  218 #define MGE_SDMA_BURST_1_WORD           0x0
  219 #define MGE_SDMA_BURST_2_WORD           0x1
  220 #define MGE_SDMA_BURST_4_WORD           0x2
  221 #define MGE_SDMA_BURST_8_WORD           0x3
  222 #define MGE_SDMA_BURST_16_WORD          0x4
  223 #define MGE_SDMA_RX_BYTE_SWAP           (1 << 4)
  224 #define MGE_SDMA_TX_BYTE_SWAP           (1 << 5)
  225 #define MGE_SDMA_DESC_SWAP_MODE         (1 << 6)
  226 
  227 #define MGE_PORT_SERIAL_CTRL            0x43c
  228 #define PORT_SERIAL_ENABLE              (1 << 0) /* serial port enable */
  229 #define PORT_SERIAL_FORCE_LINKUP        (1 << 1) /* force link status to up */
  230 #define PORT_SERIAL_AUTONEG             (1 << 2) /* enable autoneg for duplex mode */
  231 #define PORT_SERIAL_AUTONEG_FC          (1 << 3) /* enable autoneg for FC */
  232 #define PORT_SERIAL_PAUSE_ADV           (1 << 4) /* advertise symmetric FC in autoneg */
  233 #define PORT_SERIAL_FORCE_FC(val)       (((val) & 3) << 5) /* pause enable & disable frames conf */
  234 #define PORT_SERIAL_NO_PAUSE_DIS        0x00
  235 #define PORT_SERIAL_PAUSE_DIS           0x01
  236 #define PORT_SERIAL_FORCE_BP(val)       (((val) & 3) << 7) /* transmitting JAM configuration */
  237 #define PORT_SERIAL_NO_JAM              0x00
  238 #define PORT_SERIAL_JAM                 0x01
  239 #define PORT_SERIAL_RES_BIT9            (1 << 9)
  240 #define PORT_SERIAL_FORCE_LINK_FAIL     (1 << 10)
  241 #define PORT_SERIAL_SPEED_AUTONEG       (1 << 13)
  242 #define PORT_SERIAL_FORCE_DTE_ADV       (1 << 14)
  243 #define PORT_SERIAL_MRU(val)            (((val) & 7) << 17)
  244 #define PORT_SERIAL_MRU_1518            0x0
  245 #define PORT_SERIAL_MRU_1522            0x1
  246 #define PORT_SERIAL_MRU_1552            0x2
  247 #define PORT_SERIAL_MRU_9022            0x3
  248 #define PORT_SERIAL_MRU_9192            0x4
  249 #define PORT_SERIAL_MRU_9700            0x5
  250 #define PORT_SERIAL_FULL_DUPLEX         (1 << 21)
  251 #define PORT_SERIAL_FULL_DUPLEX_FC      (1 << 22)
  252 #define PORT_SERIAL_GMII_SPEED_1000     (1 << 23)
  253 #define PORT_SERIAL_MII_SPEED_100       (1 << 24)
  254 
  255 #define MGE_PORT_STATUS                 0x444
  256 #define MGE_STATUS_LINKUP               (1 << 1)
  257 #define MGE_STATUS_FULL_DUPLEX          (1 << 2)
  258 #define MGE_STATUS_FLOW_CONTROL         (1 << 3)
  259 #define MGE_STATUS_1000MB               (1 << 4)
  260 #define MGE_STATUS_100MB                (1 << 5)
  261 #define MGE_STATUS_TX_IN_PROG           (1 << 7)
  262 #define MGE_STATUS_TX_FIFO_EMPTY        (1 << 10)
  263 
  264 #define MGE_TX_QUEUE_CMD        0x448
  265 #define MGE_ENABLE_TXQ          (1 << 0)
  266 #define MGE_DISABLE_TXQ         (1 << 8)
  267 
  268 /* 88F6281 only */
  269 #define MGE_PORT_SERIAL_CTRL1           0x44c
  270 #define MGE_PCS_LOOPBACK                (1 << 1)
  271 #define MGE_RGMII_EN                    (1 << 3)
  272 #define MGE_PORT_RESET                  (1 << 4)
  273 #define MGE_CLK125_BYPASS               (1 << 5)
  274 #define MGE_INBAND_AUTONEG              (1 << 6)
  275 #define MGE_INBAND_AUTONEG_BYPASS       (1 << 6)
  276 #define MGE_INBAND_AUTONEG_RESTART      (1 << 7)
  277 #define MGE_1000BASEX                   (1 << 11)
  278 #define MGE_BP_COLLISION_COUNT          (1 << 15)
  279 #define MGE_COLLISION_LIMIT(val)        (((val) & 0x3f) << 16)
  280 #define MGE_DROP_ODD_PREAMBLE           (1 << 22)
  281 
  282 #define MGE_PORT_INT_CAUSE      0x460
  283 #define MGE_PORT_INT_MASK       0x468
  284 #define MGE_PORT_INT_RX         (1 << 0)
  285 #define MGE_PORT_INT_EXTEND     (1 << 1)
  286 #define MGE_PORT_INT_RXQ0       (1 << 2)
  287 #define MGE_PORT_INT_RXERR      (1 << 10)
  288 #define MGE_PORT_INT_RXERRQ0    (1 << 11)
  289 #define MGE_PORT_INT_SUM        (1U << 31)
  290 
  291 #define MGE_PORT_INT_CAUSE_EXT  0x464
  292 #define MGE_PORT_INT_MASK_EXT   0x46C
  293 #define MGE_PORT_INT_EXT_TXBUF0 (1 << 0)
  294 #define MGE_PORT_INT_EXT_TXERR0 (1 << 8)
  295 #define MGE_PORT_INT_EXT_PHYSC  (1 << 16)
  296 #define MGE_PORT_INT_EXT_RXOR   (1 << 18)
  297 #define MGE_PORT_INT_EXT_TXUR   (1 << 19)
  298 #define MGE_PORT_INT_EXT_LC     (1 << 20)
  299 #define MGE_PORT_INT_EXT_IAR    (1 << 23)
  300 #define MGE_PORT_INT_EXT_SUM    (1U << 31)
  301 
  302 #define MGE_RX_FIFO_URGENT_TRSH         0x470
  303 #define MGE_TX_FIFO_URGENT_TRSH         0x474
  304 
  305 #define MGE_FIXED_PRIO_CONF             0x4dc
  306 #define MGE_FIXED_PRIO_EN(q)            (1 << (q))
  307 
  308 #define MGE_RX_CUR_DESC_PTR(q)          (0x60c + ((q)<<4))
  309 
  310 #define MGE_RX_QUEUE_CMD                0x680
  311 #define MGE_ENABLE_RXQ(q)               (1 << ((q) & 0x7))
  312 #define MGE_ENABLE_RXQ_ALL              (0xff)
  313 #define MGE_DISABLE_RXQ(q)              (1 << (((q) & 0x7) + 8))
  314 #define MGE_DISABLE_RXQ_ALL             (0xff00)
  315 
  316 #define MGE_TX_CUR_DESC_PTR             0x6c0
  317 
  318 #define MGE_TX_TOKEN_COUNT(q)           (0x700 + ((q)<<4))
  319 #define MGE_TX_TOKEN_CONF(q)            (0x704 + ((q)<<4))
  320 #define MGE_TX_ARBITER_CONF(q)          (0x704 + ((q)<<4))
  321 
  322 #define MGE_MCAST_REG_NUMBER            64
  323 #define MGE_DA_FILTER_SPEC_MCAST(i)     (0x1400 + ((i) << 2))
  324 #define MGE_DA_FILTER_OTH_MCAST(i)      (0x1500 + ((i) << 2))
  325 
  326 #define MGE_UCAST_REG_NUMBER            4
  327 #define MGE_DA_FILTER_UCAST(i)          (0x1600 + ((i) << 2))
  328         
  329 
  330 /* TX descriptor bits */
  331 #define MGE_TX_LLC_SNAP         (1 << 9)
  332 #define MGE_TX_NOT_FRAGMENT     (1 << 10)
  333 #define MGE_TX_VLAN_TAGGED      (1 << 15)
  334 #define MGE_TX_UDP              (1 << 16)
  335 #define MGE_TX_GEN_L4_CSUM      (1 << 17)
  336 #define MGE_TX_GEN_IP_CSUM      (1 << 18)
  337 #define MGE_TX_PADDING          (1 << 19)
  338 #define MGE_TX_LAST             (1 << 20)
  339 #define MGE_TX_FIRST            (1 << 21)
  340 #define MGE_TX_ETH_CRC          (1 << 22)
  341 #define MGE_TX_EN_INT           (1 << 23)
  342 
  343 #define MGE_TX_IP_HDR_SIZE(size)        ((size << 11) & 0xFFFF)
  344 
  345 /* RX descriptor bits */
  346 #define MGE_ERR_SUMMARY         (1 << 0)
  347 #define MGE_ERR_MASK            (3 << 1)
  348 #define MGE_RX_L4_PROTO_MASK    (3 << 21)
  349 #define MGE_RX_L4_PROTO_TCP     (0 << 21)
  350 #define MGE_RX_L4_PROTO_UDP     (1 << 21)
  351 #define MGE_RX_L3_IS_IP         (1 << 24)
  352 #define MGE_RX_IP_OK            (1 << 25)
  353 #define MGE_RX_DESC_LAST        (1 << 26)
  354 #define MGE_RX_DESC_FIRST       (1 << 27)
  355 #define MGE_RX_ENABLE_INT       (1 << 29)
  356 #define MGE_RX_L4_CSUM_OK       (1 << 30)
  357 #define MGE_DMA_OWNED           (1U << 31)
  358 
  359 #define MGE_RX_IP_FRAGMENT      (1 << 2)
  360 
  361 #define MGE_RX_L4_IS_TCP(status)        ((status & MGE_RX_L4_PROTO_MASK) \
  362                                             == MGE_RX_L4_PROTO_TCP)
  363 
  364 #define MGE_RX_L4_IS_UDP(status)        ((status & MGE_RX_L4_PROTO_MASK) \
  365                                             == MGE_RX_L4_PROTO_UDP)
  366 
  367 /* TX error codes */
  368 #define MGE_TX_ERROR_LC         (0 << 1)        /* Late collision */
  369 #define MGE_TX_ERROR_UR         (1 << 1)        /* Underrun error */
  370 #define MGE_TX_ERROR_RL         (2 << 1)        /* Excessive collision */
  371 
  372 /* RX error codes */
  373 #define MGE_RX_ERROR_CE         (0 << 1)        /* CRC error */
  374 #define MGE_RX_ERROR_OR         (1 << 1)        /* Overrun error */
  375 #define MGE_RX_ERROR_MF         (2 << 1)        /* Max frame length error */
  376 #define MGE_RX_ERROR_RE         (3 << 1)        /* Resource error */
  377 
  378 #endif /* __IF_MGE_H__ */

Cache object: 5c4f9b09a79bcfd1896e413e4d99ad70


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