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