xref: /dragonfly/sys/dev/netif/sk/if_skvar.h (revision 26595b18)
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  */
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 _IF_SKVAR_H_
88 #define _IF_SKVAR_H_
89 
90 struct sk_jpool_entry {
91 	struct sk_if_softc	*sc_if;
92 	int			inuse;
93 	int			slot;
94 	void			*buf;
95 	bus_addr_t		paddr;
96 	SLIST_ENTRY(sk_jpool_entry) entry_next;
97 };
98 
99 /*
100  * Number of DMA segments in a TxCB. Note that this is carefully
101  * chosen to make the total struct size an even power of two. It's
102  * critical that no TxCB be split across a page boundary since
103  * no attempt is made to allocate physically contiguous memory.
104  */
105 #define SK_NTXSEG      30
106 
107 struct sk_chain_data {
108 	bus_dma_tag_t		sk_buf_dtag;
109 
110 	struct mbuf		*sk_tx_mbuf[SK_TX_RING_CNT];
111 	bus_dma_tag_t		sk_tx_dtag;
112 	bus_dmamap_t		sk_tx_dmap[SK_TX_RING_CNT];
113 	int			sk_tx_prod;
114 	int			sk_tx_cons;
115 	int			sk_tx_cnt;
116 
117 	struct mbuf		*sk_rx_mbuf[SK_RX_RING_CNT];
118 	bus_dma_tag_t		sk_rx_dtag;
119 	bus_dmamap_t		sk_rx_dmap[SK_RX_RING_CNT];
120 	bus_dmamap_t		sk_rx_dmap_tmp;
121 	int			sk_rx_prod;
122 	int			sk_rx_cons;
123 	int			sk_rx_cnt;
124 
125 	struct lwkt_serialize	sk_jpool_serializer;
126 	bus_dma_tag_t		sk_jpool_dtag;
127 	bus_dmamap_t		sk_jpool_dmap;
128 	void			*sk_jpool;
129 	struct sk_jpool_entry	sk_jpool_ent[SK_JSLOTS];
130 	SLIST_HEAD(, sk_jpool_entry) sk_jpool_free_ent;
131 };
132 
133 struct sk_ring_data {
134 	bus_dma_tag_t		sk_ring_dtag;
135 
136 	bus_dma_tag_t		sk_tx_ring_dtag;
137 	bus_dmamap_t		sk_tx_ring_dmap;
138 	bus_addr_t		sk_tx_ring_paddr;
139 	struct sk_tx_desc	*sk_tx_ring;
140 
141 	bus_dma_tag_t		sk_rx_ring_dtag;
142 	bus_dmamap_t		sk_rx_ring_dmap;
143 	bus_addr_t		sk_rx_ring_paddr;
144 	struct sk_rx_desc	*sk_rx_ring;
145 };
146 
147 struct sk_bcom_hack {
148 	int			reg;
149 	int			val;
150 };
151 
152 #define SK_INC(x, y)	(x) = (x + 1) % y
153 
154 /* Forward decl. */
155 struct sk_if_softc;
156 
157 /* Softc for the GEnesis controller. */
158 struct sk_softc {
159 	device_t		sk_dev;
160 	int			sk_res_rid;
161 	struct resource		*sk_res;
162 	bus_space_handle_t	sk_bhandle;	/* bus space handle */
163 	bus_space_tag_t		sk_btag;	/* bus space tag */
164 
165 	int			sk_irq_rid;
166 	struct resource		*sk_irq;
167 	void			*sk_intrhand;	/* irq handler handle */
168 
169 	uint8_t			sk_coppertype;
170 	uint8_t			sk_pmd;		/* physical media type */
171 	uint8_t			sk_type;
172 	uint8_t			sk_rev;
173 	uint8_t			sk_macs;	/* # of MACs */
174 	uint32_t		sk_rboff;	/* RAMbuffer offset */
175 	uint32_t		sk_ramsize;	/* amount of RAM on NIC */
176 	uint32_t		sk_intrmask;
177 	uint32_t		sk_imtimer_ticks;
178 	int			sk_imtime;
179 	struct lwkt_serialize	sk_serializer;
180 	struct sk_if_softc	*sk_if[2];
181 	device_t		sk_devs[2];
182 };
183 
184 /* Softc for each logical interface */
185 struct sk_if_softc {
186 	struct arpcom		arpcom;		/* interface info */
187 	device_t		sk_miibus;
188 	uint8_t			sk_port;	/* port # on controller */
189 	uint8_t			sk_xmac_rev;	/* XMAC chip rev (B2 or C1) */
190 	uint32_t		sk_rx_ramstart;
191 	uint32_t		sk_rx_ramend;
192 	uint32_t		sk_tx_ramstart;
193 	uint32_t		sk_tx_ramend;
194 	uint8_t			sk_phytype;
195 	int			sk_phyaddr;
196 	int			sk_cnt;
197 	int			sk_link;
198 	struct callout		sk_tick_timer;
199 	struct sk_chain_data	sk_cdata;
200 	struct sk_ring_data	sk_rdata;
201 	bus_dma_tag_t		sk_parent_dtag;
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 #define SK_NDESC_RESERVE	2
209 #define SK_NDESC_SPARE		5
210 
211 #define SK_IS_OACTIVE(sc_if) \
212 	((sc_if)->sk_cdata.sk_tx_cnt + SK_NDESC_RESERVE + SK_NDESC_SPARE > \
213 	 SK_TX_RING_CNT)
214 
215 #endif /* !_IF_SKVAR_H_ */
216