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