xref: /freebsd/sys/dev/le/lancevar.h (revision a7ee7a7d6aa723ce89a6853d54056dfec8d403d9)
1a7ee7a7dSMarius Strobl /*	$NetBSD: lancevar.h,v 1.10 2005/12/11 12:21:27 christos Exp $	*/
2a7ee7a7dSMarius Strobl 
3a7ee7a7dSMarius Strobl /*-
4a7ee7a7dSMarius Strobl  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5a7ee7a7dSMarius Strobl  * All rights reserved.
6a7ee7a7dSMarius Strobl  *
7a7ee7a7dSMarius Strobl  * This code is derived from software contributed to The NetBSD Foundation
8a7ee7a7dSMarius Strobl  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9a7ee7a7dSMarius Strobl  * Simulation Facility, NASA Ames Research Center.
10a7ee7a7dSMarius Strobl  *
11a7ee7a7dSMarius Strobl  * Redistribution and use in source and binary forms, with or without
12a7ee7a7dSMarius Strobl  * modification, are permitted provided that the following conditions
13a7ee7a7dSMarius Strobl  * are met:
14a7ee7a7dSMarius Strobl  * 1. Redistributions of source code must retain the above copyright
15a7ee7a7dSMarius Strobl  *    notice, this list of conditions and the following disclaimer.
16a7ee7a7dSMarius Strobl  * 2. Redistributions in binary form must reproduce the above copyright
17a7ee7a7dSMarius Strobl  *    notice, this list of conditions and the following disclaimer in the
18a7ee7a7dSMarius Strobl  *    documentation and/or other materials provided with the distribution.
19a7ee7a7dSMarius Strobl  * 3. All advertising materials mentioning features or use of this software
20a7ee7a7dSMarius Strobl  *    must display the following acknowledgement:
21a7ee7a7dSMarius Strobl  *	This product includes software developed by the NetBSD
22a7ee7a7dSMarius Strobl  *	Foundation, Inc. and its contributors.
23a7ee7a7dSMarius Strobl  * 4. Neither the name of The NetBSD Foundation nor the names of its
24a7ee7a7dSMarius Strobl  *    contributors may be used to endorse or promote products derived
25a7ee7a7dSMarius Strobl  *    from this software without specific prior written permission.
26a7ee7a7dSMarius Strobl  *
27a7ee7a7dSMarius Strobl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28a7ee7a7dSMarius Strobl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29a7ee7a7dSMarius Strobl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30a7ee7a7dSMarius Strobl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31a7ee7a7dSMarius Strobl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32a7ee7a7dSMarius Strobl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33a7ee7a7dSMarius Strobl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34a7ee7a7dSMarius Strobl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35a7ee7a7dSMarius Strobl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36a7ee7a7dSMarius Strobl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37a7ee7a7dSMarius Strobl  * POSSIBILITY OF SUCH DAMAGE.
38a7ee7a7dSMarius Strobl  */
39a7ee7a7dSMarius Strobl 
40a7ee7a7dSMarius Strobl /* $FreeBSD$ */
41a7ee7a7dSMarius Strobl 
42a7ee7a7dSMarius Strobl #ifndef _DEV_LE_LANCEVAR_H_
43a7ee7a7dSMarius Strobl #define	_DEV_LE_LANCEVAR_H_
44a7ee7a7dSMarius Strobl 
45a7ee7a7dSMarius Strobl #define	LE_DRIVER_NAME	"le"
46a7ee7a7dSMarius Strobl 
47a7ee7a7dSMarius Strobl extern devclass_t le_devclass;
48a7ee7a7dSMarius Strobl 
49a7ee7a7dSMarius Strobl struct lance_softc {
50a7ee7a7dSMarius Strobl 	struct ifnet	*sc_ifp;
51a7ee7a7dSMarius Strobl 	struct ifmedia	sc_media;
52a7ee7a7dSMarius Strobl 	struct mtx	sc_mtx;
53a7ee7a7dSMarius Strobl 
54a7ee7a7dSMarius Strobl 	/*
55a7ee7a7dSMarius Strobl 	 * Memory functions:
56a7ee7a7dSMarius Strobl 	 *
57a7ee7a7dSMarius Strobl 	 *	copy to/from descriptor
58a7ee7a7dSMarius Strobl 	 *	copy to/from buffer
59a7ee7a7dSMarius Strobl 	 *	zero bytes in buffer
60a7ee7a7dSMarius Strobl 	 */
61a7ee7a7dSMarius Strobl 	void	(*sc_copytodesc)(struct lance_softc *, void *, int, int);
62a7ee7a7dSMarius Strobl 	void	(*sc_copyfromdesc)(struct lance_softc *, void *, int, int);
63a7ee7a7dSMarius Strobl 	void	(*sc_copytobuf)(struct lance_softc *, void *, int, int);
64a7ee7a7dSMarius Strobl 	void	(*sc_copyfrombuf)(struct lance_softc *, void *, int, int);
65a7ee7a7dSMarius Strobl 	void	(*sc_zerobuf)(struct lance_softc *, int, int);
66a7ee7a7dSMarius Strobl 
67a7ee7a7dSMarius Strobl 	/*
68a7ee7a7dSMarius Strobl 	 * Machine-dependent functions:
69a7ee7a7dSMarius Strobl 	 *
70a7ee7a7dSMarius Strobl 	 *	read/write CSR
71a7ee7a7dSMarius Strobl 	 *	hardware reset hook - may be NULL
72a7ee7a7dSMarius Strobl 	 *	hardware init hook - may be NULL
73a7ee7a7dSMarius Strobl 	 *	no carrier hook - may be NULL
74a7ee7a7dSMarius Strobl 	 *	media change hook - may be NULL
75a7ee7a7dSMarius Strobl 	 */
76a7ee7a7dSMarius Strobl 	uint16_t	(*sc_rdcsr)(struct lance_softc *, uint16_t);
77a7ee7a7dSMarius Strobl 	void	(*sc_wrcsr)(struct lance_softc *, uint16_t, uint16_t);
78a7ee7a7dSMarius Strobl 	void	(*sc_hwreset)(struct lance_softc *);
79a7ee7a7dSMarius Strobl 	void	(*sc_hwinit)(struct lance_softc *);
80a7ee7a7dSMarius Strobl 	int	(*sc_hwintr)(struct lance_softc *);
81a7ee7a7dSMarius Strobl 	void	(*sc_nocarrier)(struct lance_softc *);
82a7ee7a7dSMarius Strobl 	int	(*sc_mediachange)(struct lance_softc *);
83a7ee7a7dSMarius Strobl 	void	(*sc_mediastatus)(struct lance_softc *, struct ifmediareq *);
84a7ee7a7dSMarius Strobl 
85a7ee7a7dSMarius Strobl 	/*
86a7ee7a7dSMarius Strobl 	 * Media-supported by this interface.  If this is NULL,
87a7ee7a7dSMarius Strobl 	 * the only supported media is assumed to be "manual".
88a7ee7a7dSMarius Strobl 	 */
89a7ee7a7dSMarius Strobl 	const int	*sc_supmedia;
90a7ee7a7dSMarius Strobl 	int	sc_nsupmedia;
91a7ee7a7dSMarius Strobl 	int	sc_defaultmedia;
92a7ee7a7dSMarius Strobl 
93a7ee7a7dSMarius Strobl 	uint16_t	sc_conf3;	/* CSR3 value */
94a7ee7a7dSMarius Strobl 
95a7ee7a7dSMarius Strobl 	void	*sc_mem;	/* base address of RAM -- CPU's view */
96a7ee7a7dSMarius Strobl 	u_long	sc_addr;	/* base address of RAM -- LANCE's view */
97a7ee7a7dSMarius Strobl 
98a7ee7a7dSMarius Strobl 	u_long	sc_memsize;	/* size of RAM */
99a7ee7a7dSMarius Strobl 
100a7ee7a7dSMarius Strobl 	int	sc_nrbuf;	/* number of receive buffers */
101a7ee7a7dSMarius Strobl 	int	sc_ntbuf;	/* number of transmit buffers */
102a7ee7a7dSMarius Strobl 	int	sc_last_rd;
103a7ee7a7dSMarius Strobl 	int	sc_first_td;
104a7ee7a7dSMarius Strobl 	int	sc_last_td;
105a7ee7a7dSMarius Strobl 	int	sc_no_td;
106a7ee7a7dSMarius Strobl 
107a7ee7a7dSMarius Strobl 	int	sc_initaddr;
108a7ee7a7dSMarius Strobl 	int	sc_rmdaddr;
109a7ee7a7dSMarius Strobl 	int	sc_tmdaddr;
110a7ee7a7dSMarius Strobl 	int	sc_rbufaddr;
111a7ee7a7dSMarius Strobl 	int	sc_tbufaddr;
112a7ee7a7dSMarius Strobl 
113a7ee7a7dSMarius Strobl 	uint8_t	sc_enaddr[ETHER_ADDR_LEN];
114a7ee7a7dSMarius Strobl 
115a7ee7a7dSMarius Strobl 	void	(*sc_meminit)(struct lance_softc *);
116a7ee7a7dSMarius Strobl 	void	(*sc_start_locked)(struct lance_softc *);
117a7ee7a7dSMarius Strobl 
118a7ee7a7dSMarius Strobl 	int	sc_flags;
119a7ee7a7dSMarius Strobl #define	LE_ALLMULTI	(1 << 0)
120a7ee7a7dSMarius Strobl #define	LE_BSWAP	(1 << 1)
121a7ee7a7dSMarius Strobl #define	LE_CARRIER	(1 << 2)
122a7ee7a7dSMarius Strobl #define	LE_DEBUG	(1 << 3)
123a7ee7a7dSMarius Strobl #define	LE_PROMISC	(1 << 4)
124a7ee7a7dSMarius Strobl };
125a7ee7a7dSMarius Strobl 
126a7ee7a7dSMarius Strobl #define	LE_LOCK_INIT(_sc, _name)					\
127a7ee7a7dSMarius Strobl 	mtx_init(&(_sc)->sc_mtx, _name, MTX_NETWORK_LOCK, MTX_DEF)
128a7ee7a7dSMarius Strobl #define	LE_LOCK_INITIALIZED(_sc)	mtx_initialized(&(_sc)->sc_mtx)
129a7ee7a7dSMarius Strobl #define	LE_LOCK(_sc)			mtx_lock(&(_sc)->sc_mtx)
130a7ee7a7dSMarius Strobl #define	LE_UNLOCK(_sc)			mtx_unlock(&(_sc)->sc_mtx)
131a7ee7a7dSMarius Strobl #define	LE_LOCK_ASSERT(_sc, _what)	mtx_assert(&(_sc)->sc_mtx, (_what))
132a7ee7a7dSMarius Strobl #define	LE_LOCK_DESTROY(_sc)		mtx_destroy(&(_sc)->sc_mtx)
133a7ee7a7dSMarius Strobl 
134a7ee7a7dSMarius Strobl #define	LE_HTOLE16(v)	(((sc)->sc_flags & LE_BSWAP) ? htole16(v) : (v))
135a7ee7a7dSMarius Strobl #define	LE_HTOLE32(v)	(((sc)->sc_flags & LE_BSWAP) ? htole32(v) : (v))
136a7ee7a7dSMarius Strobl #define	LE_LE16TOH(v)	(((sc)->sc_flags & LE_BSWAP) ? le16toh(v) : (v))
137a7ee7a7dSMarius Strobl #define	LE_LE32TOH(v)	(((sc)->sc_flags & LE_BSWAP) ? le32toh(v) : (v))
138a7ee7a7dSMarius Strobl 
139a7ee7a7dSMarius Strobl int lance_config(struct lance_softc *, const char*, int);
140a7ee7a7dSMarius Strobl void lance_attach(struct lance_softc *);
141a7ee7a7dSMarius Strobl void lance_detach(struct lance_softc *);
142a7ee7a7dSMarius Strobl void lance_suspend(struct lance_softc *);
143a7ee7a7dSMarius Strobl void lance_resume(struct lance_softc *);
144a7ee7a7dSMarius Strobl void lance_init_locked(struct lance_softc *);
145a7ee7a7dSMarius Strobl int lance_put(struct lance_softc *, int, struct mbuf *);
146a7ee7a7dSMarius Strobl void lance_read(struct lance_softc *, int, int);
147a7ee7a7dSMarius Strobl void lance_setladrf(struct lance_softc *, u_int16_t *);
148a7ee7a7dSMarius Strobl 
149a7ee7a7dSMarius Strobl /*
150a7ee7a7dSMarius Strobl  * The following functions are only useful on certain CPU/bus
151a7ee7a7dSMarius Strobl  * combinations.  They should be written in assembly language for
152a7ee7a7dSMarius Strobl  * maximum efficiency, but machine-independent versions are provided
153a7ee7a7dSMarius Strobl  * for drivers that have not yet been optimized.
154a7ee7a7dSMarius Strobl  */
155a7ee7a7dSMarius Strobl void lance_copytobuf_contig(struct lance_softc *, void *, int, int);
156a7ee7a7dSMarius Strobl void lance_copyfrombuf_contig(struct lance_softc *, void *, int, int);
157a7ee7a7dSMarius Strobl void lance_zerobuf_contig(struct lance_softc *, int, int);
158a7ee7a7dSMarius Strobl 
159a7ee7a7dSMarius Strobl #if 0	/* Example only - see lance.c */
160a7ee7a7dSMarius Strobl void lance_copytobuf_gap2(struct lance_softc *, void *, int, int);
161a7ee7a7dSMarius Strobl void lance_copyfrombuf_gap2(struct lance_softc *, void *, int, int);
162a7ee7a7dSMarius Strobl void lance_zerobuf_gap2(struct lance_softc *, int, int);
163a7ee7a7dSMarius Strobl 
164a7ee7a7dSMarius Strobl void lance_copytobuf_gap16(struct lance_softc *, void *, int, int);
165a7ee7a7dSMarius Strobl void lance_copyfrombuf_gap16(struct lance_softc *, void *, int, int);
166a7ee7a7dSMarius Strobl void lance_zerobuf_gap16(struct lance_softc *, int, int);
167a7ee7a7dSMarius Strobl #endif /* Example only */
168a7ee7a7dSMarius Strobl 
169a7ee7a7dSMarius Strobl #endif /* _DEV_LE_LANCEVAR_H_ */
170