xref: /freebsd/sys/dev/sge/if_sgereg.h (revision d8b878873e7aa8df1972cc6a642804b17eb61087)
1 /*-
2  * Copyright (c) 2008, 2009, 2010 Nikolay Denev <ndenev@gmail.com>
3  * Copyright (c) 2007, 2008 Alexander Pohoyda <alexander.pohoyda@gmx.net>
4  * Copyright (c) 1997, 1998, 1999
5  *      Bill Paul <wpaul@ctr.columbia.edu>.  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, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Bill Paul.
18  * 4. Neither the name of the author nor the names of any co-contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL AUTHORS OR
26  * THE VOICES IN THEIR HEADS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $FreeBSD$
36  */
37 
38 #ifndef _IF_SGEREG_H
39 #define	_IF_SGEREG_H
40 
41 /*
42  * SiS PCI vendor ID.
43  */
44 #define	SIS_VENDORID		0x1039
45 
46 /*
47  * SiS PCI device IDs
48  */
49 #define	SIS_DEVICEID_190	0x0190
50 #define	SIS_DEVICEID_191	0x0191
51 
52 #define	TX_CTL			0x00
53 #define	TX_DESC			0x04
54 #define	Reserved0		0x08
55 #define	TX_NEXT			0x0c
56 
57 #define	RX_CTL			0x10
58 #define	RX_DESC			0x14
59 #define	Reserved1		0x18
60 #define	RX_NEXT			0x1c
61 
62 #define	IntrStatus		0x20
63 #define	IntrMask		0x24
64 #define	IntrControl		0x28
65 #define	IntrTimer		0x2c
66 
67 #define	PMControl		0x30
68 #define	Reserved2		0x34
69 #define	ROMControl		0x38
70 #define	ROMInterface		0x3c
71 #define	StationControl		0x40
72 #define	GMIIControl		0x44
73 #define	GMacIOCR		0x48
74 #define	GMacIOCTL		0x4c
75 #define	TxMacControl		0x50
76 #define	TxMacTimeLimit		0x54
77 #define	RGMIIDelay		0x58
78 #define	Reserved3		0x5c
79 #define	RxMacControl		0x60	/* 1  WORD */
80 #define	RxMacAddr		0x62	/* 6x BYTE */
81 #define	RxHashTable		0x68	/* 1 LONG */
82 #define	RxHashTable2		0x6c	/* 1 LONG */
83 #define	RxWakeOnLan		0x70
84 #define	RxWakeOnLanData		0x74
85 #define	RxMPSControl		0x78
86 #define	Reserved4		0x7c
87 
88 /*
89  * IntrStatus Register Content
90  */
91 #define	INTR_SOFT		0x40000000
92 #define	INTR_TIMER		0x20000000
93 #define	INTR_PAUSE_FRAME	0x00080000
94 #define	INTR_MAGIC_FRAME	0x00040000
95 #define	INTR_WAKE_FRAME		0x00020000
96 #define	INTR_LINK		0x00010000
97 #define	INTR_RX_IDLE		0x00000080
98 #define	INTR_RX_DONE		0x00000040
99 #define	INTR_TXQ1_IDLE		0x00000020
100 #define	INTR_TXQ1_DONE		0x00000010
101 #define	INTR_TX_IDLE		0x00000008
102 #define	INTR_TX_DONE		0x00000004
103 #define	INTR_RX_HALT		0x00000002
104 #define	INTR_TX_HALT		0x00000001
105 
106 #define	SGE_INTRS							\
107 	(INTR_RX_IDLE | INTR_RX_DONE | INTR_TXQ1_IDLE |			\
108 	 INTR_TXQ1_DONE |INTR_TX_IDLE | INTR_TX_DONE |			\
109 	 INTR_TX_HALT | INTR_RX_HALT)
110 
111 /*
112  * RxStatusDesc Register Content
113  */
114 #define	RxRES			0x00200000
115 #define	RxCRC			0x00080000
116 #define	RxRUNT			0x00100000
117 #define	RxRWT			0x00400000
118 
119 /*
120  * RX_CTL Register Content
121  */
122 #define	RX_CTL_POLL		0x00000010
123 #define	RX_CTL_ENB		0x00000001
124 
125 /*
126  * TX_CTL Register Content
127  */
128 #define	TX_CTL_POLL		0x00000010
129 #define	TX_CTL_ENB		0x00000001
130 
131 /*
132  * RxMacControl Register Content
133  */
134 #define	AcceptBroadcast		0x0800
135 #define	AcceptMulticast		0x0400
136 #define	AcceptMyPhys		0x0200
137 #define	AcceptAllPhys		0x0100
138 #define	AcceptErr		0x0020
139 #define	AcceptRunt		0x0010
140 
141 /* Station control register. */
142 #define	SC_LOOPBACK		0x80000000
143 #define	SC_RGMII		0x00008000
144 #define	SC_FDX			0x00001000
145 #define	SC_SPEED_MASK		0x00000c00
146 #define	SC_SPEED_10		0x00000400
147 #define	SC_SPEED_100		0x00000800
148 #define	SC_SPEED_1000		0x00000c00
149 
150 /*
151  * Gigabit Media Independent Interface CTL register
152  */
153 #define	GMI_DATA		0xffff0000
154 #define	GMI_DATA_SHIFT		16
155 #define	GMI_REG			0x0000f800
156 #define	GMI_REG_SHIFT		11
157 #define	GMI_PHY			0x000007c0
158 #define	GMI_PHY_SHIFT		6
159 #define	GMI_OP_WR		0x00000020
160 #define	GMI_OP_RD		0x00000000
161 #define	GMI_REQ			0x00000010
162 #define	GMI_MDIO		0x00000008
163 #define	GMI_MDDIR		0x00000004
164 #define	GMI_MDC			0x00000002
165 #define	GMI_MDEN		0x00000001
166 
167 /* Tx descriptor command bits. */
168 #define	TDC_OWN			0x80000000
169 #define	TDC_INTR		0x40000000
170 #define	TDC_THOL3		0x30000000
171 #define	TDC_THOL2		0x20000000
172 #define	TDC_THOL1		0x10000000
173 #define	TDC_THOL0		0x00000000
174 #define	TDC_LS			0x08000000
175 #define	TDC_IP_CSUM		0x04000000
176 #define	TDC_TCP_CSUM		0x02000000
177 #define	TDC_UDP_CSUM		0x01000000
178 #define	TDC_BST			0x00800000
179 #define	TDC_EXT			0x00400000
180 #define	TDC_DEF			0x00200000
181 #define	TDC_BKF			0x00100000
182 #define	TDC_CRS			0x00080000
183 #define	TDC_COL			0x00040000
184 #define	TDC_CRC			0x00020000
185 #define	TDC_PAD			0x00010000
186 
187 #define	SGE_TX_INTR_FRAMES	32
188 
189 /*
190  * TX descriptor status bits.
191  */
192 #define	TDS_OWC			0x00080000
193 #define	TDS_ABT			0x00040000
194 #define	TDS_FIFO		0x00020000
195 #define	TDS_CRS			0x00010000
196 #define	TDS_COLLS		0x0000ffff
197 #define	SGE_TX_ERROR(x)		((x) & (TDS_OWC | TDS_ABT | TDS_FIFO | TDS_CRS))
198 #define	TX_ERR_BITS		"\20"				\
199 				"\21CRS\22FIFO\23ABT\24OWC"
200 
201 /* Rx descriptor command bits. */
202 #define	RDC_OWN			0x80000000
203 #define	RDC_INTR		0x40000000
204 #define	RDC_IP_CSUM		0x20000000
205 #define	RDC_TCP_CSUM		0x10000000
206 #define	RDC_UDP_CSUM		0x08000000
207 #define	RDC_IP_CSUM_OK		0x04000000
208 #define	RDC_TCP_CSUM_OK		0x02000000
209 #define	RDC_UDP_CSUM_OK		0x01000000
210 #define	RDC_WAKEUP		0x00400000
211 #define	RDC_MAGIC		0x00200000
212 #define	RDC_PAUSE		0x00100000
213 #define	RDC_BCAST		0x000c0000
214 #define	RDC_MCAST		0x00080000
215 #define	RDC_UCAST		0x00040000
216 #define	RDC_CRCOFF		0x00020000
217 #define	RDC_PREADD		0x00010000
218 
219 /*
220  * RX descriptor status bits
221  */
222 #define	RDS_TAGON		0x80000000
223 #define	RDS_DESCS		0x3f000000
224 #define	RDS_ABORT		0x00800000
225 #define	RDS_SHORT		0x00400000
226 #define	RDS_LIMIT		0x00200000
227 #define	RDS_MIIER		0x00100000
228 #define	RDS_OVRUN		0x00080000
229 #define	RDS_NIBON		0x00040000
230 #define	RDS_COLON		0x00020000
231 #define	RDS_CRCOK		0x00010000
232 #define	SGE_RX_ERROR(x)							\
233         ((x) & (RDS_COLON | RDS_NIBON | RDS_OVRUN | RDS_MIIER |		\
234 	RDS_LIMIT | RDS_SHORT | RDS_ABORT))
235 #define	SGE_RX_NSEGS(x)		(((x) & RDS_DESCS) >> 24)
236 #define	RX_ERR_BITS 		"\20"					\
237 				"\21CRCOK\22COLON\23NIBON\24OVRUN"	\
238 				"\25MIIER\26LIMIT\27SHORT\30ABORT"	\
239 				"\40TAGON"
240 
241 #define	RING_END		0x80000000
242 #define	SGE_RX_BYTES(x)		((x) & 0xFFFF)
243 #define	SGE_INC(x, y)		(x) = (((x) + 1) % y)
244 
245 /* Taken from Solaris driver */
246 #define	EI_DATA			0xffff0000
247 #define	EI_DATA_SHIFT		16
248 #define	EI_OFFSET		0x0000fc00
249 #define	EI_OFFSET_SHIFT		10
250 #define	EI_OP			0x00000300
251 #define	EI_OP_SHIFT		8
252 #define	EI_OP_RD		(2 << EI_OP_SHIFT)
253 #define	EI_OP_WR		(1 << EI_OP_SHIFT)
254 #define	EI_REQ			0x00000080
255 #define	EI_DO			0x00000008
256 #define	EI_DI			0x00000004
257 #define	EI_CLK			0x00000002
258 #define	EI_CS			0x00000001
259 
260 /*
261  * EEPROM Addresses
262  */
263 #define	EEPROMSignature		0x00
264 #define	EEPROMCLK		0x01
265 #define	EEPROMInfo		0x02
266 #define	EEPROMMACAddr		0x03
267 
268 struct sge_desc {
269 	uint32_t	sge_sts_size;
270 	uint32_t	sge_cmdsts;
271 	uint32_t	sge_ptr;
272 	uint32_t	sge_flags;
273 };
274 
275 #define	SGE_RX_RING_CNT		256 /* [8, 1024] */
276 #define	SGE_TX_RING_CNT		256 /* [8, 8192] */
277 #define	SGE_DESC_ALIGN		16
278 #define	SGE_MAXTXSEGS		1
279 #define	SGE_RX_BUF_ALIGN	sizeof(uint64_t)
280 
281 #define	SGE_RX_RING_SZ		(SGE_RX_RING_CNT * sizeof(struct sge_desc))
282 #define	SGE_TX_RING_SZ		(SGE_TX_RING_CNT * sizeof(struct sge_desc))
283 #define	SGE_ADDR_LO(x)		((uint64_t) (x) & 0xFFFFFFFF)
284 
285 struct sge_list_data {
286 	struct sge_desc		*sge_rx_ring;
287 	struct sge_desc		*sge_tx_ring;
288 	/* physical bus addresses of sge_rx_ring/sge_tx_ring */
289 	bus_addr_t		sge_rx_paddr;
290 	bus_addr_t		sge_tx_paddr;
291 };
292 
293 struct sge_chain_data {
294 	bus_dma_tag_t		sge_tag;
295 	bus_dma_tag_t		sge_rx_tag;
296 	bus_dma_tag_t		sge_tx_tag;
297 	bus_dmamap_t		sge_rx_dmamap;
298 	bus_dmamap_t		sge_tx_dmamap;
299 	bus_dma_tag_t		sge_txmbuf_tag;
300 	bus_dma_tag_t		sge_rxmbuf_tag;
301 	struct mbuf		*sge_rx_mbuf[SGE_RX_RING_CNT];
302 	struct mbuf		*sge_tx_mbuf[SGE_TX_RING_CNT];
303 	bus_dmamap_t		sge_rx_map[SGE_RX_RING_CNT];
304 	bus_dmamap_t		sge_rx_spare_map;
305 	bus_dmamap_t		sge_tx_map[SGE_TX_RING_CNT];
306 	int			sge_rx_cons;
307 	int			sge_tx_prod;
308 	int			sge_tx_cons;
309 	int			sge_tx_cnt;
310 };
311 
312 struct sge_type {
313 	uint16_t		sge_vid;
314 	uint16_t		sge_did;
315 	char			*sge_name;
316 };
317 
318 struct sge_softc {
319 	struct ifnet		*sge_ifp;	/* interface info */
320 	struct resource		*sge_res;
321 	int			sge_res_id;
322 	int			sge_res_type;
323 	struct resource		*sge_irq;
324 	void			*sge_intrhand;
325 	device_t		sge_dev;
326 	device_t		sge_miibus;
327 	uint8_t			sge_rev;
328 	struct sge_list_data	sge_ldata;
329 	struct sge_chain_data	sge_cdata;
330 	struct callout		sge_stat_ch;
331 	int			sge_timer;
332 	int			sge_flags;
333 #define	SGE_FLAG_FASTETHER	0x0001
334 #define	SGE_FLAG_RGMII		0x0010
335 #define	SGE_FLAG_SPEED_1000	0x2000
336 #define	SGE_FLAG_FDX		0x4000
337 #define	SGE_FLAG_LINK		0x8000
338 	int			sge_if_flags;
339 	int			sge_intrcontrol;
340 	int			sge_intrtimer;
341 	struct mtx		sge_mtx;
342 };
343 
344 #define	SGE_LOCK(_sc)		mtx_lock(&(_sc)->sge_mtx)
345 #define	SGE_UNLOCK(_sc)		mtx_unlock(&(_sc)->sge_mtx)
346 #define	SGE_LOCK_ASSERT(_sc)	mtx_assert(&(_sc)->sge_mtx, MA_OWNED)
347 
348 #define	SGE_TIMEOUT		1000
349 
350 #endif /* _IF_SGEREG_H */
351