if_le_ioasic.c revision 1.3 1 /* $NetBSD: if_le_ioasic.c,v 1.3 1996/12/05 01:25:33 cgd 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
43 #ifdef INET
44 #include <netinet/in.h>
45 #include <netinet/if_ether.h>
46 #endif
47
48 #include <dev/ic/am7990reg.h>
49 #include <dev/ic/am7990var.h>
50
51 #include <dev/tc/if_levar.h>
52 #include <dev/tc/tcvar.h>
53 #include <dev/tc/ioasicvar.h>
54
55 extern caddr_t le_iomem;
56
57 #ifdef __BROKEN_INDIRECT_CONFIG
58 int le_ioasic_match __P((struct device *, void *, void *));
59 #else
60 int le_ioasic_match __P((struct device *, struct cfdata *, void *));
61 #endif
62 void le_ioasic_attach __P((struct device *, struct device *, void *));
63
64 hide void le_ioasic_copytobuf_gap2 __P((struct am7990_softc *, void *,
65 int, int));
66 hide void le_ioasic_copyfrombuf_gap2 __P((struct am7990_softc *, void *,
67 int, int));
68
69 hide void le_ioasic_copytobuf_gap16 __P((struct am7990_softc *, void *,
70 int, int));
71 hide void le_ioasic_copyfrombuf_gap16 __P((struct am7990_softc *, void *,
72 int, int));
73 hide void le_ioasic_zerobuf_gap16 __P((struct am7990_softc *, int, int));
74
75 struct cfattach le_ioasic_ca = {
76 sizeof(struct le_softc), le_ioasic_match, le_ioasic_attach
77 };
78
79 int
80 le_ioasic_match(parent, match, aux)
81 struct device *parent;
82 #ifdef __BROKEN_INDIRECT_CONFIG
83 void *match;
84 #else
85 struct cfdata *match;
86 #endif
87 void *aux;
88 {
89 struct ioasicdev_attach_args *d = aux;
90
91 if (!ioasic_submatch(match, aux))
92 return (0);
93 if (strncmp("lance", d->iada_modname, TC_ROM_LLEN))
94 return (0);
95
96 return (1);
97 }
98
99 void
100 le_ioasic_attach(parent, self, aux)
101 struct device *parent, *self;
102 void *aux;
103 {
104 struct ioasicdev_attach_args *d = aux;
105 register struct le_softc *lesc = (void *)self;
106 register struct am7990_softc *sc = &lesc->sc_am7990;
107
108 lesc->sc_r1 = (struct lereg1 *)
109 TC_DENSE_TO_SPARSE(TC_PHYS_TO_UNCACHED(d->iada_addr));
110 sc->sc_mem = (void *)TC_PHYS_TO_UNCACHED(le_iomem);
111
112 sc->sc_copytodesc = le_ioasic_copytobuf_gap2;
113 sc->sc_copyfromdesc = le_ioasic_copyfrombuf_gap2;
114 sc->sc_copytobuf = le_ioasic_copytobuf_gap16;
115 sc->sc_copyfrombuf = le_ioasic_copyfrombuf_gap16;
116 sc->sc_zerobuf = le_ioasic_zerobuf_gap16;
117
118 ioasic_lance_dma_setup(le_iomem); /* XXX more thought */
119
120 dec_le_common_attach(sc, ioasic_lance_ether_address());
121
122 ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_NET,
123 am7990_intr, sc);
124 }
125
126 /*
127 * Special memory access functions needed by ioasic-attached LANCE
128 * chips.
129 */
130
131 /*
132 * gap2: two bytes of data followed by two bytes of pad.
133 *
134 * Buffers must be 4-byte aligned. The code doesn't worry about
135 * doing an extra byte.
136 */
137
138 void
139 le_ioasic_copytobuf_gap2(sc, fromv, boff, len)
140 struct am7990_softc *sc;
141 void *fromv;
142 int boff;
143 register int len;
144 {
145 volatile caddr_t buf = sc->sc_mem;
146 register caddr_t from = fromv;
147 register volatile u_int16_t *bptr;
148
149 if (boff & 0x1) {
150 /* handle unaligned first byte */
151 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
152 *bptr = (*from++ << 8) | (*bptr & 0xff);
153 bptr += 2;
154 len--;
155 } else
156 bptr = ((volatile u_int16_t *)buf) + boff;
157 while (len > 1) {
158 *bptr = (from[1] << 8) | (from[0] & 0xff);
159 bptr += 2;
160 from += 2;
161 len -= 2;
162 }
163 if (len == 1)
164 *bptr = (u_int16_t)*from;
165 }
166
167 void
168 le_ioasic_copyfrombuf_gap2(sc, tov, boff, len)
169 struct am7990_softc *sc;
170 void *tov;
171 int boff, len;
172 {
173 volatile caddr_t buf = sc->sc_mem;
174 register caddr_t to = tov;
175 register volatile u_int16_t *bptr;
176 register u_int16_t tmp;
177
178 if (boff & 0x1) {
179 /* handle unaligned first byte */
180 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
181 *to++ = (*bptr >> 8) & 0xff;
182 bptr += 2;
183 len--;
184 } else
185 bptr = ((volatile u_int16_t *)buf) + boff;
186 while (len > 1) {
187 tmp = *bptr;
188 *to++ = tmp & 0xff;
189 *to++ = (tmp >> 8) & 0xff;
190 bptr += 2;
191 len -= 2;
192 }
193 if (len == 1)
194 *to = *bptr & 0xff;
195 }
196
197 /*
198 * gap16: 16 bytes of data followed by 16 bytes of pad.
199 *
200 * Buffers must be 32-byte aligned.
201 */
202
203 void
204 le_ioasic_copytobuf_gap16(sc, fromv, boff, len)
205 struct am7990_softc *sc;
206 void *fromv;
207 int boff;
208 register int len;
209 {
210 volatile caddr_t buf = sc->sc_mem;
211 register caddr_t from = fromv;
212 register caddr_t bptr;
213 register int xfer;
214
215 bptr = buf + ((boff << 1) & ~0x1f);
216 boff &= 0xf;
217 xfer = min(len, 16 - boff);
218 while (len > 0) {
219 bcopy(from, bptr + boff, xfer);
220 from += xfer;
221 bptr += 32;
222 boff = 0;
223 len -= xfer;
224 xfer = min(len, 16);
225 }
226 }
227
228 void
229 le_ioasic_copyfrombuf_gap16(sc, tov, boff, len)
230 struct am7990_softc *sc;
231 void *tov;
232 int boff, len;
233 {
234 volatile caddr_t buf = sc->sc_mem;
235 register caddr_t to = tov;
236 register caddr_t bptr;
237 register int xfer;
238
239 bptr = buf + ((boff << 1) & ~0x1f);
240 boff &= 0xf;
241 xfer = min(len, 16 - boff);
242 while (len > 0) {
243 bcopy(bptr + boff, to, xfer);
244 to += xfer;
245 bptr += 32;
246 boff = 0;
247 len -= xfer;
248 xfer = min(len, 16);
249 }
250 }
251
252 void
253 le_ioasic_zerobuf_gap16(sc, boff, len)
254 struct am7990_softc *sc;
255 int boff, len;
256 {
257 volatile caddr_t buf = sc->sc_mem;
258 register caddr_t bptr;
259 register int xfer;
260
261 bptr = buf + ((boff << 1) & ~0x1f);
262 boff &= 0xf;
263 xfer = min(len, 16 - boff);
264 while (len > 0) {
265 bzero(bptr + boff, xfer);
266 bptr += 32;
267 boff = 0;
268 len -= xfer;
269 xfer = min(len, 16);
270 }
271 }
272