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