12608aefcSPyun YongHyeon /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 42608aefcSPyun YongHyeon * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org> 52608aefcSPyun YongHyeon * All rights reserved. 62608aefcSPyun YongHyeon * 72608aefcSPyun YongHyeon * Redistribution and use in source and binary forms, with or without 82608aefcSPyun YongHyeon * modification, are permitted provided that the following conditions 92608aefcSPyun YongHyeon * are met: 102608aefcSPyun YongHyeon * 1. Redistributions of source code must retain the above copyright 112608aefcSPyun YongHyeon * notice unmodified, this list of conditions, and the following 122608aefcSPyun YongHyeon * disclaimer. 132608aefcSPyun YongHyeon * 2. Redistributions in binary form must reproduce the above copyright 142608aefcSPyun YongHyeon * notice, this list of conditions and the following disclaimer in the 152608aefcSPyun YongHyeon * documentation and/or other materials provided with the distribution. 162608aefcSPyun YongHyeon * 172608aefcSPyun YongHyeon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 182608aefcSPyun YongHyeon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 192608aefcSPyun YongHyeon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 202608aefcSPyun YongHyeon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 212608aefcSPyun YongHyeon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 222608aefcSPyun YongHyeon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 232608aefcSPyun YongHyeon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 242608aefcSPyun YongHyeon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 252608aefcSPyun YongHyeon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 262608aefcSPyun YongHyeon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 272608aefcSPyun YongHyeon * SUCH DAMAGE. 282608aefcSPyun YongHyeon */ 292608aefcSPyun YongHyeon 302608aefcSPyun YongHyeon #ifndef _IF_VTEVAR_H 312608aefcSPyun YongHyeon #define _IF_VTEVAR_H 322608aefcSPyun YongHyeon 332608aefcSPyun YongHyeon #define VTE_TX_RING_CNT 64 342608aefcSPyun YongHyeon #define VTE_TX_RING_ALIGN 16 352608aefcSPyun YongHyeon /* 362608aefcSPyun YongHyeon * The TX/RX descriptor format has no limitation for number of 372608aefcSPyun YongHyeon * descriptors in TX/RX ring. However, the maximum number of 382608aefcSPyun YongHyeon * descriptors that could be set as RX descriptor ring residue 392608aefcSPyun YongHyeon * counter is 255. This effectively limits number of RX 402608aefcSPyun YongHyeon * descriptors available to be less than or equal to 255. 412608aefcSPyun YongHyeon */ 422608aefcSPyun YongHyeon #define VTE_RX_RING_CNT 128 432608aefcSPyun YongHyeon #define VTE_RX_RING_ALIGN 16 442608aefcSPyun YongHyeon #define VTE_RX_BUF_ALIGN 4 452608aefcSPyun YongHyeon 462608aefcSPyun YongHyeon #define VTE_DESC_INC(x, y) ((x) = ((x) + 1) % (y)) 472608aefcSPyun YongHyeon 482608aefcSPyun YongHyeon #define VTE_TX_RING_SZ \ 492608aefcSPyun YongHyeon (sizeof(struct vte_tx_desc) * VTE_TX_RING_CNT) 502608aefcSPyun YongHyeon #define VTE_RX_RING_SZ \ 512608aefcSPyun YongHyeon (sizeof(struct vte_rx_desc) * VTE_RX_RING_CNT) 522608aefcSPyun YongHyeon 532608aefcSPyun YongHyeon #define VTE_RX_BUF_SIZE_MAX (MCLBYTES - sizeof(uint32_t)) 542608aefcSPyun YongHyeon 552608aefcSPyun YongHyeon #define VTE_MIN_FRAMELEN (ETHER_MIN_LEN - ETHER_CRC_LEN) 562608aefcSPyun YongHyeon 572608aefcSPyun YongHyeon struct vte_rxdesc { 582608aefcSPyun YongHyeon struct mbuf *rx_m; 592608aefcSPyun YongHyeon bus_dmamap_t rx_dmamap; 602608aefcSPyun YongHyeon struct vte_rx_desc *rx_desc; 612608aefcSPyun YongHyeon }; 622608aefcSPyun YongHyeon 632608aefcSPyun YongHyeon struct vte_txdesc { 642608aefcSPyun YongHyeon struct mbuf *tx_m; 652608aefcSPyun YongHyeon bus_dmamap_t tx_dmamap; 662608aefcSPyun YongHyeon struct vte_tx_desc *tx_desc; 672608aefcSPyun YongHyeon int tx_flags; 682608aefcSPyun YongHyeon #define VTE_TXMBUF 0x0001 692608aefcSPyun YongHyeon }; 702608aefcSPyun YongHyeon 712608aefcSPyun YongHyeon struct vte_chain_data { 722608aefcSPyun YongHyeon bus_dma_tag_t vte_parent_tag; 732608aefcSPyun YongHyeon bus_dma_tag_t vte_buffer_tag; 742608aefcSPyun YongHyeon bus_dma_tag_t vte_tx_tag; 752608aefcSPyun YongHyeon struct vte_txdesc vte_txdesc[VTE_TX_RING_CNT]; 762608aefcSPyun YongHyeon struct mbuf *vte_txmbufs[VTE_TX_RING_CNT]; 772608aefcSPyun YongHyeon bus_dma_tag_t vte_rx_tag; 782608aefcSPyun YongHyeon struct vte_rxdesc vte_rxdesc[VTE_RX_RING_CNT]; 792608aefcSPyun YongHyeon bus_dma_tag_t vte_tx_ring_tag; 802608aefcSPyun YongHyeon bus_dmamap_t vte_tx_ring_map; 812608aefcSPyun YongHyeon bus_dma_tag_t vte_rx_ring_tag; 822608aefcSPyun YongHyeon bus_dmamap_t vte_rx_ring_map; 832608aefcSPyun YongHyeon bus_dmamap_t vte_rx_sparemap; 842608aefcSPyun YongHyeon struct vte_tx_desc *vte_tx_ring; 852608aefcSPyun YongHyeon bus_addr_t vte_tx_ring_paddr; 862608aefcSPyun YongHyeon struct vte_rx_desc *vte_rx_ring; 872608aefcSPyun YongHyeon bus_addr_t vte_rx_ring_paddr; 882608aefcSPyun YongHyeon 892608aefcSPyun YongHyeon int vte_tx_prod; 902608aefcSPyun YongHyeon int vte_tx_cons; 912608aefcSPyun YongHyeon int vte_tx_cnt; 922608aefcSPyun YongHyeon int vte_rx_cons; 932608aefcSPyun YongHyeon }; 942608aefcSPyun YongHyeon 952608aefcSPyun YongHyeon struct vte_hw_stats { 962608aefcSPyun YongHyeon /* RX stats. */ 972608aefcSPyun YongHyeon uint32_t rx_frames; 982608aefcSPyun YongHyeon uint32_t rx_bcast_frames; 992608aefcSPyun YongHyeon uint32_t rx_mcast_frames; 1002608aefcSPyun YongHyeon uint32_t rx_runts; 1012608aefcSPyun YongHyeon uint32_t rx_crcerrs; 1022608aefcSPyun YongHyeon uint32_t rx_long_frames; 1032608aefcSPyun YongHyeon uint32_t rx_fifo_full; 1042608aefcSPyun YongHyeon uint32_t rx_desc_unavail; 1052608aefcSPyun YongHyeon uint32_t rx_pause_frames; 1062608aefcSPyun YongHyeon 1072608aefcSPyun YongHyeon /* TX stats. */ 1082608aefcSPyun YongHyeon uint32_t tx_frames; 1092608aefcSPyun YongHyeon uint32_t tx_underruns; 1102608aefcSPyun YongHyeon uint32_t tx_late_colls; 1112608aefcSPyun YongHyeon uint32_t tx_pause_frames; 1122608aefcSPyun YongHyeon }; 1132608aefcSPyun YongHyeon 1142608aefcSPyun YongHyeon struct vte_ident { 1152608aefcSPyun YongHyeon uint16_t vendorid; 1162608aefcSPyun YongHyeon uint16_t deviceid; 1172608aefcSPyun YongHyeon const char *name; 1182608aefcSPyun YongHyeon }; 1192608aefcSPyun YongHyeon 1202608aefcSPyun YongHyeon /* 1212608aefcSPyun YongHyeon * Software state per device. 1222608aefcSPyun YongHyeon */ 1232608aefcSPyun YongHyeon struct vte_softc { 1243486b835SJustin Hibbits if_t vte_ifp; 1252608aefcSPyun YongHyeon device_t vte_dev; 1262608aefcSPyun YongHyeon device_t vte_miibus; 1272608aefcSPyun YongHyeon struct resource *vte_res; 1282608aefcSPyun YongHyeon int vte_res_id; 1292608aefcSPyun YongHyeon int vte_res_type; 1302608aefcSPyun YongHyeon struct resource *vte_irq; 1312608aefcSPyun YongHyeon void *vte_intrhand; 1322608aefcSPyun YongHyeon const struct vte_ident *vte_ident; 1332608aefcSPyun YongHyeon uint8_t vte_eaddr[ETHER_ADDR_LEN]; 1342608aefcSPyun YongHyeon int vte_flags; 1352608aefcSPyun YongHyeon #define VTE_FLAG_LINK 0x8000 1362608aefcSPyun YongHyeon 1372608aefcSPyun YongHyeon struct callout vte_tick_ch; 1382608aefcSPyun YongHyeon struct vte_hw_stats vte_stats; 1392608aefcSPyun YongHyeon struct vte_chain_data vte_cdata; 1402608aefcSPyun YongHyeon int vte_if_flags; 1412608aefcSPyun YongHyeon int vte_watchdog_timer; 1422608aefcSPyun YongHyeon int vte_int_rx_mod; 1432608aefcSPyun YongHyeon int vte_int_tx_mod; 1442608aefcSPyun YongHyeon 1452608aefcSPyun YongHyeon struct mtx vte_mtx; 1462608aefcSPyun YongHyeon }; 1472608aefcSPyun YongHyeon 1482608aefcSPyun YongHyeon /* Register access macros. */ 1492608aefcSPyun YongHyeon #define CSR_WRITE_2(_sc, reg, val) \ 1502608aefcSPyun YongHyeon bus_write_2((_sc)->vte_res, (reg), (val)) 1512608aefcSPyun YongHyeon #define CSR_READ_2(_sc, reg) \ 1522608aefcSPyun YongHyeon bus_read_2((_sc)->vte_res, (reg)) 1532608aefcSPyun YongHyeon 1542608aefcSPyun YongHyeon #define VTE_LOCK(_sc) mtx_lock(&(_sc)->vte_mtx) 1552608aefcSPyun YongHyeon #define VTE_UNLOCK(_sc) mtx_unlock(&(_sc)->vte_mtx) 1562608aefcSPyun YongHyeon #define VTE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->vte_mtx, MA_OWNED) 1572608aefcSPyun YongHyeon 1582608aefcSPyun YongHyeon #define VTE_TX_TIMEOUT 5 1592608aefcSPyun YongHyeon #define VTE_RESET_TIMEOUT 100 1602608aefcSPyun YongHyeon #define VTE_TIMEOUT 1000 1612608aefcSPyun YongHyeon #define VTE_PHY_TIMEOUT 1000 1622608aefcSPyun YongHyeon 1632608aefcSPyun YongHyeon #endif /* _IF_VTEVAR_H */ 164