xref: /dragonfly/sys/dev/netif/sk/if_skvar.h (revision ce0e08e2)
1 /*-
2  * Copyright (c) 2003 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the NetBSD
16  *	Foundation, Inc. and its contributors.
17  * 4. Neither the name of The NetBSD Foundation nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
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 THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1997, 1998, 1999, 2000
36  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed by Bill Paul.
49  * 4. Neither the name of the author nor the names of any co-contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
57  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
63  * THE POSSIBILITY OF SUCH DAMAGE.
64  *
65  *
66  * $FreeBSD: /c/ncvs/src/sys/pci/if_skreg.h,v 1.9 2000/04/22 02:16:37 wpaul Exp $
67  * $NetBSD: if_skvar.h,v 1.6 2005/05/30 04:35:22 christos Exp $
68  * $OpenBSD: if_skvar.h,v 1.2 2005/12/22 20:54:47 brad Exp $
69  * $DragonFly: src/sys/dev/netif/sk/if_skvar.h,v 1.4 2007/12/14 11:37:11 sephe 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 _IF_SKVAR_H_
89 #define _IF_SKVAR_H_
90 
91 struct sk_jpool_entry {
92 	struct sk_if_softc	*sc_if;
93 	int			inuse;
94 	int			slot;
95 	void			*buf;
96 	bus_addr_t		paddr;
97 	SLIST_ENTRY(sk_jpool_entry) entry_next;
98 };
99 
100 /*
101  * Number of DMA segments in a TxCB. Note that this is carefully
102  * chosen to make the total struct size an even power of two. It's
103  * critical that no TxCB be split across a page boundary since
104  * no attempt is made to allocate physically contiguous memory.
105  */
106 #define SK_NTXSEG      30
107 
108 struct sk_chain_data {
109 	struct mbuf		*sk_tx_mbuf[SK_TX_RING_CNT];
110 	bus_dma_tag_t		sk_tx_dtag;
111 	bus_dmamap_t		sk_tx_dmap[SK_TX_RING_CNT];
112 	int			sk_tx_prod;
113 	int			sk_tx_cons;
114 	int			sk_tx_cnt;
115 
116 	struct mbuf		*sk_rx_mbuf[SK_RX_RING_CNT];
117 	bus_dma_tag_t		sk_rx_dtag;
118 	bus_dmamap_t		sk_rx_dmap[SK_RX_RING_CNT];
119 	bus_dmamap_t		sk_rx_dmap_tmp;
120 	int			sk_rx_prod;
121 	int			sk_rx_cons;
122 	int			sk_rx_cnt;
123 
124 	struct lwkt_serialize	sk_jpool_serializer;
125 	bus_dma_tag_t		sk_jpool_dtag;
126 	bus_dmamap_t		sk_jpool_dmap;
127 	void			*sk_jpool;
128 	struct sk_jpool_entry	sk_jpool_ent[SK_JSLOTS];
129 	SLIST_HEAD(, sk_jpool_entry) sk_jpool_free_ent;
130 };
131 
132 struct sk_ring_data {
133 	struct sk_tx_desc	sk_tx_ring[SK_TX_RING_CNT];
134 	struct sk_rx_desc	sk_rx_ring[SK_RX_RING_CNT];
135 };
136 
137 #define SK_TX_RING_ADDR(sc, i)	\
138     ((sc)->sk_rdata_paddr + offsetof(struct sk_ring_data, sk_tx_ring[(i)]))
139 
140 #define SK_RX_RING_ADDR(sc, i)	\
141     ((sc)->sk_rdata_paddr + offsetof(struct sk_ring_data, sk_rx_ring[(i)]))
142 
143 struct sk_bcom_hack {
144 	int			reg;
145 	int			val;
146 };
147 
148 #define SK_INC(x, y)	(x) = (x + 1) % y
149 
150 /* Forward decl. */
151 struct sk_if_softc;
152 
153 /* Softc for the GEnesis controller. */
154 struct sk_softc {
155 	device_t		sk_dev;
156 	int			sk_res_rid;
157 	struct resource		*sk_res;
158 	bus_space_handle_t	sk_bhandle;	/* bus space handle */
159 	bus_space_tag_t		sk_btag;	/* bus space tag */
160 
161 	int			sk_irq_rid;
162 	struct resource		*sk_irq;
163 	void			*sk_intrhand;	/* irq handler handle */
164 
165 	uint8_t			sk_coppertype;
166 	uint8_t			sk_pmd;		/* physical media type */
167 	uint8_t			sk_type;
168 	uint8_t			sk_rev;
169 	uint8_t			sk_macs;	/* # of MACs */
170 	uint32_t		sk_rboff;	/* RAMbuffer offset */
171 	uint32_t		sk_ramsize;	/* amount of RAM on NIC */
172 	uint32_t		sk_intrmask;
173 	uint32_t		sk_imtimer_ticks;
174 	int			sk_imtime;
175 	struct sysctl_ctx_list	sk_sysctl_ctx;
176 	struct sysctl_oid	*sk_sysctl_tree;
177 	struct lwkt_serialize	sk_serializer;
178 	struct sk_if_softc	*sk_if[2];
179 	device_t		sk_devs[2];
180 };
181 
182 /* Softc for each logical interface */
183 struct sk_if_softc {
184 	struct arpcom		arpcom;		/* interface info */
185 	device_t		sk_miibus;
186 	uint8_t			sk_port;	/* port # on controller */
187 	uint8_t			sk_xmac_rev;	/* XMAC chip rev (B2 or C1) */
188 	uint32_t		sk_rx_ramstart;
189 	uint32_t		sk_rx_ramend;
190 	uint32_t		sk_tx_ramstart;
191 	uint32_t		sk_tx_ramend;
192 	uint8_t			sk_phytype;
193 	int			sk_phyaddr;
194 	int			sk_cnt;
195 	int			sk_link;
196 	struct callout		sk_tick_timer;
197 	struct sk_chain_data	sk_cdata;
198 	struct sk_ring_data	*sk_rdata;
199 	bus_dma_tag_t		sk_rdata_dtag;
200 	bus_dmamap_t		sk_rdata_dmap;
201 	bus_addr_t		sk_rdata_paddr;
202 	struct sk_softc		*sk_softc;	/* parent controller */
203 	int			sk_tx_bmu;	/* TX BMU register */
204 	int			sk_if_flags;
205 	int			sk_use_jumbo;
206 };
207 
208 struct sk_dma_ctx {
209 	int			nsegs;
210 	bus_dma_segment_t	*segs;
211 };
212 
213 #endif /* !_IF_SKVAR_H_ */
214