if_le_ioasic.c revision 1.6 1 /* $NetBSD: if_le_ioasic.c,v 1.6 1997/03/17 03:19:13 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 /*
31 * LANCE on DEC IOCTL ASIC.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/mbuf.h>
37 #include <sys/syslog.h>
38 #include <sys/socket.h>
39 #include <sys/device.h>
40
41 #include <net/if.h>
42 #include <net/if_ether.h>
43 #include <net/if_media.h>
44
45 #ifdef INET
46 #include <netinet/in.h>
47 #include <netinet/if_inarp.h>
48 #endif
49
50 #include <dev/ic/am7990reg.h>
51 #include <dev/ic/am7990var.h>
52
53 #include <dev/tc/if_levar.h>
54 #include <dev/tc/tcvar.h>
55 #include <dev/tc/ioasicvar.h>
56
57 extern caddr_t le_iomem;
58
59 #ifdef __BROKEN_INDIRECT_CONFIG
60 int le_ioasic_match __P((struct device *, void *, void *));
61 #else
62 int le_ioasic_match __P((struct device *, struct cfdata *, void *));
63 #endif
64 void le_ioasic_attach __P((struct device *, struct device *, void *));
65
66 hide void le_ioasic_copytobuf_gap2 __P((struct am7990_softc *, void *,
67 int, int));
68 hide void le_ioasic_copyfrombuf_gap2 __P((struct am7990_softc *, void *,
69 int, int));
70
71 hide void le_ioasic_copytobuf_gap16 __P((struct am7990_softc *, void *,
72 int, int));
73 hide void le_ioasic_copyfrombuf_gap16 __P((struct am7990_softc *, void *,
74 int, int));
75 hide void le_ioasic_zerobuf_gap16 __P((struct am7990_softc *, int, int));
76
77 struct cfattach le_ioasic_ca = {
78 sizeof(struct le_softc), le_ioasic_match, le_ioasic_attach
79 };
80
81 int
82 le_ioasic_match(parent, match, aux)
83 struct device *parent;
84 #ifdef __BROKEN_INDIRECT_CONFIG
85 void *match;
86 #else
87 struct cfdata *match;
88 #endif
89 void *aux;
90 {
91 struct ioasicdev_attach_args *d = aux;
92
93 if (!ioasic_submatch(match, aux))
94 return (0);
95 if (strncmp("lance", d->iada_modname, TC_ROM_LLEN))
96 return (0);
97
98 return (1);
99 }
100
101 void
102 le_ioasic_attach(parent, self, aux)
103 struct device *parent, *self;
104 void *aux;
105 {
106 struct ioasicdev_attach_args *d = aux;
107 register struct le_softc *lesc = (void *)self;
108 register struct am7990_softc *sc = &lesc->sc_am7990;
109
110 lesc->sc_r1 = (struct lereg1 *)
111 TC_DENSE_TO_SPARSE(TC_PHYS_TO_UNCACHED(d->iada_addr));
112 sc->sc_mem = (void *)TC_PHYS_TO_UNCACHED(le_iomem);
113
114 sc->sc_copytodesc = le_ioasic_copytobuf_gap2;
115 sc->sc_copyfromdesc = le_ioasic_copyfrombuf_gap2;
116 sc->sc_copytobuf = le_ioasic_copytobuf_gap16;
117 sc->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
118 sc->sc_zerobuf = le_ioasic_zerobuf_gap16;
119
120 ioasic_lance_dma_setup(le_iomem); /* XXX more thought */
121
122 dec_le_common_attach(sc, ioasic_lance_ether_address());
123
124 ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_NET,
125 am7990_intr, sc);
126 }
127
128 /*
129 * Special memory access functions needed by ioasic-attached LANCE
130 * chips.
131 */
132
133 /*
134 * gap2: two bytes of data followed by two bytes of pad.
135 *
136 * Buffers must be 4-byte aligned. The code doesn't worry about
137 * doing an extra byte.
138 */
139
140 void
141 le_ioasic_copytobuf_gap2(sc, fromv, boff, len)
142 struct am7990_softc *sc;
143 void *fromv;
144 int boff;
145 register int len;
146 {
147 volatile caddr_t buf = sc->sc_mem;
148 register caddr_t from = fromv;
149 register volatile u_int16_t *bptr;
150
151 if (boff & 0x1) {
152 /* handle unaligned first byte */
153 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
154 *bptr = (*from++ << 8) | (*bptr & 0xff);
155 bptr += 2;
156 len--;
157 } else
158 bptr = ((volatile u_int16_t *)buf) + boff;
159 while (len > 1) {
160 *bptr = (from[1] << 8) | (from[0] & 0xff);
161 bptr += 2;
162 from += 2;
163 len -= 2;
164 }
165 if (len == 1)
166 *bptr = (u_int16_t)*from;
167 }
168
169 void
170 le_ioasic_copyfrombuf_gap2(sc, tov, boff, len)
171 struct am7990_softc *sc;
172 void *tov;
173 int boff, len;
174 {
175 volatile caddr_t buf = sc->sc_mem;
176 register caddr_t to = tov;
177 register volatile u_int16_t *bptr;
178 register u_int16_t tmp;
179
180 if (boff & 0x1) {
181 /* handle unaligned first byte */
182 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
183 *to++ = (*bptr >> 8) & 0xff;
184 bptr += 2;
185 len--;
186 } else
187 bptr = ((volatile u_int16_t *)buf) + boff;
188 while (len > 1) {
189 tmp = *bptr;
190 *to++ = tmp & 0xff;
191 *to++ = (tmp >> 8) & 0xff;
192 bptr += 2;
193 len -= 2;
194 }
195 if (len == 1)
196 *to = *bptr & 0xff;
197 }
198
199 /*
200 * gap16: 16 bytes of data followed by 16 bytes of pad.
201 *
202 * Buffers must be 32-byte aligned.
203 */
204
205 void
206 le_ioasic_copytobuf_gap16(sc, fromv, boff, len)
207 struct am7990_softc *sc;
208 void *fromv;
209 int boff;
210 register int len;
211 {
212 volatile caddr_t buf = sc->sc_mem;
213 register caddr_t from = fromv;
214 register caddr_t bptr;
215 register int xfer;
216
217 bptr = buf + ((boff << 1) & ~0x1f);
218 boff &= 0xf;
219 xfer = min(len, 16 - boff);
220 while (len > 0) {
221 bcopy(from, bptr + boff, xfer);
222 from += xfer;
223 bptr += 32;
224 boff = 0;
225 len -= xfer;
226 xfer = min(len, 16);
227 }
228 }
229
230 void
231 le_ioasic_copyfrombuf_gap16(sc, tov, boff, len)
232 struct am7990_softc *sc;
233 void *tov;
234 int boff, len;
235 {
236 volatile caddr_t buf = sc->sc_mem;
237 register caddr_t to = tov;
238 register caddr_t bptr;
239 register int xfer;
240
241 bptr = buf + ((boff << 1) & ~0x1f);
242 boff &= 0xf;
243 xfer = min(len, 16 - boff);
244 while (len > 0) {
245 bcopy(bptr + boff, to, xfer);
246 to += xfer;
247 bptr += 32;
248 boff = 0;
249 len -= xfer;
250 xfer = min(len, 16);
251 }
252 }
253
254 void
255 le_ioasic_zerobuf_gap16(sc, boff, len)
256 struct am7990_softc *sc;
257 int boff, len;
258 {
259 volatile caddr_t buf = sc->sc_mem;
260 register caddr_t bptr;
261 register int xfer;
262
263 bptr = buf + ((boff << 1) & ~0x1f);
264 boff &= 0xf;
265 xfer = min(len, 16 - boff);
266 while (len > 0) {
267 bzero(bptr + boff, xfer);
268 bptr += 32;
269 boff = 0;
270 len -= xfer;
271 xfer = min(len, 16);
272 }
273 }
274