if_le.c revision 1.15 1 /* $NetBSD: if_le.c,v 1.15 1995/09/29 13:51:56 chopps Exp $ */
2
3 /*-
4 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Ralph Campbell and Rick Macklem.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 */
41
42 #include "bpfilter.h"
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mbuf.h>
47 #include <sys/syslog.h>
48 #include <sys/socket.h>
49 #include <sys/device.h>
50
51 #include <net/if.h>
52
53 #ifdef INET
54 #include <netinet/in.h>
55 #include <netinet/if_ether.h>
56 #endif
57
58 #include <machine/cpu.h>
59 #include <machine/mtpr.h>
60
61 #include <amiga/amiga/device.h>
62 #include <amiga/amiga/isr.h>
63 #include <amiga/dev/zbusvar.h>
64 #include <amiga/dev/if_levar.h>
65 #include <dev/ic/am7990reg.h>
66 #include <dev/ic/am7990var.h>
67
68 /* offsets for: ID, REGS, MEM */
69 int lestd[] = { 0, 0x4000, 0x8000 };
70
71 #define LE_SOFTC(unit) lecd.cd_devs[unit]
72 #define LE_DELAY(x) DELAY(x)
73
74 int lematch __P((struct device *, void *, void *));
75 void leattach __P((struct device *, struct device *, void *));
76 int leintr __P((void *));
77
78 struct cfdriver lecd = {
79 NULL, "le", lematch, leattach, DV_IFNET, sizeof(struct le_softc)
80 };
81
82 integrate void
83 lewrcsr(sc, port, val)
84 struct le_softc *sc;
85 u_int16_t port, val;
86 {
87 struct lereg1 *ler1 = sc->sc_r1;
88
89 ler1->ler1_rap = port;
90 ler1->ler1_rdp = val;
91 }
92
93 integrate u_int16_t
94 lerdcsr(sc, port)
95 struct le_softc *sc;
96 u_int16_t port;
97 {
98 struct lereg1 *ler1 = sc->sc_r1;
99 u_int16_t val;
100
101 ler1->ler1_rap = port;
102 val = ler1->ler1_rdp;
103 return (val);
104 }
105
106 int
107 lematch(parent, match, aux)
108 struct device *parent;
109 void *match, *aux;
110 {
111 struct zbus_args *zap = aux;
112
113 /* Commodore ethernet card */
114 if (zap->manid == 514 && zap->prodid == 112)
115 return (1);
116
117 /* Ameristar ethernet card */
118 if (zap->manid == 1053 && zap->prodid == 1)
119 return (1);
120
121 return (0);
122 }
123
124 void
125 leattach(parent, self, aux)
126 struct device *parent, *self;
127 void *aux;
128 {
129 struct le_softc *sc = (void *)self;
130 struct zbus_args *zap = aux;
131 char *cp;
132 int i;
133 u_long ser;
134
135 sc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)zap->va);
136 sc->sc_mem = (void *)(lestd[2] + (int)zap->va);
137
138 sc->sc_copytodesc = copytobuf_contig;
139 sc->sc_copyfromdesc = copyfrombuf_contig;
140 sc->sc_copytobuf = copytobuf_contig;
141 sc->sc_copyfrombuf = copyfrombuf_contig;
142 sc->sc_zerobuf = zerobuf_contig;
143
144 sc->sc_conf3 = LE_C3_BSWP;
145 sc->sc_addr = 0x8000;
146
147 /*
148 * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
149 */
150 switch (zap->manid) {
151 case 514:
152 /* Commodore */
153 sc->sc_memsize = 32768;
154 sc->sc_arpcom.ac_enaddr[0] = 0x00;
155 sc->sc_arpcom.ac_enaddr[1] = 0x80;
156 sc->sc_arpcom.ac_enaddr[2] = 0x10;
157 break;
158
159 case 1053:
160 /* Ameristar */
161 sc->sc_memsize = 32768;
162 sc->sc_arpcom.ac_enaddr[0] = 0x00;
163 sc->sc_arpcom.ac_enaddr[1] = 0x00;
164 sc->sc_arpcom.ac_enaddr[2] = 0x9f;
165 break;
166
167 default:
168 panic("leattach: bad manid");
169 }
170
171 /*
172 * Serial number for board is used as host ID.
173 */
174 ser = (u_long)zap->serno;
175 sc->sc_arpcom.ac_enaddr[3] = (ser >> 16) & 0xff;
176 sc->sc_arpcom.ac_enaddr[4] = (ser >> 8) & 0xff;
177 sc->sc_arpcom.ac_enaddr[5] = (ser ) & 0xff;
178
179 sc->sc_arpcom.ac_if.if_name = lecd.cd_name;
180 leconfig(sc);
181
182 sc->sc_isr.isr_intr = leintr;
183 sc->sc_isr.isr_arg = sc;
184 sc->sc_isr.isr_ipl = 2;
185 add_isr(&sc->sc_isr);
186 }
187
188 /*
189 * Routines for accessing the transmit and receive buffers.
190 */
191
192 void
193 copytobuf_contig(sc, from, boff, len)
194 struct le_softc *sc;
195 caddr_t from;
196 int boff, len;
197 {
198 volatile caddr_t buf = sc->sc_mem;
199
200 /*
201 * Just call bcopy() to do the work.
202 */
203 bcopy(from, buf + boff, len);
204 }
205
206 void
207 copyfrombuf_contig(sc, to, boff, len)
208 struct le_softc *sc;
209 caddr_t to;
210 int boff, len;
211 {
212 volatile caddr_t buf = sc->sc_mem;
213
214 /*
215 * Just call bcopy() to do the work.
216 */
217 bcopy(buf + boff, to, len);
218 }
219
220 void
221 zerobuf_contig(sc, boff, len)
222 struct le_softc *sc;
223 int boff, len;
224 {
225 volatile caddr_t buf = sc->sc_mem;
226
227 /*
228 * Just call bzero() to do the work.
229 */
230 bzero(buf + boff, len);
231 }
232
233 #include <dev/ic/am7990.c>
234