xref: /netbsd-src/sys/dev/pci/if_skvar.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /* $NetBSD: if_skvar.h,v 1.4 2004/09/26 14:23:58 skd 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@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@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 struct sk_jslot {
91 	caddr_t			sk_buf;
92 	int			sk_inuse;
93 };
94 
95 struct sk_jpool_entry {
96 	int                             slot;
97 	LIST_ENTRY(sk_jpool_entry)	jpool_entries;
98 };
99 
100 struct sk_chain {
101 	void			*sk_desc;
102 	struct mbuf		*sk_mbuf;
103 	struct sk_chain		*sk_next;
104 };
105 
106 /*
107  * Number of DMA segments in a TxCB. Note that this is carefully
108  * chosen to make the total struct size an even power of two. It's
109  * critical that no TxCB be split across a page boundary since
110  * no attempt is made to allocate physically contiguous memory.
111  *
112  */
113 #define SK_NTXSEG      30
114 
115 struct sk_txmap_entry {
116 	bus_dmamap_t			dmamap;
117 	SIMPLEQ_ENTRY(sk_txmap_entry)	link;
118 };
119 
120 struct sk_chain_data {
121 	struct sk_chain		sk_tx_chain[SK_TX_RING_CNT];
122 	struct sk_chain		sk_rx_chain[SK_RX_RING_CNT];
123 	struct sk_txmap_entry	*sk_tx_map[SK_TX_RING_CNT];
124 	bus_dmamap_t		sk_rx_map[SK_RX_RING_CNT];
125 	int			sk_tx_prod;
126 	int			sk_tx_cons;
127 	int			sk_tx_cnt;
128 	int			sk_rx_prod;
129 	int			sk_rx_cons;
130 	int			sk_rx_cnt;
131 	/* Stick the jumbo mem management stuff here too. */
132 	struct sk_jslot		sk_jslots[SK_JSLOTS];
133 	void			*sk_jumbo_buf;
134 
135 };
136 
137 struct sk_ring_data {
138 	struct sk_tx_desc	sk_tx_ring[SK_TX_RING_CNT];
139 	struct sk_rx_desc	sk_rx_ring[SK_RX_RING_CNT];
140 };
141 
142 #define SK_TX_RING_ADDR(sc, i) \
143     ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
144      offsetof(struct sk_ring_data, sk_tx_ring[(i)]))
145 
146 #define SK_RX_RING_ADDR(sc, i) \
147     ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
148      offsetof(struct sk_ring_data, sk_rx_ring[(i)]))
149 
150 #define SK_CDOFF(x)	offsetof(struct sk_ring_data, x)
151 #define SK_CDTXOFF(x)	SK_CDOFF(sk_tx_ring[(x)])
152 #define SK_CDRXOFF(x)	SK_CDOFF(sk_rx_ring[(x)])
153 
154 #define SK_CDTXSYNC(sc, x, n, ops)					\
155 do {									\
156 	int __x, __n;							\
157 									\
158 	__x = (x);							\
159 	__n = (n);							\
160 									\
161 	/* If it will wrap around, sync to the end of the ring. */	\
162 	if ((__x + __n) > SK_TX_RING_CNT) {				\
163 		bus_dmamap_sync((sc)->sk_softc->sc_dmatag,		\
164 		    (sc)->sk_ring_map, SK_CDTXOFF(__x),			\
165 		    sizeof(struct sk_tx_desc) *	 (SK_TX_RING_CNT - __x),\
166 		    (ops));						\
167 		__n -= (SK_TX_RING_CNT - __x);				\
168 		__x = 0;						\
169 	}								\
170 									\
171 	/* Now sync whatever is left. */				\
172 	bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map,	\
173 	    SK_CDTXOFF((__x)), sizeof(struct sk_tx_desc) * __n, (ops));	\
174 } while (/*CONSTCOND*/0)
175 
176 #define SK_CDRXSYNC(sc, x, ops)						\
177 do {									\
178 	bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map,	\
179 	    SK_CDRXOFF((x)), sizeof(struct sk_rx_desc), (ops));		\
180 } while (/*CONSTCOND*/0)
181 
182 struct sk_bcom_hack {
183 	int			reg;
184 	int			val;
185 };
186 
187 #define SK_INC(x, y)	(x) = (x + 1) % y
188 
189 /* Forward decl. */
190 struct sk_if_softc;
191 
192 /* Softc for the GEnesis controller. */
193 struct sk_softc {
194 	struct device		sk_dev;		/* generic device */
195 	bus_space_handle_t	sk_bhandle;	/* bus space handle */
196 	bus_space_tag_t		sk_btag;	/* bus space tag */
197 	void			*sk_intrhand;	/* irq handler handle */
198 	struct resource		*sk_irq;	/* IRQ resource handle */
199 	struct resource		*sk_res;	/* I/O or shared mem handle */
200 	u_int8_t		sk_type;
201 	u_int8_t		sk_rev;
202   	char			*sk_name;
203 	char			*sk_vpd_prodname;
204 	char			*sk_vpd_readonly;
205 	u_int32_t		sk_rboff;	/* RAMbuffer offset */
206 	u_int32_t		sk_ramsize;	/* amount of RAM on NIC */
207 	u_int32_t		sk_pmd;		/* physical media type */
208 	u_int32_t		sk_intrmask;
209 	bus_dma_tag_t		sc_dmatag;
210 	struct sk_if_softc	*sk_if[2];
211 };
212 
213 /* Softc for each logical interface */
214 struct sk_if_softc {
215 	struct device		sk_dev;		/* generic device */
216 	struct ethercom		sk_ethercom;	/* interface info */
217 	struct mii_data		sk_mii;
218 	u_int8_t                sk_enaddr[ETHER_ADDR_LEN]; /* station addr */
219 	u_int8_t		sk_port;	/* port # on controller */
220 	u_int8_t		sk_xmac_rev;	/* XMAC chip rev (B2 or C1) */
221 	u_int32_t		sk_rx_ramstart;
222 	u_int32_t		sk_rx_ramend;
223 	u_int32_t		sk_tx_ramstart;
224 	u_int32_t		sk_tx_ramend;
225 	int			sk_phytype;
226 	int			sk_phyaddr;
227 	int			sk_cnt;
228 	int			sk_link;
229 	struct callout		sk_tick_ch;
230 	struct sk_chain_data	sk_cdata;
231 	struct sk_ring_data	*sk_rdata;
232 	bus_dmamap_t		sk_ring_map;
233 	struct sk_softc		*sk_softc;	/* parent controller */
234 	int			sk_tx_bmu;	/* TX BMU register */
235 	int			sk_if_flags;
236 	LIST_HEAD(__sk_jfreehead, sk_jpool_entry)	sk_jfree_listhead;
237 	LIST_HEAD(__sk_jinusehead, sk_jpool_entry)	sk_jinuse_listhead;
238 	SIMPLEQ_HEAD(__sk_txmaphead, sk_txmap_entry) sk_txmap_head;
239 };
240 
241 struct skc_attach_args {
242 	u_int16_t	skc_port;
243 };
244 
245 #endif /* _DEV_PCI_IF_SKVAR_H_ */
246