xref: /dragonfly/sys/dev/netif/bge/if_bgevar.h (revision cfd1aba3)
1 /*
2  * Copyright (c) 2001 Wind River Systems
3  * Copyright (c) 1997, 1998, 1999, 2001
4  *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following 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  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by Bill Paul.
17  * 4. Neither the name of the author nor the names of any co-contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * $FreeBSD: src/sys/dev/bge/if_bgereg.h,v 1.1.2.16 2004/09/23 20:11:18 ps Exp $
34  * $DragonFly: src/sys/dev/netif/bge/if_bgereg.h,v 1.25 2008/10/22 14:24:24 sephe Exp $
35  */
36 
37 #ifndef _IF_BGEVAR_H_
38 #define _IF_BGEVAR_H_
39 
40 /*
41  * Tigon general information block. This resides in host memory
42  * and contains the status counters, ring control blocks and
43  * producer pointers.
44  */
45 
46 struct bge_gib {
47 	struct bge_stats	bge_stats;
48 	struct bge_rcb		bge_tx_rcb[16];
49 	struct bge_rcb		bge_std_rx_rcb;
50 	struct bge_rcb		bge_jumbo_rx_rcb;
51 	struct bge_rcb		bge_mini_rx_rcb;
52 	struct bge_rcb		bge_return_rcb;
53 };
54 
55 #define BGE_MIN_FRAMELEN	60
56 #define BGE_MAX_FRAMELEN	1536
57 #define BGE_JUMBO_FRAMELEN	9018
58 #define BGE_JUMBO_MTU		(BGE_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
59 
60 #define BGE_TIMEOUT		5000
61 #define BGE_FIRMWARE_TIMEOUT	100000
62 #define BGE_TXCONS_UNSET	0xFFFF	/* impossible value */
63 
64 /*
65  * Other utility macros.
66  */
67 #define BGE_INC(x, y)		(x) = ((x) + 1) % (y)
68 
69 /*
70  * BAR0 MAC register access macros.  The Tigon always uses memory mapped
71  * register accesses and all registers must be accessed with 32 bit
72  * operations.
73  */
74 
75 #define CSR_WRITE_4(sc, reg, val)	\
76 	bus_space_write_4(sc->bge_btag, sc->bge_bhandle, reg, val)
77 
78 #define CSR_READ_4(sc, reg)		\
79 	bus_space_read_4(sc->bge_btag, sc->bge_bhandle, reg)
80 
81 #define BGE_SETBIT(sc, reg, x)	\
82 	CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) | x))
83 
84 #define BGE_CLRBIT(sc, reg, x)	\
85 	CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) & ~x))
86 
87 /* BAR2 APE register access macros. */
88 #define	APE_WRITE_4(sc, reg, val)	\
89 	bus_write_4(sc->bge_res2, reg, val)
90 
91 #define	APE_READ_4(sc, reg)		\
92 	bus_read_4(sc->bge_res2, reg)
93 
94 #define	APE_SETBIT(sc, reg, x)	\
95 	APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) | (x)))
96 #define	APE_CLRBIT(sc, reg, x)	\
97 	APE_WRITE_4(sc, reg, (APE_READ_4(sc, reg) & ~(x)))
98 
99 #define BGE_MEMWIN_READ(sc, x, val)				\
100 do {								\
101 	pci_write_config(sc->bge_dev, BGE_PCI_MEMWIN_BASEADDR,	\
102 	    (0xFFFF0000 & x), 4);				\
103 	val = CSR_READ_4(sc, BGE_MEMWIN_START + (x & 0xFFFF));	\
104 } while(0)
105 
106 #define BGE_MEMWIN_WRITE(sc, x, val)				\
107 do {								\
108 	pci_write_config(sc->bge_dev, BGE_PCI_MEMWIN_BASEADDR,	\
109 	    (0xFFFF0000 & x), 4);				\
110 	CSR_WRITE_4(sc, BGE_MEMWIN_START + (x & 0xFFFF), val);	\
111 } while(0)
112 
113 #define RCB_WRITE_4(sc, rcb, offset, val)			\
114 	bus_space_write_4(sc->bge_btag, sc->bge_bhandle,	\
115 			  rcb + offsetof(struct bge_rcb, offset), val)
116 
117 /*
118  * Memory management stuff. Note: the SSLOTS, MSLOTS and JSLOTS
119  * values are tuneable. They control the actual amount of buffers
120  * allocated for the standard, mini and jumbo receive rings.
121  */
122 
123 #define BGE_SSLOTS	256
124 #define BGE_MSLOTS	256
125 #define BGE_JSLOTS	384
126 
127 #define BGE_JRAWLEN (BGE_JUMBO_FRAMELEN + ETHER_ALIGN)
128 #define BGE_JLEN (BGE_JRAWLEN + \
129 	(sizeof(uint64_t) - BGE_JRAWLEN % sizeof(uint64_t)))
130 #define BGE_JPAGESZ PAGE_SIZE
131 #define BGE_RESID (BGE_JPAGESZ - (BGE_JLEN * BGE_JSLOTS) % BGE_JPAGESZ)
132 #define BGE_JMEM ((BGE_JLEN * BGE_JSLOTS) + BGE_RESID)
133 
134 struct bge_softc;
135 
136 struct bge_jslot {
137 	struct bge_softc	*bge_sc;
138 	void			*bge_buf;
139 	bus_addr_t		bge_paddr;
140 	int			bge_inuse;
141 	int			bge_slot;
142 	SLIST_ENTRY(bge_jslot)	jslot_link;
143 };
144 
145 /*
146  * Ring structures. Most of these reside in host memory and we tell
147  * the NIC where they are via the ring control blocks. The exceptions
148  * are the tx and command rings, which live in NIC memory and which
149  * we access via the shared memory window.
150  */
151 struct bge_ring_data {
152 	struct bge_rx_bd	*bge_rx_std_ring;
153 	bus_addr_t		bge_rx_std_ring_paddr;
154 	struct bge_rx_bd	*bge_rx_jumbo_ring;
155 	bus_addr_t		bge_rx_jumbo_ring_paddr;
156 	struct bge_rx_bd	*bge_rx_return_ring;
157 	bus_addr_t		bge_rx_return_ring_paddr;
158 	struct bge_tx_bd	*bge_tx_ring;
159 	bus_addr_t		bge_tx_ring_paddr;
160 	struct bge_status_block	*bge_status_block;
161 	bus_addr_t		bge_status_block_paddr;
162 	struct bge_stats	*bge_stats;
163 	bus_addr_t		bge_stats_paddr;
164 	void			*bge_jumbo_buf;
165 	struct bge_gib		bge_info;
166 };
167 
168 struct bge_rxchain {
169 	struct mbuf	*bge_mbuf;
170 	bus_addr_t	bge_paddr;
171 };
172 
173 /*
174  * Mbuf pointers. We need these to keep track of the virtual addresses
175  * of our mbuf chains since we can only convert from physical to virtual,
176  * not the other way around.
177  */
178 struct bge_chain_data {
179 	bus_dma_tag_t		bge_parent_tag;
180 	bus_dma_tag_t		bge_rx_std_ring_tag;
181 	bus_dma_tag_t		bge_rx_jumbo_ring_tag;
182 	bus_dma_tag_t		bge_rx_return_ring_tag;
183 	bus_dma_tag_t		bge_tx_ring_tag;
184 	bus_dma_tag_t		bge_status_tag;
185 	bus_dma_tag_t		bge_stats_tag;
186 	bus_dma_tag_t		bge_jumbo_tag;
187 	bus_dma_tag_t		bge_tx_mtag;	/* TX mbuf DMA tag */
188 	bus_dma_tag_t		bge_rx_mtag;	/* RX mbuf DMA tag */
189 	bus_dmamap_t		bge_rx_tmpmap;
190 	bus_dmamap_t		bge_tx_dmamap[BGE_TX_RING_CNT];
191 	bus_dmamap_t		bge_rx_std_dmamap[BGE_STD_RX_RING_CNT];
192 	bus_dmamap_t		bge_rx_std_ring_map;
193 	bus_dmamap_t		bge_rx_jumbo_ring_map;
194 	bus_dmamap_t		bge_tx_ring_map;
195 	bus_dmamap_t		bge_rx_return_ring_map;
196 	bus_dmamap_t		bge_status_map;
197 	bus_dmamap_t		bge_stats_map;
198 	bus_dmamap_t		bge_jumbo_map;
199 	struct mbuf		*bge_tx_chain[BGE_TX_RING_CNT];
200 	struct bge_rxchain	bge_rx_std_chain[BGE_STD_RX_RING_CNT];
201 	struct bge_rxchain	bge_rx_jumbo_chain[BGE_JUMBO_RX_RING_CNT];
202 	/* Stick the jumbo mem management stuff here too. */
203 	struct bge_jslot	bge_jslots[BGE_JSLOTS];
204 };
205 
206 struct bge_softc {
207 	struct arpcom		arpcom;		/* interface info */
208 	device_t		bge_dev;
209 	device_t		bge_miibus;
210 	bus_space_handle_t	bge_bhandle;
211 	bus_space_tag_t		bge_btag;
212 	void			*bge_intrhand;
213 	struct resource		*bge_irq;
214 	int			bge_irq_type;
215 	int			bge_irq_rid;
216 	struct resource		*bge_res;	/* MAC mapped I/O */
217 	struct resource		*bge_res2;	/* APE mapped I/O */
218 	struct ifmedia		bge_ifmedia;	/* TBI media info */
219 	int			bge_pcixcap;
220 	int			bge_pciecap;
221 	int			bge_msicap;
222 	uint32_t		bge_pci_miscctl;
223 	uint32_t		bge_status_tag;
224 	uint32_t		bge_flags;	/* BGE_FLAG_ */
225 #define BGE_FLAG_TBI		0x00000001
226 #define BGE_FLAG_JUMBO		0x00000002
227 #define BGE_FLAG_ONESHOT_MSI	0x00000004
228 #define BGE_FLAG_TSO		0x00000008
229 #define BGE_FLAG_MII_SERDES	0x00000010
230 #define	BGE_FLAG_CPMU		0x00000020
231 #define BGE_FLAG_APE		0x00000040
232 #define BGE_FLAG_PCIX		0x00000200
233 #define BGE_FLAG_PCIE		0x00000400
234 #define BGE_FLAG_5700_FAMILY	0x00001000
235 #define BGE_FLAG_5705_PLUS	0x00002000
236 #define BGE_FLAG_5714_FAMILY	0x00004000
237 #define BGE_FLAG_575X_PLUS	0x00008000
238 #define BGE_FLAG_5755_PLUS	0x00010000
239 #define BGE_FLAG_MAXADDR_40BIT	0x00020000
240 #define BGE_FLAG_RX_ALIGNBUG	0x00100000
241 #define BGE_FLAG_NO_EEPROM	0x10000000
242 #define BGE_FLAG_5788		0x20000000
243 #define BGE_FLAG_SHORTDMA	0x40000000
244 #define BGE_FLAG_STATUS_TAG	0x80000000
245 
246 	uint32_t		bge_mfw_flags;	/* Management F/W flags */
247 #define	BGE_MFW_ON_RXCPU	0x00000001
248 #define	BGE_MFW_ON_APE		0x00000002
249 #define	BGE_MFW_TYPE_NCSI	0x00000004
250 #define	BGE_MFW_TYPE_DASH	0x00000008
251 	int			bge_phy_ape_lock;
252 	int			bge_func_addr;
253 
254 	uint32_t		bge_chipid;
255 	uint8_t			bge_asf_mode;
256 #define ASF_ENABLE		0x01
257 #define ASF_NEW_HANDSHAKE	0x02
258 #define ASF_STACKUP		0x04
259 	uint8_t			bge_asf_count;
260 	uint32_t		bge_asicrev;
261 	uint32_t		bge_chiprev;
262 	struct ifpoll_compat	bge_npoll;	/* polling */
263 	struct bge_ring_data	bge_ldata;	/* rings */
264 	struct bge_chain_data	bge_cdata;	/* mbufs */
265 	uint16_t		bge_tx_saved_considx;
266 	uint16_t		bge_rx_saved_considx;
267 	uint16_t		bge_ev_saved_considx;
268 	uint16_t		bge_return_ring_cnt;
269 	uint16_t		bge_std;	/* current std ring head */
270 	uint16_t		bge_jumbo;	/* current jumo ring head */
271 	SLIST_HEAD(__bge_jfreehead, bge_jslot)	bge_jfree_listhead;
272 	struct lwkt_serialize	bge_jslot_serializer;
273 	uint32_t		bge_stat_ticks;
274 	uint32_t		bge_rx_coal_ticks;
275 	uint32_t		bge_tx_coal_ticks;
276 	uint32_t		bge_rx_coal_bds;
277 	uint32_t		bge_tx_coal_bds;
278 	uint32_t		bge_rx_coal_ticks_int;
279 	uint32_t		bge_tx_coal_ticks_int;
280 	uint32_t		bge_rx_coal_bds_int;
281 	uint32_t		bge_tx_coal_bds_int;
282 	uint32_t		bge_tx_prodidx;
283 	int			bge_tx_wreg;
284 	int			bge_rx_wreg;
285 	uint32_t		bge_tx_buf_ratio;
286 	uint32_t		bge_mi_mode;
287 	int			bge_force_defrag;
288 	int			bge_mbox_reorder;
289 	int			bge_if_flags;
290 	int			bge_txcnt;
291 	int			bge_txspare;
292 	int			bge_txrsvd;
293 	int			bge_link;
294 	int			bge_link_evt;
295 	struct callout		bge_stat_timer;
296 
297 	struct sysctl_ctx_list	bge_sysctl_ctx;
298 	struct sysctl_oid	*bge_sysctl_tree;
299 
300 	int			bge_phyno;
301 	uint32_t		bge_coal_chg;
302 #define BGE_RX_COAL_TICKS_CHG		0x01
303 #define BGE_TX_COAL_TICKS_CHG		0x02
304 #define BGE_RX_COAL_BDS_CHG		0x04
305 #define BGE_TX_COAL_BDS_CHG		0x08
306 #define BGE_RX_COAL_TICKS_INT_CHG	0x10
307 #define BGE_TX_COAL_TICKS_INT_CHG	0x20
308 #define BGE_RX_COAL_BDS_INT_CHG		0x40
309 #define BGE_TX_COAL_BDS_INT_CHG		0x80
310 
311 	void			(*bge_link_upd)(struct bge_softc *, uint32_t);
312 	uint32_t		bge_link_chg;
313 };
314 
315 #define BGE_NSEG_NEW		40
316 #define BGE_NSEG_SPARE		5
317 #define BGE_NSEG_SPARE_TSO	33
318 #define BGE_NSEG_RSVD		16
319 #define BGE_NSEG_RSVD_TSO	4
320 
321 /* RX coalesce ticks, unit: us */
322 #define BGE_RX_COAL_TICKS_MIN	0
323 #define BGE_RX_COAL_TICKS_DEF	160
324 #define BGE_RX_COAL_TICKS_MAX	1023
325 
326 /* TX coalesce ticks, unit: us */
327 #define BGE_TX_COAL_TICKS_MIN	0
328 #define BGE_TX_COAL_TICKS_DEF	1023
329 #define BGE_TX_COAL_TICKS_MAX	1023
330 
331 /* RX coalesce BDs */
332 #define BGE_RX_COAL_BDS_MIN	0
333 #define BGE_RX_COAL_BDS_DEF	80
334 #define BGE_RX_COAL_BDS_MAX	255
335 
336 /* TX coalesce BDs */
337 #define BGE_TX_COAL_BDS_MIN	0
338 #define BGE_TX_COAL_BDS_DEF	128
339 #define BGE_TX_COAL_BDS_MAX	255
340 
341 /* Number of segments sent before writing to TX related registers */
342 #define BGE_TX_WREG_NSEGS	16
343 
344 #endif	/* !_IF_BGEVAR_H_ */
345