1/*	$NetBSD: midwayvar.h,v 1.10 1997/03/20 21:34:46 chuck Exp $	*/
2
3/*-
4 * Copyright (c) 1996 Charles D. Cranor and Washington University.
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 Charles D. Cranor and
18 *	Washington University.
19 * 4. The name of the author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * $FreeBSD$
34 */
35
36/*
37 * m i d w a y v a r . h
38 *
39 * we define the en_softc here so that bus specific modules can allocate
40 * it as the first item in their softc.
41 *
42 * author: Chuck Cranor <chuck@ccrc.wustl.edu>
43 */
44
45/*
46 * params needed to determine softc size
47 */
48#ifndef EN_NTX
49#define EN_NTX          8       /* number of tx bufs to use */
50#endif
51#ifndef EN_TXSZ
52#define EN_TXSZ         32      /* trasmit buf size in KB */
53#endif
54#ifndef EN_RXSZ
55#define EN_RXSZ         32      /* recv buf size in KB */
56#endif
57
58/* largest possible NRX (depends on RAM size) */
59#define EN_MAXNRX       ((2048 - (EN_NTX * EN_TXSZ)) / EN_RXSZ)
60
61#ifndef EN_MAX_DMASEG
62#define EN_MAX_DMASEG	32
63#endif
64
65/* number of bytes to use in the first receive buffer. This must not be larger
66 * than MHLEN, should be a multiple of 64 and must be a multiple of 4. */
67#define EN_RX1BUF	128
68
69/*
70 * Structure to hold DMA maps. These are handle via a typestable uma zone.
71 */
72struct en_map {
73	uintptr_t	flags;		/* map flags */
74	struct en_map	*rsvd2;		/* see uma_zalloc(9) */
75	struct en_softc	*sc;		/* back pointer */
76	bus_dmamap_t	map;		/* the map */
77};
78#define ENMAP_LOADED	0x02
79#define ENMAP_ALLOC	0x01
80
81#define EN_MAX_MAPS	400
82
83/*
84 * Statistics
85 */
86struct en_stats {
87	uint32_t vtrash;	/* sw copy of counter */
88	uint32_t otrash;	/* sw copy of counter */
89	uint32_t ttrash;	/* # of RBD's with T bit set */
90	uint32_t mfixaddr;	/* # of times we had to mfix an address */
91	uint32_t mfixlen;	/* # of times we had to mfix a lenght*/
92	uint32_t mfixfail;	/* # of times mfix failed */
93	uint32_t txmbovr;	/* # of times we dropped due to mbsize */
94	uint32_t dmaovr;	/* tx dma overflow count */
95	uint32_t txoutspace;	/* out of space in xmit buffer */
96	uint32_t txdtqout;	/* out of DTQs */
97	uint32_t launch;	/* total # of launches */
98	uint32_t hwpull;	/* # of pulls off hardware service list */
99	uint32_t swadd;		/* # of pushes on sw service list */
100	uint32_t rxqnotus;	/* # of times we pull from rx q, but fail */
101	uint32_t rxqus;		/* # of good pulls from rx q */
102	uint32_t rxdrqout;	/* # of times out of DRQs */
103	uint32_t rxmbufout;	/* # of time out of mbufs */
104	uint32_t txnomap;	/* out of DMA maps in TX */
105};
106
107/*
108 * Each of these structures describes one of the eight transmit channels
109 */
110struct en_txslot {
111	uint32_t	mbsize;		/* # mbuf bytes in use (max=TXHIWAT) */
112	uint32_t	bfree;		/* # free bytes in buffer */
113	uint32_t	start;		/* start of buffer area (byte offset) */
114	uint32_t	stop;		/* ends of buffer area (byte offset) */
115	uint32_t	cur;		/* next free area (byte offset) */
116	uint32_t	nref;		/* # of VCs using this channel */
117	struct ifqueue	q;		/* mbufs waiting for DMA now */
118	struct ifqueue	indma;		/* mbufs waiting for DMA now */
119};
120
121/*
122 * Each of these structures is used for each of the receive buffers on the
123 * card.
124 */
125struct en_rxslot {
126	uint32_t	mode;		/* saved copy of mode info */
127	uint32_t	start;		/* begin of my buffer area */
128	uint32_t	stop;		/* end of my buffer area */
129	uint32_t	cur;		/* where I am at in the buffer */
130	struct en_vcc	*vcc;		/* backpointer to VCI */
131	struct ifqueue	q;		/* mbufs waiting for dma now */
132	struct ifqueue	indma;		/* mbufs being dma'd now */
133};
134
135struct en_vcc {
136	struct atmio_vcc vcc;		/* required by common code */
137	void		*rxhand;
138	u_int		vflags;
139	uint32_t	ipackets;
140	uint32_t	opackets;
141	uint32_t	ibytes;
142	uint32_t	obytes;
143
144	uint8_t		txspeed;
145	struct en_txslot *txslot;	/* transmit slot */
146	struct en_rxslot *rxslot;	/* receive slot */
147};
148#define	VCC_DRAIN	0x0001		/* closed, but draining rx */
149#define	VCC_SWSL	0x0002		/* on rx software service list */
150#define	VCC_CLOSE_RX	0x0004		/* currently closing */
151
152/*
153 * softc
154 */
155struct en_softc {
156	struct ifnet	*ifp;
157	device_t dev;
158
159	/* bus glue */
160	bus_space_tag_t en_memt;	/* for EN_READ/EN_WRITE */
161	bus_space_handle_t en_base;	/* base of en card */
162	bus_size_t en_obmemsz;		/* size of en card (bytes) */
163	void (*en_busreset)(void *);	/* bus specific reset function */
164	bus_dma_tag_t txtag;		/* TX DMA tag */
165
166	/* serv list */
167	uint32_t hwslistp;	/* hw pointer to service list (byte offset) */
168	uint16_t swslist[MID_SL_N]; /* software svc list (see en_service()) */
169	uint16_t swsl_head; 	/* ends of swslist (index into swslist) */
170	uint16_t swsl_tail;
171	uint32_t swsl_size;	/* # of items in swsl */
172
173	/* xmit dma */
174	uint32_t dtq[MID_DTQ_N];/* sw copy of dma q (see EN_DQ_MK macros) */
175	uint32_t dtq_free;	/* # of dtq's free */
176	uint32_t dtq_us;	/* software copy of our pointer (byte offset) */
177	uint32_t dtq_chip;	/* chip's pointer (byte offset) */
178	uint32_t need_dtqs;	/* true if we ran out of DTQs */
179
180	/* recv dma */
181	uint32_t drq[MID_DRQ_N];/* sw copy of dma q (see ENIDQ macros) */
182	uint32_t drq_free;	/* # of drq's free */
183	uint32_t drq_us;	/* software copy of our pointer (byte offset) */
184	uint32_t drq_chip;	/* chip's pointer (byte offset) */
185	uint32_t need_drqs;	/* true if we ran out of DRQs */
186
187	/* xmit buf ctrl. (per channel) */
188	struct en_txslot txslot[MID_NTX_CH];
189
190	/* recv buf ctrl. (per recv slot) */
191	struct en_rxslot rxslot[EN_MAXNRX];
192	int en_nrx;			/* # of active rx slots */
193
194	/* vccs */
195	struct en_vcc **vccs;
196	u_int vccs_open;
197	struct cv cv_close;		/* close CV */
198
199	/* stats */
200	struct en_stats stats;
201
202	/* random stuff */
203	uint32_t ipl;		/* sbus interrupt lvl (1 on pci?) */
204	uint8_t bestburstcode;	/* code of best burst we can use */
205	uint8_t bestburstlen;	/* length of best burst (bytes) */
206	uint8_t bestburstshift;	/* (x >> shift) == (x / bestburstlen) */
207	uint8_t bestburstmask;	/* bits to check if not multiple of burst */
208	uint8_t alburst;	/* align dma bursts? */
209	uint8_t noalbursts;	/* don't use unaligned > 4 byte bursts */
210	uint8_t is_adaptec;	/* adaptec version of midway? */
211	struct mbuf *padbuf;	/* buffer of zeros for TX padding */
212
213	/* mutex to protect this structure and the associated hardware */
214	struct mtx en_mtx;
215
216	/* sysctl support */
217	struct sysctl_ctx_list sysctl_ctx;
218	struct sysctl_oid *sysctl_tree;
219
220	/* memory zones */
221	uma_zone_t map_zone;
222
223	/* media and phy */
224	struct ifmedia media;
225	struct utopia utopia;
226
227#ifdef EN_DEBUG
228	/* debugging */
229	u_int debug;
230#endif
231};
232
233/*
234 * exported functions
235 */
236int	en_attach(struct en_softc *);
237void	en_destroy(struct en_softc *);
238void	en_intr(void *);
239void	en_reset(struct en_softc *);
240int	en_modevent(module_t, int, void *arg);
241