if_skvar.h revision 1.8 1 /* $NetBSD: if_skvar.h,v 1.8 2006/02/11 13:04:44 rpaulo Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
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, 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 the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35 /* $OpenBSD: if_skreg.h,v 1.10 2003/08/12 05:23:06 nate Exp $ */
36
37 /*
38 * Copyright (c) 1997, 1998, 1999, 2000
39 * Bill Paul <wpaul (at) ctr.columbia.edu>. All rights reserved.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by Bill Paul.
52 * 4. Neither the name of the author nor the names of any co-contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
60 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66 * THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 * $FreeBSD: /c/ncvs/src/sys/pci/if_skreg.h,v 1.9 2000/04/22 02:16:37 wpaul Exp $
69 */
70
71 /*
72 * Copyright (c) 2003 Nathan L. Binkert <binkertn (at) umich.edu>
73 *
74 * Permission to use, copy, modify, and distribute this software for any
75 * purpose with or without fee is hereby granted, provided that the above
76 * copyright notice and this permission notice appear in all copies.
77 *
78 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
79 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
80 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
81 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
82 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
83 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
84 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
85 */
86
87 #ifndef _DEV_PCI_IF_SKVAR_H_
88 #define _DEV_PCI_IF_SKVAR_H_
89
90 #include "rnd.h"
91
92 #if NRND > 0
93 #include <sys/rnd.h>
94 #endif
95
96 struct sk_jslot {
97 caddr_t sk_buf;
98 int sk_inuse;
99 };
100
101 struct sk_jpool_entry {
102 int slot;
103 LIST_ENTRY(sk_jpool_entry) jpool_entries;
104 };
105
106 struct sk_chain {
107 void *sk_desc;
108 struct mbuf *sk_mbuf;
109 struct sk_chain *sk_next;
110 };
111
112 /*
113 * Number of DMA segments in a TxCB. Note that this is carefully
114 * chosen to make the total struct size an even power of two. It's
115 * critical that no TxCB be split across a page boundary since
116 * no attempt is made to allocate physically contiguous memory.
117 *
118 */
119 #define SK_NTXSEG 30
120
121 struct sk_txmap_entry {
122 bus_dmamap_t dmamap;
123 SIMPLEQ_ENTRY(sk_txmap_entry) link;
124 };
125
126 struct sk_chain_data {
127 struct sk_chain sk_tx_chain[SK_TX_RING_CNT];
128 struct sk_chain sk_rx_chain[SK_RX_RING_CNT];
129 struct sk_txmap_entry *sk_tx_map[SK_TX_RING_CNT];
130 bus_dmamap_t sk_rx_map[SK_RX_RING_CNT];
131 int sk_tx_prod;
132 int sk_tx_cons;
133 int sk_tx_cnt;
134 int sk_rx_prod;
135 int sk_rx_cons;
136 int sk_rx_cnt;
137 /* Stick the jumbo mem management stuff here too. */
138 struct sk_jslot sk_jslots[SK_JSLOTS];
139 void *sk_jumbo_buf;
140
141 };
142
143 struct sk_ring_data {
144 struct sk_tx_desc sk_tx_ring[SK_TX_RING_CNT];
145 struct sk_rx_desc sk_rx_ring[SK_RX_RING_CNT];
146 };
147
148 #define SK_TX_RING_ADDR(sc, i) \
149 ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
150 offsetof(struct sk_ring_data, sk_tx_ring[(i)]))
151
152 #define SK_RX_RING_ADDR(sc, i) \
153 ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
154 offsetof(struct sk_ring_data, sk_rx_ring[(i)]))
155
156 #define SK_CDOFF(x) offsetof(struct sk_ring_data, x)
157 #define SK_CDTXOFF(x) SK_CDOFF(sk_tx_ring[(x)])
158 #define SK_CDRXOFF(x) SK_CDOFF(sk_rx_ring[(x)])
159
160 #define SK_CDTXSYNC(sc, x, n, ops) \
161 do { \
162 int __x, __n; \
163 \
164 __x = (x); \
165 __n = (n); \
166 \
167 /* If it will wrap around, sync to the end of the ring. */ \
168 if ((__x + __n) > SK_TX_RING_CNT) { \
169 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, \
170 (sc)->sk_ring_map, SK_CDTXOFF(__x), \
171 sizeof(struct sk_tx_desc) * (SK_TX_RING_CNT - __x),\
172 (ops)); \
173 __n -= (SK_TX_RING_CNT - __x); \
174 __x = 0; \
175 } \
176 \
177 /* Now sync whatever is left. */ \
178 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map, \
179 SK_CDTXOFF((__x)), sizeof(struct sk_tx_desc) * __n, (ops)); \
180 } while (/*CONSTCOND*/0)
181
182 #define SK_CDRXSYNC(sc, x, ops) \
183 do { \
184 bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map, \
185 SK_CDRXOFF((x)), sizeof(struct sk_rx_desc), (ops)); \
186 } while (/*CONSTCOND*/0)
187
188 struct sk_bcom_hack {
189 int reg;
190 int val;
191 };
192
193 #define SK_INC(x, y) (x) = (x + 1) % y
194
195 /* Forward decl. */
196 struct sk_if_softc;
197
198 /* Softc for the GEnesis controller. */
199 struct sk_softc {
200 struct device sk_dev; /* generic device */
201 bus_space_handle_t sk_bhandle; /* bus space handle */
202 bus_space_tag_t sk_btag; /* bus space tag */
203 void *sk_intrhand; /* irq handler handle */
204 struct resource *sk_irq; /* IRQ resource handle */
205 struct resource *sk_res; /* I/O or shared mem handle */
206 u_int8_t sk_type;
207 u_int8_t sk_rev;
208 const char *sk_name;
209 char *sk_vpd_prodname;
210 char *sk_vpd_readonly;
211 u_int32_t sk_rboff; /* RAMbuffer offset */
212 u_int32_t sk_ramsize; /* amount of RAM on NIC */
213 u_int32_t sk_pmd; /* physical media type */
214 u_int32_t sk_intrmask;
215 bus_dma_tag_t sc_dmatag;
216 struct sk_if_softc *sk_if[2];
217 #if NRND > 0
218 rndsource_element_t rnd_source;
219 #endif
220 };
221
222 /* Softc for each logical interface */
223 struct sk_if_softc {
224 struct device sk_dev; /* generic device */
225 struct ethercom sk_ethercom; /* interface info */
226 struct mii_data sk_mii;
227 u_int8_t sk_enaddr[ETHER_ADDR_LEN]; /* station addr */
228 u_int8_t sk_port; /* port # on controller */
229 u_int8_t sk_xmac_rev; /* XMAC chip rev (B2 or C1) */
230 u_int32_t sk_rx_ramstart;
231 u_int32_t sk_rx_ramend;
232 u_int32_t sk_tx_ramstart;
233 u_int32_t sk_tx_ramend;
234 int sk_phytype;
235 int sk_phyaddr;
236 int sk_cnt;
237 int sk_link;
238 struct callout sk_tick_ch;
239 struct sk_chain_data sk_cdata;
240 struct sk_ring_data *sk_rdata;
241 bus_dmamap_t sk_ring_map;
242 struct sk_softc *sk_softc; /* parent controller */
243 int sk_tx_bmu; /* TX BMU register */
244 int sk_if_flags;
245 LIST_HEAD(__sk_jfreehead, sk_jpool_entry) sk_jfree_listhead;
246 LIST_HEAD(__sk_jinusehead, sk_jpool_entry) sk_jinuse_listhead;
247 SIMPLEQ_HEAD(__sk_txmaphead, sk_txmap_entry) sk_txmap_head;
248 };
249
250 struct skc_attach_args {
251 u_int16_t skc_port;
252 };
253
254 #endif /* _DEV_PCI_IF_SKVAR_H_ */
255