xref: /openbsd/sys/dev/pci/if_mskvar.h (revision 6a44dfb4)
1 /*	$OpenBSD: if_mskvar.h,v 1.16 2022/01/10 04:47:53 dlg 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_mskvar.h,v 1.16 2022/01/10 04:47:53 dlg 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_MSKVAR_H_
82 #define _DEV_PCI_IF_MSKVAR_H_
83 
84 #define SK_NTXSEG      30
85 
86 struct msk_chain_data {
87 	struct mbuf		*sk_rx_mbuf[MSK_RX_RING_CNT];
88 	bus_dmamap_t		 sk_rx_maps[MSK_RX_RING_CNT];
89 
90 	struct mbuf		*sk_tx_mbuf[MSK_TX_RING_CNT];
91 	bus_dmamap_t		 sk_tx_maps[MSK_TX_RING_CNT];
92 
93 	struct if_rxring	 sk_rx_ring;
94 
95 	unsigned int		 sk_tx_prod;
96 	unsigned int		 sk_tx_cons;
97 	uint32_t		 sk_tx_hiaddr;
98 
99 	unsigned int		 sk_rx_prod;
100 	unsigned int		 sk_rx_cons;
101 	uint32_t		 sk_rx_hiaddr;
102 };
103 
104 struct msk_ring_data {
105 	struct msk_tx_desc	sk_tx_ring[MSK_TX_RING_CNT];
106 	struct msk_rx_desc	sk_rx_ring[MSK_RX_RING_CNT];
107 };
108 
109 #define MSK_TX_RING_ADDR(sc, i) \
110     ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
111      offsetof(struct msk_ring_data, sk_tx_ring[(i)]))
112 
113 #define MSK_RX_RING_ADDR(sc, i) \
114     ((sc)->sk_ring_map->dm_segs[0].ds_addr + \
115      offsetof(struct msk_ring_data, sk_rx_ring[(i)]))
116 
117 #define MSK_CDOFF(x)	offsetof(struct msk_ring_data, x)
118 #define MSK_CDTXOFF(x)	MSK_CDOFF(sk_tx_ring[(x)])
119 #define MSK_CDRXOFF(x)	MSK_CDOFF(sk_rx_ring[(x)])
120 #define MSK_CDSTOFF(x)	((x) * sizeof(uint64_t))
121 
122 #define MSK_CDTXSYNC(sc, x, n, ops)					\
123 do {									\
124 	int __x, __n;							\
125 									\
126 	__x = (x);							\
127 	__n = (n);							\
128 									\
129 	/* If it will wrap around, sync to the end of the ring. */	\
130 	if ((__x + __n) > MSK_TX_RING_CNT) {				\
131 		bus_dmamap_sync((sc)->sk_softc->sc_dmatag,		\
132 		    (sc)->sk_ring_map, MSK_CDTXOFF(__x),		\
133 		    sizeof(struct msk_tx_desc) * (MSK_TX_RING_CNT - __x), \
134 		    (ops));						\
135 		__n -= (MSK_TX_RING_CNT - __x);				\
136 		__x = 0;						\
137 	}								\
138 									\
139 	/* Now sync whatever is left. */				\
140 	bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map,	\
141 	    MSK_CDTXOFF((__x)), sizeof(struct msk_tx_desc) * __n, (ops)); \
142 } while (/*CONSTCOND*/0)
143 
144 #define MSK_CDRXSYNC(sc, x, ops)					\
145 do {									\
146 	bus_dmamap_sync((sc)->sk_softc->sc_dmatag, (sc)->sk_ring_map,	\
147 	    MSK_CDRXOFF((x)), sizeof(struct msk_rx_desc), (ops));	\
148 } while (/*CONSTCOND*/0)
149 
150 #define MSK_CDSTSYNC(sc, x, ops)					\
151 do {									\
152 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sk_status_map,		\
153 	    MSK_CDSTOFF((x)), sizeof(uint64_t), (ops));	\
154 } while (/*CONSTCOND*/0)
155 
156 #define SK_INC(x, y)	(x) = (x + 1) % y
157 
158 /* Forward decl. */
159 struct sk_if_softc;
160 struct msk_kstat;
161 
162 /* Softc for the Yukon-II controller. */
163 struct sk_softc {
164 	struct device		sk_dev;		/* generic device */
165 	bus_space_handle_t	sk_bhandle;	/* bus space handle */
166 	bus_space_tag_t		sk_btag;	/* bus space tag */
167 	bus_size_t		sk_bsize;	/* bus space size */
168 	void			*sk_intrhand;	/* irq handler handle */
169 	pci_chipset_tag_t	sk_pc;
170 	u_int8_t		sk_fibertype;
171 	u_int8_t		sk_type;
172 	u_int8_t		sk_rev;
173 	u_int8_t		sk_macs;	/* # of MACs */
174 	char			*sk_name;
175 	u_int32_t		sk_ramsize;	/* amount of RAM on NIC */
176 	u_int32_t		sk_intrmask;
177 	bus_dma_tag_t		sc_dmatag;
178 	struct sk_if_softc	*sk_if[2];
179 	uint64_t		*sk_status_ring;
180 	bus_dmamap_t		sk_status_map;
181 	bus_dma_segment_t	sk_status_seg;
182 	int			sk_status_nseg;
183 	int			sk_status_idx;
184 };
185 
186 /* Softc for each logical interface */
187 struct sk_if_softc {
188 	struct device		sk_dev;		/* generic device */
189 	struct arpcom		arpcom;		/* interface info */
190 	struct mii_data		sk_mii;
191 	u_int8_t		sk_port;	/* port # on controller */
192 	u_int8_t		sk_xmac_rev;	/* XMAC chip rev (B2 or C1) */
193 	u_int32_t		sk_rx_ramstart;
194 	u_int32_t		sk_rx_ramend;
195 	u_int32_t		sk_tx_ramstart;
196 	u_int32_t		sk_tx_ramend;
197 	int			sk_pktlen;
198 	int			sk_link;
199 	struct timeout		sk_tick_ch;
200 	struct timeout		sk_tick_rx;
201 	struct msk_chain_data	sk_cdata;
202 	struct msk_ring_data	*sk_rdata;
203 	bus_dmamap_t		sk_ring_map;
204 	bus_dma_segment_t	sk_ring_seg;
205 	int			sk_ring_nseg;
206 	int			sk_status_idx;
207 	struct sk_softc		*sk_softc;	/* parent controller */
208 	int			sk_tx_bmu;	/* TX BMU register */
209 	SIMPLEQ_HEAD(__sk_txmaphead, sk_txmap_entry)	sk_txmap_head;
210 
211 	struct msk_kstat	*sk_kstat;
212 };
213 
214 struct skc_attach_args {
215 	u_int16_t	skc_port;
216 	u_int8_t	skc_type;
217 	u_int8_t	skc_rev;
218 };
219 
220 #define MSK_TX_TIMEOUT	5
221 
222 #endif /* _DEV_PCI_IF_MSKVAR_H_ */
223