xref: /netbsd-src/sys/dev/dec/if_le_dec.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: if_le_dec.c,v 1.19 2008/04/04 12:25:07 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Ralph Campbell and Rick Macklem.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
35  */
36 
37 /*-
38  * Copyright (c) 1997 Jonathan Stone. All rights reserved.
39  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
40  *
41  * This code is derived from software contributed to Berkeley by
42  * Ralph Campbell and Rick Macklem.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *	This product includes software developed by the University of
55  *	California, Berkeley and its contributors.
56  * 4. Neither the name of the University nor the names of its contributors
57  *    may be used to endorse or promote products derived from this software
58  *    without specific prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
73  */
74 
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: if_le_dec.c,v 1.19 2008/04/04 12:25:07 tsutsui Exp $");
77 
78 #include "opt_inet.h"
79 #include "bpfilter.h"
80 
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/mbuf.h>
84 #include <sys/syslog.h>
85 #include <sys/socket.h>
86 #include <sys/device.h>
87 
88 #include <net/if.h>
89 #include <net/if_ether.h>
90 #include <net/if_media.h>
91 
92 #ifdef INET
93 #include <netinet/in.h>
94 #include <netinet/if_inarp.h>
95 #endif
96 
97 #include <dev/ic/lancereg.h>
98 #include <dev/ic/lancevar.h>
99 #include <dev/ic/am7990reg.h>
100 #include <dev/ic/am7990var.h>
101 
102 #include <dev/tc/if_levar.h>
103 #include <dev/tc/tcvar.h>
104 
105 #include <sys/bus.h>
106 
107 /* access LANCE registers */
108 void le_dec_writereg(volatile uint16_t *regptr, uint16_t val);
109 #define	LERDWR(cntl, src, dst)	{ (dst) = (src); tc_mb(); }
110 #define	LEWREG(src, dst)	le_dec_writereg(&(dst), (src))
111 
112 #if defined(_KERNEL_OPT)
113 #include "opt_ddb.h"
114 #endif
115 
116 #ifdef DDB
117 #define	integrate
118 #define hide
119 #else
120 #define	integrate	static inline
121 #define hide		static
122 #endif
123 
124 hide void le_dec_wrcsr(struct lance_softc *, uint16_t, uint16_t);
125 hide uint16_t le_dec_rdcsr(struct lance_softc *, uint16_t);
126 
127 void
128 dec_le_common_attach(struct am7990_softc *sc, uint8_t *eap)
129 {
130 	int i;
131 
132 	sc->lsc.sc_rdcsr = le_dec_rdcsr;
133 	sc->lsc.sc_wrcsr = le_dec_wrcsr;
134 	sc->lsc.sc_hwinit = NULL;
135 
136 	sc->lsc.sc_conf3 = 0;
137 	sc->lsc.sc_addr = 0;
138 	sc->lsc.sc_memsize = 65536;
139 
140 	/*
141 	 * Get the ethernet address out of rom
142 	 */
143 	for (i = 0; i < sizeof(sc->lsc.sc_enaddr); i++) {
144 		sc->lsc.sc_enaddr[i] = *eap;
145 		eap += 4;
146 	}
147 
148 	am7990_config(sc);
149 }
150 
151 hide void
152 le_dec_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
153 {
154 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
155 
156 	LEWREG(port, ler1->ler1_rap);
157 	LERDWR(port, val, ler1->ler1_rdp);
158 }
159 
160 hide uint16_t
161 le_dec_rdcsr(struct lance_softc *sc, uint16_t port)
162 {
163 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
164 	uint16_t val;
165 
166 	LEWREG(port, ler1->ler1_rap);
167 	LERDWR(0, ler1->ler1_rdp, val);
168 	return (val);
169 }
170 
171 /*
172  * Write a lance register port, reading it back to ensure success. This seems
173  * to be necessary during initialization, since the chip appears to be a bit
174  * pokey sometimes.
175  */
176 void
177 le_dec_writereg(volatile uint16_t *regptr, uint16_t val)
178 {
179 	int i = 0;
180 
181 	while (*regptr != val) {
182 		*regptr = val;
183 		tc_mb();
184 		if (++i > 10000) {
185 			printf("le: Reg did not settle (to x%x): x%x\n", val,
186 			    *regptr);
187 			return;
188 		}
189 		DELAY(100);
190 	}
191 }
192 
193 /*
194  * Routines for accessing the transmit and receive buffers are provided
195  * by am7990.c, because of the LE_NEED_BUF_* macros defined above.
196  * Unfortunately, CPU addressing of these buffers is done in one of
197  * 3 ways:
198  * - contiguous (for the 3max and turbochannel option card)
199  * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
200  *   spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
201  * - gap16, which means 16bytes interspersed with 16byte spaces
202  *   for buffers which must begin on a 32byte boundary (for 3min, maxine,
203  *   and alpha)
204  * The buffer offset is the logical byte offset, assuming contiguous storage.
205  */
206