2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2001
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
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 $
41 * Tigon general information block. This resides in host memory
42 * and contains the status counters, ring control blocks and
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;
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)
60 #define BGE_TIMEOUT 5000
61 #define BGE_FIRMWARE_TIMEOUT 20000
62 #define BGE_TXCONS_UNSET 0xFFFF /* impossible value */
65 * Other utility macros.
67 #define BGE_INC(x, y) (x) = ((x) + 1) % (y)
70 * Register access macros. The Tigon always uses memory mapped register
71 * accesses and all registers must be accessed with 32 bit operations.
74 #define CSR_WRITE_4(sc, reg, val) \
75 bus_space_write_4(sc->bge_btag, sc->bge_bhandle, reg, val)
77 #define CSR_READ_4(sc, reg) \
78 bus_space_read_4(sc->bge_btag, sc->bge_bhandle, reg)
80 #define BGE_SETBIT(sc, reg, x) \
81 CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) | x))
83 #define BGE_CLRBIT(sc, reg, x) \
84 CSR_WRITE_4(sc, reg, (CSR_READ_4(sc, reg) & ~x))
86 #define BGE_MEMWIN_READ(sc, x, val) \
88 pci_write_config(sc->bge_dev, BGE_PCI_MEMWIN_BASEADDR, \
89 (0xFFFF0000 & x), 4); \
90 val = CSR_READ_4(sc, BGE_MEMWIN_START + (x & 0xFFFF)); \
93 #define BGE_MEMWIN_WRITE(sc, x, val) \
95 pci_write_config(sc->bge_dev, BGE_PCI_MEMWIN_BASEADDR, \
96 (0xFFFF0000 & x), 4); \
97 CSR_WRITE_4(sc, BGE_MEMWIN_START + (x & 0xFFFF), val); \
100 #define RCB_WRITE_4(sc, rcb, offset, val) \
101 bus_space_write_4(sc->bge_btag, sc->bge_bhandle, \
102 rcb + offsetof(struct bge_rcb, offset), val)
105 * Memory management stuff. Note: the SSLOTS, MSLOTS and JSLOTS
106 * values are tuneable. They control the actual amount of buffers
107 * allocated for the standard, mini and jumbo receive rings.
110 #define BGE_SSLOTS 256
111 #define BGE_MSLOTS 256
112 #define BGE_JSLOTS 384
114 #define BGE_JRAWLEN (BGE_JUMBO_FRAMELEN + ETHER_ALIGN)
115 #define BGE_JLEN (BGE_JRAWLEN + \
116 (sizeof(uint64_t) - BGE_JRAWLEN % sizeof(uint64_t)))
117 #define BGE_JPAGESZ PAGE_SIZE
118 #define BGE_RESID (BGE_JPAGESZ - (BGE_JLEN * BGE_JSLOTS) % BGE_JPAGESZ)
119 #define BGE_JMEM ((BGE_JLEN * BGE_JSLOTS) + BGE_RESID)
124 struct bge_softc *bge_sc;
126 bus_addr_t bge_paddr;
129 SLIST_ENTRY(bge_jslot) jslot_link;
133 * Ring structures. Most of these reside in host memory and we tell
134 * the NIC where they are via the ring control blocks. The exceptions
135 * are the tx and command rings, which live in NIC memory and which
136 * we access via the shared memory window.
138 struct bge_ring_data {
139 struct bge_rx_bd *bge_rx_std_ring;
140 bus_addr_t bge_rx_std_ring_paddr;
141 struct bge_rx_bd *bge_rx_jumbo_ring;
142 bus_addr_t bge_rx_jumbo_ring_paddr;
143 struct bge_rx_bd *bge_rx_return_ring;
144 bus_addr_t bge_rx_return_ring_paddr;
145 struct bge_tx_bd *bge_tx_ring;
146 bus_addr_t bge_tx_ring_paddr;
147 struct bge_status_block *bge_status_block;
148 bus_addr_t bge_status_block_paddr;
149 struct bge_stats *bge_stats;
150 bus_addr_t bge_stats_paddr;
152 struct bge_gib bge_info;
156 struct mbuf *bge_mbuf;
157 bus_addr_t bge_paddr;
161 * Mbuf pointers. We need these to keep track of the virtual addresses
162 * of our mbuf chains since we can only convert from physical to virtual,
163 * not the other way around.
165 struct bge_chain_data {
166 bus_dma_tag_t bge_parent_tag;
167 bus_dma_tag_t bge_rx_std_ring_tag;
168 bus_dma_tag_t bge_rx_jumbo_ring_tag;
169 bus_dma_tag_t bge_rx_return_ring_tag;
170 bus_dma_tag_t bge_tx_ring_tag;
171 bus_dma_tag_t bge_status_tag;
172 bus_dma_tag_t bge_stats_tag;
173 bus_dma_tag_t bge_jumbo_tag;
174 bus_dma_tag_t bge_tx_mtag; /* TX mbuf DMA tag */
175 bus_dma_tag_t bge_rx_mtag; /* RX mbuf DMA tag */
176 bus_dmamap_t bge_rx_tmpmap;
177 bus_dmamap_t bge_tx_dmamap[BGE_TX_RING_CNT];
178 bus_dmamap_t bge_rx_std_dmamap[BGE_STD_RX_RING_CNT];
179 bus_dmamap_t bge_rx_std_ring_map;
180 bus_dmamap_t bge_rx_jumbo_ring_map;
181 bus_dmamap_t bge_tx_ring_map;
182 bus_dmamap_t bge_rx_return_ring_map;
183 bus_dmamap_t bge_status_map;
184 bus_dmamap_t bge_stats_map;
185 bus_dmamap_t bge_jumbo_map;
186 struct mbuf *bge_tx_chain[BGE_TX_RING_CNT];
187 struct bge_rxchain bge_rx_std_chain[BGE_STD_RX_RING_CNT];
188 struct bge_rxchain bge_rx_jumbo_chain[BGE_JUMBO_RX_RING_CNT];
189 /* Stick the jumbo mem management stuff here too. */
190 struct bge_jslot bge_jslots[BGE_JSLOTS];
194 struct arpcom arpcom; /* interface info */
197 bus_space_handle_t bge_bhandle;
198 bus_space_tag_t bge_btag;
200 struct resource *bge_irq;
201 struct resource *bge_res;
202 struct ifmedia bge_ifmedia; /* TBI media info */
205 uint32_t bge_pci_miscctl;
206 uint32_t bge_status_tag;
207 uint32_t bge_flags; /* BGE_FLAG_ */
208 #define BGE_FLAG_TBI 0x00000001
209 #define BGE_FLAG_JUMBO 0x00000002
210 #define BGE_FLAG_MII_SERDES 0x00000010
211 #define BGE_FLAG_CPMU 0x00000020
212 #define BGE_FLAG_PCIX 0x00000200
213 #define BGE_FLAG_PCIE 0x00000400
214 #define BGE_FLAG_5700_FAMILY 0x00001000
215 #define BGE_FLAG_5705_PLUS 0x00002000
216 #define BGE_FLAG_5714_FAMILY 0x00004000
217 #define BGE_FLAG_575X_PLUS 0x00008000
218 #define BGE_FLAG_5755_PLUS 0x00010000
219 #define BGE_FLAG_MAXADDR_40BIT 0x00020000
220 #define BGE_FLAG_RX_ALIGNBUG 0x00100000
221 #define BGE_FLAG_NO_EEPROM 0x10000000
222 #define BGE_FLAG_5788 0x20000000
223 #define BGE_FLAG_SHORTDMA 0x40000000
224 #define BGE_FLAG_STATUS_TAG 0x80000000
227 uint32_t bge_asicrev;
228 uint32_t bge_chiprev;
229 struct bge_ring_data bge_ldata; /* rings */
230 struct bge_chain_data bge_cdata; /* mbufs */
231 uint16_t bge_tx_saved_considx;
232 uint16_t bge_rx_saved_considx;
233 uint16_t bge_ev_saved_considx;
234 uint16_t bge_return_ring_cnt;
235 uint16_t bge_std; /* current std ring head */
236 uint16_t bge_jumbo; /* current jumo ring head */
237 SLIST_HEAD(__bge_jfreehead, bge_jslot) bge_jfree_listhead;
238 struct lwkt_serialize bge_jslot_serializer;
239 uint32_t bge_stat_ticks;
240 uint32_t bge_rx_coal_ticks;
241 uint32_t bge_tx_coal_ticks;
242 uint32_t bge_rx_coal_bds;
243 uint32_t bge_tx_coal_bds;
244 uint32_t bge_rx_coal_ticks_int;
245 uint32_t bge_tx_coal_ticks_int;
246 uint32_t bge_rx_coal_bds_int;
247 uint32_t bge_tx_coal_bds_int;
248 uint32_t bge_tx_prodidx;
249 uint32_t bge_tx_buf_ratio;
250 uint32_t bge_mi_mode;
251 int bge_force_defrag;
252 int bge_mbox_reorder;
257 struct callout bge_stat_timer;
259 struct sysctl_ctx_list bge_sysctl_ctx;
260 struct sysctl_oid *bge_sysctl_tree;
263 uint32_t bge_coal_chg;
264 #define BGE_RX_COAL_TICKS_CHG 0x01
265 #define BGE_TX_COAL_TICKS_CHG 0x02
266 #define BGE_RX_COAL_BDS_CHG 0x04
267 #define BGE_TX_COAL_BDS_CHG 0x08
268 #define BGE_RX_COAL_TICKS_INT_CHG 0x10
269 #define BGE_TX_COAL_TICKS_INT_CHG 0x20
270 #define BGE_RX_COAL_BDS_INT_CHG 0x40
271 #define BGE_TX_COAL_BDS_INT_CHG 0x80
273 void (*bge_link_upd)(struct bge_softc *, uint32_t);
274 uint32_t bge_link_chg;
277 #define BGE_NSEG_NEW 32
278 #define BGE_NSEG_SPARE 5
279 #define BGE_NSEG_RSVD 16
281 /* RX coalesce ticks, unit: us */
282 #define BGE_RX_COAL_TICKS_MIN 0
283 #define BGE_RX_COAL_TICKS_DEF 160
284 #define BGE_RX_COAL_TICKS_MAX 1023
286 /* TX coalesce ticks, unit: us */
287 #define BGE_TX_COAL_TICKS_MIN 0
288 #define BGE_TX_COAL_TICKS_DEF 1023
289 #define BGE_TX_COAL_TICKS_MAX 1023
291 /* RX coalesce BDs */
292 #define BGE_RX_COAL_BDS_MIN 1
293 #define BGE_RX_COAL_BDS_DEF 80
294 #define BGE_RX_COAL_BDS_MAX 255
296 /* TX coalesce BDs */
297 #define BGE_TX_COAL_BDS_MIN 1
298 #define BGE_TX_COAL_BDS_DEF 128
299 #define BGE_TX_COAL_BDS_MAX 255
301 #endif /* !_IF_BGEVAR_H_ */