xref: /netbsd-src/sys/dev/pci/if_vtevar.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: if_vtevar.h,v 1.4 2015/04/14 20:32:36 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010, Pyun YongHyeon <yongari@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  * FreeBSD: src/sys/dev/vte/if_vtevar.h,v 1.1 2010/12/31 00:21:41 yongari Exp
30  */
31 
32 #ifndef	_IF_VTEVAR_H
33 #define	_IF_VTEVAR_H
34 
35 #include <sys/rndsource.h>
36 
37 #define	VTE_TX_RING_CNT		64
38 #define	VTE_TX_RING_ALIGN	16
39 /*
40  * The TX/RX descriptor format has no limitation for number of
41  * descriptors in TX/RX ring.  However, the maximum number of
42  * descriptors that could be set as RX descriptor ring residue
43  * counter is 255.  This effectively limits number of RX
44  * descriptors available to be less than or equal to 255.
45  */
46 #define	VTE_RX_RING_CNT		128
47 #define	VTE_RX_RING_ALIGN	16
48 #define	VTE_RX_BUF_ALIGN	4
49 
50 #define	VTE_DESC_INC(x, y)	((x) = ((x) + 1) % (y))
51 
52 #define	VTE_TX_RING_SZ		\
53 	(sizeof(struct vte_tx_desc) * VTE_TX_RING_CNT)
54 #define	VTE_RX_RING_SZ		\
55 	(sizeof(struct vte_rx_desc) * VTE_RX_RING_CNT)
56 
57 #define	VTE_RX_BUF_SIZE_MAX	(MCLBYTES - sizeof(uint32_t))
58 
59 #define	VTE_MIN_FRAMELEN	(ETHER_MIN_LEN - ETHER_CRC_LEN)
60 
61 struct vte_rxdesc {
62 	struct mbuf		*rx_m;
63 	bus_dma_segment_t	rx_seg;
64 	bus_dmamap_t		rx_dmamap;
65 	struct vte_rx_desc	*rx_desc;
66 };
67 
68 struct vte_txdesc {
69 	struct mbuf		*tx_m;
70 	bus_dma_segment_t	*tx_seg;
71 	bus_dmamap_t		tx_dmamap;
72 	struct vte_tx_desc	*tx_desc;
73 	int			tx_flags;
74 #define	VTE_TXMBUF		0x0001
75 };
76 
77 struct vte_chain_data {
78 	struct vte_txdesc	vte_txdesc[VTE_TX_RING_CNT];
79 	struct mbuf		*vte_txmbufs[VTE_TX_RING_CNT];
80 	struct vte_rxdesc	vte_rxdesc[VTE_RX_RING_CNT];
81 	bus_dmamap_t		vte_tx_ring_map;
82 	bus_dma_segment_t	vte_tx_ring_seg[1];
83 	bus_dmamap_t		vte_rx_ring_map;
84 	bus_dma_segment_t	vte_rx_ring_seg[1];
85 	bus_dmamap_t		vte_rr_ring_map;
86 	bus_dma_segment_t	vte_rr_ring_seg[1];
87 	bus_dmamap_t		vte_rx_sparemap;
88 	bus_dmamap_t		vte_cmb_map;
89 	bus_dmamap_t		vte_smb_map;
90 	struct vte_tx_desc	*vte_tx_ring;
91 	struct vte_rx_desc	*vte_rx_ring;
92 
93 	int			vte_tx_prod;
94 	int			vte_tx_cons;
95 	int			vte_tx_cnt;
96 	int			vte_rx_cons;
97 };
98 
99 struct vte_hw_stats {
100 	/* RX stats. */
101 	uint32_t rx_frames;
102 	uint32_t rx_bcast_frames;
103 	uint32_t rx_mcast_frames;
104 	uint32_t rx_runts;
105 	uint32_t rx_crcerrs;
106 	uint32_t rx_long_frames;
107 	uint32_t rx_fifo_full;
108 	uint32_t rx_desc_unavail;
109 	uint32_t rx_pause_frames;
110 
111 	/* TX stats. */
112 	uint32_t tx_frames;
113 	uint32_t tx_underruns;
114 	uint32_t tx_late_colls;
115 	uint32_t tx_pause_frames;
116 };
117 
118 /*
119  * Software state per device.
120  */
121 struct vte_softc {
122 	device_t		vte_dev;
123 	bus_space_tag_t		vte_bustag;
124 	bus_space_handle_t	vte_bushandle;
125 	bus_dma_tag_t		vte_dmatag;
126 	void*			vte_ih;
127 	struct ethercom		vte_ec;
128 	mii_data_t		vte_mii;
129 	device_t		vte_miibus;
130 	uint8_t			vte_eaddr[ETHER_ADDR_LEN];
131 	int			vte_flags;
132 #define	VTE_FLAG_LINK		0x8000
133 
134 	struct callout		vte_tick_ch;
135 	struct vte_hw_stats	vte_stats;
136 	struct vte_chain_data	vte_cdata;
137 	int			vte_if_flags;
138 	int			vte_watchdog_timer;
139 	struct sysctllog	*vte_clog;
140 	int			vte_int_rx_mod;
141 	int			vte_int_tx_mod;
142 
143 	krndsource_t	rnd_source;
144 };
145 
146 #define vte_if	vte_ec.ec_if
147 #define vte_bpf	vte_if.if_bpf
148 
149 /* Register access macros. */
150 #define	CSR_WRITE_2(_sc, reg, val)	\
151 	bus_space_write_2((_sc)->vte_bustag,  (_sc)->vte_bushandle, \
152 	(reg), (val))
153 #define	CSR_READ_2(_sc, reg)		\
154 	bus_space_read_2((_sc)->vte_bustag,  (_sc)->vte_bushandle, (reg))
155 
156 #define	VTE_TX_TIMEOUT		5
157 #define	VTE_RESET_TIMEOUT	100
158 #define	VTE_TIMEOUT		1000
159 #define	VTE_PHY_TIMEOUT		1000
160 
161 #endif	/* _IF_VTEVAR_H */
162