2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #define VTE_TX_RING_CNT 64
36 #define VTE_TX_RING_ALIGN 16
38 * The TX/RX descriptor format has no limitation for number of
39 * descriptors in TX/RX ring. However, the maximum number of
40 * descriptors that could be set as RX descriptor ring residue
41 * counter is 255. This effectively limits number of RX
42 * descriptors available to be less than or equal to 255.
44 #define VTE_RX_RING_CNT 128
45 #define VTE_RX_RING_ALIGN 16
46 #define VTE_RX_BUF_ALIGN 4
48 #define VTE_DESC_INC(x, y) ((x) = ((x) + 1) % (y))
50 #define VTE_TX_RING_SZ \
51 (sizeof(struct vte_tx_desc) * VTE_TX_RING_CNT)
52 #define VTE_RX_RING_SZ \
53 (sizeof(struct vte_rx_desc) * VTE_RX_RING_CNT)
55 #define VTE_RX_BUF_SIZE_MAX (MCLBYTES - sizeof(uint32_t))
57 #define VTE_MIN_FRAMELEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
61 bus_dmamap_t rx_dmamap;
62 struct vte_rx_desc *rx_desc;
67 bus_dmamap_t tx_dmamap;
68 struct vte_tx_desc *tx_desc;
70 #define VTE_TXMBUF 0x0001
73 struct vte_chain_data {
74 bus_dma_tag_t vte_parent_tag;
75 bus_dma_tag_t vte_buffer_tag;
76 bus_dma_tag_t vte_tx_tag;
77 struct vte_txdesc vte_txdesc[VTE_TX_RING_CNT];
78 struct mbuf *vte_txmbufs[VTE_TX_RING_CNT];
79 bus_dma_tag_t vte_rx_tag;
80 struct vte_rxdesc vte_rxdesc[VTE_RX_RING_CNT];
81 bus_dma_tag_t vte_tx_ring_tag;
82 bus_dmamap_t vte_tx_ring_map;
83 bus_dma_tag_t vte_rx_ring_tag;
84 bus_dmamap_t vte_rx_ring_map;
85 bus_dmamap_t vte_rx_sparemap;
86 struct vte_tx_desc *vte_tx_ring;
87 bus_addr_t vte_tx_ring_paddr;
88 struct vte_rx_desc *vte_rx_ring;
89 bus_addr_t vte_rx_ring_paddr;
100 uint32_t rx_bcast_frames;
101 uint32_t rx_mcast_frames;
104 uint32_t rx_long_frames;
105 uint32_t rx_fifo_full;
106 uint32_t rx_desc_unavail;
107 uint32_t rx_pause_frames;
111 uint32_t tx_underruns;
112 uint32_t tx_late_colls;
113 uint32_t tx_pause_frames;
123 * Software state per device.
126 struct ifnet *vte_ifp;
129 struct resource *vte_res;
132 struct resource *vte_irq;
134 const struct vte_ident *vte_ident;
135 uint8_t vte_eaddr[ETHER_ADDR_LEN];
137 #define VTE_FLAG_LINK 0x8000
139 struct callout vte_tick_ch;
140 struct vte_hw_stats vte_stats;
141 struct vte_chain_data vte_cdata;
143 int vte_watchdog_timer;
150 /* Register access macros. */
151 #define CSR_WRITE_2(_sc, reg, val) \
152 bus_write_2((_sc)->vte_res, (reg), (val))
153 #define CSR_READ_2(_sc, reg) \
154 bus_read_2((_sc)->vte_res, (reg))
156 #define VTE_LOCK(_sc) mtx_lock(&(_sc)->vte_mtx)
157 #define VTE_UNLOCK(_sc) mtx_unlock(&(_sc)->vte_mtx)
158 #define VTE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->vte_mtx, MA_OWNED)
160 #define VTE_TX_TIMEOUT 5
161 #define VTE_RESET_TIMEOUT 100
162 #define VTE_TIMEOUT 1000
163 #define VTE_PHY_TIMEOUT 1000
165 #endif /* _IF_VTEVAR_H */