if_le.c revision 1.26 1 /* $NetBSD: if_le.c,v 1.26 1996/03/26 14:42:18 gwr 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/autoconf.h>
59 #include <machine/cpu.h>
60 #include <machine/dvma.h>
61 #include <machine/isr.h>
62 #include <machine/obio.h>
63 #include <machine/idprom.h>
64
65 #include <sun3/dev/if_lereg.h>
66 #include <sun3/dev/if_levar.h>
67 #include <dev/ic/am7990reg.h>
68 #define LE_NEED_BUF_CONTIG
69 #include <dev/ic/am7990var.h>
70
71 #define LE_SOFTC(unit) le_cd.cd_devs[unit]
72 #define LE_DELAY(x) DELAY(x)
73
74 static int le_match __P((struct device *, void *, void *));
75 static void le_attach __P((struct device *, struct device *, void *));
76 int leintr __P((void *));
77
78 struct cfattach le_ca = {
79 sizeof(struct le_softc), le_match, le_attach
80 };
81
82 struct cfdriver le_cd = {
83 NULL, "le", DV_IFNET
84 };
85
86 integrate void
87 lewrcsr(sc, port, val)
88 struct le_softc *sc;
89 u_int16_t port, val;
90 {
91 register struct lereg1 *ler1 = sc->sc_r1;
92
93 ler1->ler1_rap = port;
94 ler1->ler1_rdp = val;
95 }
96
97 integrate u_int16_t
98 lerdcsr(sc, port)
99 struct le_softc *sc;
100 u_int16_t port;
101 {
102 register struct lereg1 *ler1 = sc->sc_r1;
103 u_int16_t val;
104
105 ler1->ler1_rap = port;
106 val = ler1->ler1_rdp;
107 return (val);
108 }
109
110 int
111 le_match(parent, vcf, aux)
112 struct device *parent;
113 void *vcf, *aux;
114 {
115 struct cfdata *cf = vcf;
116 struct confargs *ca = aux;
117 int pa, x;
118
119 /*
120 * OBIO match functions may be called for every possible
121 * physical address, so match only our physical address.
122 */
123 if ((pa = cf->cf_paddr) == -1) {
124 /* Use our default PA. */
125 pa = OBIO_AMD_ETHER;
126 }
127 if (pa != ca->ca_paddr)
128 return (0);
129
130 /* The peek returns -1 on bus error. */
131 x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
132 return (x != -1);
133 }
134
135 void
136 le_attach(parent, self, aux)
137 struct device *parent, *self;
138 void *aux;
139 {
140 struct le_softc *sc = (void *)self;
141 struct cfdata *cf = self->dv_cfdata;
142 struct confargs *ca = aux;
143 int intpri;
144
145 /* Default interrupt level. */
146 if ((intpri = cf->cf_intpri) == -1)
147 intpri = 3;
148 printf(" level %d", intpri);
149
150 sc->sc_r1 = (struct lereg1 *)
151 obio_alloc(ca->ca_paddr, OBIO_AMD_ETHER_SIZE);
152
153 sc->sc_memsize = 0x4000; /* 16K */
154 sc->sc_mem = dvma_malloc(sc->sc_memsize);
155 sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
156 sc->sc_conf3 = LE_C3_BSWP;
157
158 idprom_etheraddr(sc->sc_arpcom.ac_enaddr);
159
160 sc->sc_copytodesc = copytobuf_contig;
161 sc->sc_copyfromdesc = copyfrombuf_contig;
162 sc->sc_copytobuf = copytobuf_contig;
163 sc->sc_copyfrombuf = copyfrombuf_contig;
164 sc->sc_zerobuf = zerobuf_contig;
165
166 sc->sc_arpcom.ac_if.if_name = le_cd.cd_name;
167 leconfig(sc);
168
169 /* Install interrupt handler. */
170 isr_add_autovect(leintr, (void *)sc, intpri);
171 }
172
173 /*
174 * Compare two Ether/802 addresses for equality, inlined and
175 * unrolled for speed. I'd love to have an inline assembler
176 * version of this... XXX: Who wanted that? mycroft?
177 * I wrote one, but the following is just as efficient.
178 * This expands to 10 short m68k instructions! -gwr
179 * Note: use this like bcmp()
180 */
181 static inline u_short
182 ether_cmp(one, two)
183 u_char *one, *two;
184 {
185 register u_short *a = (u_short *) one;
186 register u_short *b = (u_short *) two;
187 register u_short diff;
188
189 diff = *a++ - *b++;
190 diff |= *a++ - *b++;
191 diff |= *a++ - *b++;
192
193 return (diff);
194 }
195
196 #define ETHER_CMP ether_cmp
197
198 #include <dev/ic/am7990.c>
199