xref: /freebsd/sys/dev/vte/if_vtevar.h (revision 050570efa79efcc9cf5adeb545f1a679c8dc377b)
1 /*-
2  * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef	_IF_VTEVAR_H
31 #define	_IF_VTEVAR_H
32 
33 #define	VTE_TX_RING_CNT		64
34 #define	VTE_TX_RING_ALIGN	16
35 /*
36  * The TX/RX descriptor format has no limitation for number of
37  * descriptors in TX/RX ring.  However, the maximum number of
38  * descriptors that could be set as RX descriptor ring residue
39  * counter is 255.  This effectively limits number of RX
40  * descriptors available to be less than or equal to 255.
41  */
42 #define	VTE_RX_RING_CNT		128
43 #define	VTE_RX_RING_ALIGN	16
44 #define	VTE_RX_BUF_ALIGN	4
45 
46 #define	VTE_DESC_INC(x, y)	((x) = ((x) + 1) % (y))
47 
48 #define	VTE_TX_RING_SZ		\
49 	(sizeof(struct vte_tx_desc) * VTE_TX_RING_CNT)
50 #define	VTE_RX_RING_SZ		\
51 	(sizeof(struct vte_rx_desc) * VTE_RX_RING_CNT)
52 
53 #define	VTE_RX_BUF_SIZE_MAX	(MCLBYTES - sizeof(uint32_t))
54 
55 #define	VTE_MIN_FRAMELEN	(ETHER_MIN_LEN - ETHER_CRC_LEN)
56 
57 struct vte_rxdesc {
58 	struct mbuf		*rx_m;
59 	bus_dmamap_t		rx_dmamap;
60 	struct vte_rx_desc	*rx_desc;
61 };
62 
63 struct vte_txdesc {
64 	struct mbuf		*tx_m;
65 	bus_dmamap_t		tx_dmamap;
66 	struct vte_tx_desc	*tx_desc;
67 	int			tx_flags;
68 #define	VTE_TXMBUF		0x0001
69 };
70 
71 struct vte_chain_data {
72 	bus_dma_tag_t		vte_parent_tag;
73 	bus_dma_tag_t		vte_buffer_tag;
74 	bus_dma_tag_t		vte_tx_tag;
75 	struct vte_txdesc	vte_txdesc[VTE_TX_RING_CNT];
76 	struct mbuf		*vte_txmbufs[VTE_TX_RING_CNT];
77 	bus_dma_tag_t		vte_rx_tag;
78 	struct vte_rxdesc	vte_rxdesc[VTE_RX_RING_CNT];
79 	bus_dma_tag_t		vte_tx_ring_tag;
80 	bus_dmamap_t		vte_tx_ring_map;
81 	bus_dma_tag_t		vte_rx_ring_tag;
82 	bus_dmamap_t		vte_rx_ring_map;
83 	bus_dma_tag_t		vte_rr_ring_tag;
84 	bus_dmamap_t		vte_rr_ring_map;
85 	bus_dmamap_t		vte_rx_sparemap;
86 	bus_dma_tag_t		vte_cmb_tag;
87 	bus_dmamap_t		vte_cmb_map;
88 	bus_dma_tag_t		vte_smb_tag;
89 	bus_dmamap_t		vte_smb_map;
90 	struct vte_tx_desc	*vte_tx_ring;
91 	bus_addr_t		vte_tx_ring_paddr;
92 	struct vte_rx_desc	*vte_rx_ring;
93 	bus_addr_t		vte_rx_ring_paddr;
94 
95 	int			vte_tx_prod;
96 	int			vte_tx_cons;
97 	int			vte_tx_cnt;
98 	int			vte_rx_cons;
99 };
100 
101 struct vte_hw_stats {
102 	/* RX stats. */
103 	uint32_t rx_frames;
104 	uint32_t rx_bcast_frames;
105 	uint32_t rx_mcast_frames;
106 	uint32_t rx_runts;
107 	uint32_t rx_crcerrs;
108 	uint32_t rx_long_frames;
109 	uint32_t rx_fifo_full;
110 	uint32_t rx_desc_unavail;
111 	uint32_t rx_pause_frames;
112 
113 	/* TX stats. */
114 	uint32_t tx_frames;
115 	uint32_t tx_underruns;
116 	uint32_t tx_late_colls;
117 	uint32_t tx_pause_frames;
118 };
119 
120 struct vte_ident {
121 	uint16_t	vendorid;
122 	uint16_t	deviceid;
123 	const char	*name;
124 };
125 
126 /*
127  * Software state per device.
128  */
129 struct vte_softc {
130 	struct ifnet 		*vte_ifp;
131 	device_t		vte_dev;
132 	device_t		vte_miibus;
133 	struct resource		*vte_res;
134 	int			vte_res_id;
135 	int			vte_res_type;
136 	struct resource		*vte_irq;
137 	void			*vte_intrhand;
138 	const struct vte_ident	*vte_ident;
139 	uint8_t			vte_eaddr[ETHER_ADDR_LEN];
140 	int			vte_flags;
141 #define	VTE_FLAG_LINK		0x8000
142 
143 	struct callout		vte_tick_ch;
144 	struct vte_hw_stats	vte_stats;
145 	struct vte_chain_data	vte_cdata;
146 	int			vte_if_flags;
147 	int			vte_watchdog_timer;
148 	int			vte_int_rx_mod;
149 	int			vte_int_tx_mod;
150 
151 	struct mtx		vte_mtx;
152 };
153 
154 /* Register access macros. */
155 #define	CSR_WRITE_2(_sc, reg, val)	\
156 	bus_write_2((_sc)->vte_res, (reg), (val))
157 #define	CSR_READ_2(_sc, reg)		\
158 	bus_read_2((_sc)->vte_res, (reg))
159 
160 #define	VTE_LOCK(_sc)		mtx_lock(&(_sc)->vte_mtx)
161 #define	VTE_UNLOCK(_sc)		mtx_unlock(&(_sc)->vte_mtx)
162 #define	VTE_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->vte_mtx, MA_OWNED)
163 
164 #define	VTE_TX_TIMEOUT		5
165 #define	VTE_RESET_TIMEOUT	100
166 #define	VTE_TIMEOUT		1000
167 #define	VTE_PHY_TIMEOUT		1000
168 
169 #endif	/* _IF_VTEVAR_H */
170