if_le.c revision 1.27 1 1.27 cgd /* $NetBSD: if_le.c,v 1.27 1996/04/18 00:25:25 cgd Exp $ */
2 1.12 cgd
3 1.24 mycroft /*-
4 1.24 mycroft * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 1.24 mycroft * Copyright (c) 1992, 1993
6 1.24 mycroft * The Regents of the University of California. All rights reserved.
7 1.1 glass *
8 1.24 mycroft * This code is derived from software contributed to Berkeley by
9 1.24 mycroft * Ralph Campbell and Rick Macklem.
10 1.1 glass *
11 1.24 mycroft * Redistribution and use in source and binary forms, with or without
12 1.24 mycroft * modification, are permitted provided that the following conditions
13 1.24 mycroft * are met:
14 1.24 mycroft * 1. Redistributions of source code must retain the above copyright
15 1.24 mycroft * notice, this list of conditions and the following disclaimer.
16 1.24 mycroft * 2. Redistributions in binary form must reproduce the above copyright
17 1.24 mycroft * notice, this list of conditions and the following disclaimer in the
18 1.24 mycroft * documentation and/or other materials provided with the distribution.
19 1.24 mycroft * 3. All advertising materials mentioning features or use of this software
20 1.24 mycroft * must display the following acknowledgement:
21 1.24 mycroft * This product includes software developed by the University of
22 1.24 mycroft * California, Berkeley and its contributors.
23 1.24 mycroft * 4. Neither the name of the University nor the names of its contributors
24 1.24 mycroft * may be used to endorse or promote products derived from this software
25 1.24 mycroft * without specific prior written permission.
26 1.24 mycroft *
27 1.24 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.24 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.24 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.24 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.24 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.24 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.24 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.24 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.24 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.24 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.24 mycroft * SUCH DAMAGE.
38 1.24 mycroft *
39 1.24 mycroft * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 1.1 glass */
41 1.1 glass
42 1.1 glass #include "bpfilter.h"
43 1.1 glass
44 1.8 glass #include <sys/param.h>
45 1.8 glass #include <sys/systm.h>
46 1.8 glass #include <sys/mbuf.h>
47 1.24 mycroft #include <sys/syslog.h>
48 1.8 glass #include <sys/socket.h>
49 1.16 gwr #include <sys/device.h>
50 1.8 glass
51 1.8 glass #include <net/if.h>
52 1.10 gwr
53 1.1 glass #ifdef INET
54 1.8 glass #include <netinet/in.h>
55 1.8 glass #include <netinet/if_ether.h>
56 1.1 glass #endif
57 1.1 glass
58 1.8 glass #include <machine/autoconf.h>
59 1.10 gwr #include <machine/cpu.h>
60 1.24 mycroft #include <machine/dvma.h>
61 1.24 mycroft #include <machine/isr.h>
62 1.24 mycroft #include <machine/obio.h>
63 1.24 mycroft #include <machine/idprom.h>
64 1.24 mycroft
65 1.24 mycroft #include <sun3/dev/if_lereg.h>
66 1.24 mycroft #include <sun3/dev/if_levar.h>
67 1.24 mycroft #include <dev/ic/am7990reg.h>
68 1.24 mycroft #define LE_NEED_BUF_CONTIG
69 1.24 mycroft #include <dev/ic/am7990var.h>
70 1.24 mycroft
71 1.25 thorpej #define LE_SOFTC(unit) le_cd.cd_devs[unit]
72 1.24 mycroft #define LE_DELAY(x) DELAY(x)
73 1.24 mycroft
74 1.26 gwr static int le_match __P((struct device *, void *, void *));
75 1.26 gwr static void le_attach __P((struct device *, struct device *, void *));
76 1.24 mycroft int leintr __P((void *));
77 1.10 gwr
78 1.25 thorpej struct cfattach le_ca = {
79 1.26 gwr sizeof(struct le_softc), le_match, le_attach
80 1.25 thorpej };
81 1.25 thorpej
82 1.25 thorpej struct cfdriver le_cd = {
83 1.25 thorpej NULL, "le", DV_IFNET
84 1.10 gwr };
85 1.10 gwr
86 1.24 mycroft integrate void
87 1.24 mycroft lewrcsr(sc, port, val)
88 1.16 gwr struct le_softc *sc;
89 1.24 mycroft u_int16_t port, val;
90 1.16 gwr {
91 1.24 mycroft register struct lereg1 *ler1 = sc->sc_r1;
92 1.16 gwr
93 1.24 mycroft ler1->ler1_rap = port;
94 1.24 mycroft ler1->ler1_rdp = val;
95 1.16 gwr }
96 1.16 gwr
97 1.24 mycroft integrate u_int16_t
98 1.24 mycroft lerdcsr(sc, port)
99 1.16 gwr struct le_softc *sc;
100 1.24 mycroft u_int16_t port;
101 1.16 gwr {
102 1.24 mycroft register struct lereg1 *ler1 = sc->sc_r1;
103 1.24 mycroft u_int16_t val;
104 1.16 gwr
105 1.24 mycroft ler1->ler1_rap = port;
106 1.24 mycroft val = ler1->ler1_rdp;
107 1.24 mycroft return (val);
108 1.16 gwr }
109 1.16 gwr
110 1.24 mycroft int
111 1.26 gwr le_match(parent, vcf, aux)
112 1.24 mycroft struct device *parent;
113 1.26 gwr void *vcf, *aux;
114 1.10 gwr {
115 1.26 gwr struct cfdata *cf = vcf;
116 1.16 gwr struct confargs *ca = aux;
117 1.26 gwr int pa, x;
118 1.18 gwr
119 1.26 gwr /*
120 1.26 gwr * OBIO match functions may be called for every possible
121 1.26 gwr * physical address, so match only our physical address.
122 1.26 gwr */
123 1.26 gwr if ((pa = cf->cf_paddr) == -1) {
124 1.26 gwr /* Use our default PA. */
125 1.26 gwr pa = OBIO_AMD_ETHER;
126 1.26 gwr }
127 1.26 gwr if (pa != ca->ca_paddr)
128 1.26 gwr return (0);
129 1.23 gwr
130 1.24 mycroft /* The peek returns -1 on bus error. */
131 1.24 mycroft x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
132 1.24 mycroft return (x != -1);
133 1.1 glass }
134 1.1 glass
135 1.10 gwr void
136 1.26 gwr le_attach(parent, self, aux)
137 1.24 mycroft struct device *parent, *self;
138 1.24 mycroft void *aux;
139 1.10 gwr {
140 1.24 mycroft struct le_softc *sc = (void *)self;
141 1.26 gwr struct cfdata *cf = self->dv_cfdata;
142 1.24 mycroft struct confargs *ca = aux;
143 1.26 gwr int intpri;
144 1.26 gwr
145 1.26 gwr /* Default interrupt level. */
146 1.26 gwr if ((intpri = cf->cf_intpri) == -1)
147 1.26 gwr intpri = 3;
148 1.26 gwr printf(" level %d", intpri);
149 1.10 gwr
150 1.24 mycroft sc->sc_r1 = (struct lereg1 *)
151 1.24 mycroft obio_alloc(ca->ca_paddr, OBIO_AMD_ETHER_SIZE);
152 1.26 gwr
153 1.26 gwr sc->sc_memsize = 0x4000; /* 16K */
154 1.26 gwr sc->sc_mem = dvma_malloc(sc->sc_memsize);
155 1.26 gwr sc->sc_addr = (u_long)sc->sc_mem & 0xffffff;
156 1.24 mycroft sc->sc_conf3 = LE_C3_BSWP;
157 1.1 glass
158 1.24 mycroft idprom_etheraddr(sc->sc_arpcom.ac_enaddr);
159 1.1 glass
160 1.27 cgd sc->sc_copytodesc = am7990_copytobuf_contig;
161 1.27 cgd sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
162 1.27 cgd sc->sc_copytobuf = am7990_copytobuf_contig;
163 1.27 cgd sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
164 1.27 cgd sc->sc_zerobuf = am7990_zerobuf_contig;
165 1.1 glass
166 1.25 thorpej sc->sc_arpcom.ac_if.if_name = le_cd.cd_name;
167 1.24 mycroft leconfig(sc);
168 1.16 gwr
169 1.24 mycroft /* Install interrupt handler. */
170 1.26 gwr isr_add_autovect(leintr, (void *)sc, intpri);
171 1.26 gwr }
172 1.26 gwr
173 1.26 gwr /*
174 1.26 gwr * Compare two Ether/802 addresses for equality, inlined and
175 1.26 gwr * unrolled for speed. I'd love to have an inline assembler
176 1.26 gwr * version of this... XXX: Who wanted that? mycroft?
177 1.26 gwr * I wrote one, but the following is just as efficient.
178 1.26 gwr * This expands to 10 short m68k instructions! -gwr
179 1.26 gwr * Note: use this like bcmp()
180 1.26 gwr */
181 1.26 gwr static inline u_short
182 1.26 gwr ether_cmp(one, two)
183 1.26 gwr u_char *one, *two;
184 1.26 gwr {
185 1.26 gwr register u_short *a = (u_short *) one;
186 1.26 gwr register u_short *b = (u_short *) two;
187 1.26 gwr register u_short diff;
188 1.26 gwr
189 1.26 gwr diff = *a++ - *b++;
190 1.26 gwr diff |= *a++ - *b++;
191 1.26 gwr diff |= *a++ - *b++;
192 1.26 gwr
193 1.26 gwr return (diff);
194 1.1 glass }
195 1.26 gwr
196 1.26 gwr #define ETHER_CMP ether_cmp
197 1.1 glass
198 1.24 mycroft #include <dev/ic/am7990.c>
199