1 /* $NetBSD: if_le_dec.c,v 1.21 2017/06/22 16:46:53 flxd 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.21 2017/06/22 16:46:53 flxd Exp $");
77
78 #include "opt_inet.h"
79
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/mbuf.h>
83 #include <sys/syslog.h>
84 #include <sys/socket.h>
85 #include <sys/device.h>
86
87 #include <net/if.h>
88 #include <net/if_ether.h>
89 #include <net/if_media.h>
90
91 #ifdef INET
92 #include <netinet/in.h>
93 #include <netinet/if_inarp.h>
94 #endif
95
96 #include <dev/ic/lancereg.h>
97 #include <dev/ic/lancevar.h>
98 #include <dev/ic/am7990reg.h>
99 #include <dev/ic/am7990var.h>
100
101 #include <dev/tc/if_levar.h>
102 #include <dev/tc/tcvar.h>
103
104 #include <sys/bus.h>
105
106 /* access LANCE registers */
107 void le_dec_writereg(volatile uint16_t *regptr, uint16_t val);
108 #define LERDWR(cntl, src, dst) { (dst) = (src); tc_mb(); }
109 #define LEWREG(src, dst) le_dec_writereg(&(dst), (src))
110
111 #if defined(_KERNEL_OPT)
112 #include "opt_ddb.h"
113 #endif
114
115 #ifdef DDB
116 #define integrate
117 #define hide
118 #else
119 #define integrate static inline
120 #define hide static
121 #endif
122
123 hide void le_dec_wrcsr(struct lance_softc *, uint16_t, uint16_t);
124 hide uint16_t le_dec_rdcsr(struct lance_softc *, uint16_t);
125
126 void
127 dec_le_common_attach(struct am7990_softc *sc, uint8_t *eap)
128 {
129 int i;
130
131 sc->lsc.sc_rdcsr = le_dec_rdcsr;
132 sc->lsc.sc_wrcsr = le_dec_wrcsr;
133 sc->lsc.sc_hwinit = NULL;
134
135 sc->lsc.sc_conf3 = 0;
136 sc->lsc.sc_addr = 0;
137 sc->lsc.sc_memsize = 65536;
138
139 /*
140 * Get the ethernet address out of rom
141 */
142 for (i = 0; i < sizeof(sc->lsc.sc_enaddr); i++) {
143 sc->lsc.sc_enaddr[i] = *eap;
144 eap += 4;
145 }
146
147 am7990_config(sc);
148 }
149
150 hide void
151 le_dec_wrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
152 {
153 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
154
155 LEWREG(port, ler1->ler1_rap);
156 LERDWR(port, val, ler1->ler1_rdp);
157 }
158
159 hide uint16_t
160 le_dec_rdcsr(struct lance_softc *sc, uint16_t port)
161 {
162 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
163 uint16_t val;
164
165 LEWREG(port, ler1->ler1_rap);
166 LERDWR(0, ler1->ler1_rdp, val);
167 return (val);
168 }
169
170 /*
171 * Write a lance register port, reading it back to ensure success. This seems
172 * to be necessary during initialization, since the chip appears to be a bit
173 * pokey sometimes.
174 */
175 void
176 le_dec_writereg(volatile uint16_t *regptr, uint16_t val)
177 {
178 int i = 0;
179
180 while (*regptr != val) {
181 *regptr = val;
182 tc_mb();
183 if (++i > 10000) {
184 printf("le: Reg did not settle (to x%x): x%x\n", val,
185 *regptr);
186 return;
187 }
188 DELAY(100);
189 }
190 }
191
192 /*
193 * Routines for accessing the transmit and receive buffers are provided
194 * by am7990.c, because of the LE_NEED_BUF_* macros defined above.
195 * Unfortunately, CPU addressing of these buffers is done in one of
196 * 3 ways:
197 * - contiguous (for the 3max and TURBOchannel option card)
198 * - gap2, which means shorts (2 bytes) interspersed with short (2 byte)
199 * spaces (for the pmax, vax 3400, and ioasic LANCE descriptors)
200 * - gap16, which means 16bytes interspersed with 16byte spaces
201 * for buffers which must begin on a 32byte boundary (for 3min, maxine,
202 * and alpha)
203 * The buffer offset is the logical byte offset, assuming contiguous storage.
204 */
Cache object: ad286473d494566a05d49987ac0a936f
|