if_le.c revision 1.24 1 1.24 thorpej /* $NetBSD: if_le.c,v 1.24 1997/03/17 03:17:34 thorpej Exp $ */
2 1.7 cgd
3 1.15 chopps /*-
4 1.15 chopps * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 1.15 chopps * Copyright (c) 1992, 1993
6 1.15 chopps * The Regents of the University of California. All rights reserved.
7 1.15 chopps *
8 1.15 chopps * This code is derived from software contributed to Berkeley by
9 1.15 chopps * Ralph Campbell and Rick Macklem.
10 1.1 mw *
11 1.1 mw * Redistribution and use in source and binary forms, with or without
12 1.1 mw * modification, are permitted provided that the following conditions
13 1.1 mw * are met:
14 1.1 mw * 1. Redistributions of source code must retain the above copyright
15 1.1 mw * notice, this list of conditions and the following disclaimer.
16 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mw * notice, this list of conditions and the following disclaimer in the
18 1.1 mw * documentation and/or other materials provided with the distribution.
19 1.1 mw * 3. All advertising materials mentioning features or use of this software
20 1.1 mw * must display the following acknowledgement:
21 1.1 mw * This product includes software developed by the University of
22 1.1 mw * California, Berkeley and its contributors.
23 1.1 mw * 4. Neither the name of the University nor the names of its contributors
24 1.1 mw * may be used to endorse or promote products derived from this software
25 1.1 mw * without specific prior written permission.
26 1.1 mw *
27 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 mw * SUCH DAMAGE.
38 1.1 mw *
39 1.15 chopps * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 1.1 mw */
41 1.1 mw
42 1.1 mw #include "bpfilter.h"
43 1.1 mw
44 1.5 chopps #include <sys/param.h>
45 1.5 chopps #include <sys/systm.h>
46 1.5 chopps #include <sys/mbuf.h>
47 1.15 chopps #include <sys/syslog.h>
48 1.5 chopps #include <sys/socket.h>
49 1.6 chopps #include <sys/device.h>
50 1.5 chopps
51 1.5 chopps #include <net/if.h>
52 1.23 is #include <net/if_ether.h>
53 1.24 thorpej #include <net/if_media.h>
54 1.1 mw
55 1.1 mw #ifdef INET
56 1.5 chopps #include <netinet/in.h>
57 1.23 is #include <netinet/if_inarp.h>
58 1.1 mw #endif
59 1.1 mw
60 1.5 chopps #include <machine/cpu.h>
61 1.5 chopps #include <machine/mtpr.h>
62 1.15 chopps
63 1.6 chopps #include <amiga/amiga/device.h>
64 1.10 chopps #include <amiga/amiga/isr.h>
65 1.21 thorpej
66 1.21 thorpej #include <dev/ic/am7990reg.h>
67 1.21 thorpej #include <dev/ic/am7990var.h>
68 1.21 thorpej
69 1.9 chopps #include <amiga/dev/zbusvar.h>
70 1.15 chopps #include <amiga/dev/if_levar.h>
71 1.6 chopps
72 1.6 chopps /* offsets for: ID, REGS, MEM */
73 1.6 chopps int lestd[] = { 0, 0x4000, 0x8000 };
74 1.6 chopps
75 1.22 veego int le_zbus_match __P((struct device *, struct cfdata *, void *));
76 1.17 thorpej void le_zbus_attach __P((struct device *, struct device *, void *));
77 1.6 chopps
78 1.17 thorpej struct cfattach le_zbus_ca = {
79 1.17 thorpej sizeof(struct le_softc), le_zbus_match, le_zbus_attach
80 1.17 thorpej };
81 1.17 thorpej
82 1.21 thorpej hide void lewrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
83 1.21 thorpej hide u_int16_t lerdcsr __P((struct am7990_softc *, u_int16_t));
84 1.6 chopps
85 1.21 thorpej hide void
86 1.15 chopps lewrcsr(sc, port, val)
87 1.21 thorpej struct am7990_softc *sc;
88 1.15 chopps u_int16_t port, val;
89 1.15 chopps {
90 1.21 thorpej struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
91 1.6 chopps
92 1.15 chopps ler1->ler1_rap = port;
93 1.15 chopps ler1->ler1_rdp = val;
94 1.15 chopps }
95 1.6 chopps
96 1.21 thorpej hide u_int16_t
97 1.15 chopps lerdcsr(sc, port)
98 1.21 thorpej struct am7990_softc *sc;
99 1.15 chopps u_int16_t port;
100 1.6 chopps {
101 1.21 thorpej struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
102 1.15 chopps u_int16_t val;
103 1.6 chopps
104 1.15 chopps ler1->ler1_rap = port;
105 1.15 chopps val = ler1->ler1_rdp;
106 1.15 chopps return (val);
107 1.15 chopps }
108 1.6 chopps
109 1.15 chopps int
110 1.22 veego le_zbus_match(parent, cfp, aux)
111 1.15 chopps struct device *parent;
112 1.22 veego struct cfdata *cfp;
113 1.22 veego void *aux;
114 1.15 chopps {
115 1.15 chopps struct zbus_args *zap = aux;
116 1.6 chopps
117 1.6 chopps /* Commodore ethernet card */
118 1.15 chopps if (zap->manid == 514 && zap->prodid == 112)
119 1.15 chopps return (1);
120 1.6 chopps
121 1.6 chopps /* Ameristar ethernet card */
122 1.15 chopps if (zap->manid == 1053 && zap->prodid == 1)
123 1.15 chopps return (1);
124 1.6 chopps
125 1.6 chopps return (0);
126 1.6 chopps }
127 1.1 mw
128 1.6 chopps void
129 1.17 thorpej le_zbus_attach(parent, self, aux)
130 1.15 chopps struct device *parent, *self;
131 1.15 chopps void *aux;
132 1.1 mw {
133 1.21 thorpej struct le_softc *lesc = (struct le_softc *)self;
134 1.21 thorpej struct am7990_softc *sc = &lesc->sc_am7990;
135 1.15 chopps struct zbus_args *zap = aux;
136 1.15 chopps u_long ser;
137 1.23 is u_int8_t myaddr[ETHER_ADDR_LEN];
138 1.1 mw
139 1.21 thorpej lesc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)zap->va);
140 1.15 chopps sc->sc_mem = (void *)(lestd[2] + (int)zap->va);
141 1.6 chopps
142 1.18 cgd sc->sc_copytodesc = am7990_copytobuf_contig;
143 1.18 cgd sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
144 1.18 cgd sc->sc_copytobuf = am7990_copytobuf_contig;
145 1.18 cgd sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
146 1.18 cgd sc->sc_zerobuf = am7990_zerobuf_contig;
147 1.6 chopps
148 1.21 thorpej sc->sc_rdcsr = lerdcsr;
149 1.21 thorpej sc->sc_wrcsr = lewrcsr;
150 1.21 thorpej sc->sc_hwinit = NULL;
151 1.21 thorpej
152 1.15 chopps sc->sc_conf3 = LE_C3_BSWP;
153 1.15 chopps sc->sc_addr = 0x8000;
154 1.6 chopps
155 1.6 chopps /*
156 1.6 chopps * Manufacturer decides the 3 first bytes, i.e. ethernet vendor ID.
157 1.6 chopps */
158 1.15 chopps switch (zap->manid) {
159 1.15 chopps case 514:
160 1.15 chopps /* Commodore */
161 1.15 chopps sc->sc_memsize = 32768;
162 1.23 is sc->sc_enaddr[0] = 0x00;
163 1.23 is sc->sc_enaddr[1] = 0x80;
164 1.23 is sc->sc_enaddr[2] = 0x10;
165 1.15 chopps break;
166 1.6 chopps
167 1.15 chopps case 1053:
168 1.15 chopps /* Ameristar */
169 1.15 chopps sc->sc_memsize = 32768;
170 1.23 is sc->sc_enaddr[0] = 0x00;
171 1.23 is sc->sc_enaddr[1] = 0x00;
172 1.23 is sc->sc_enaddr[2] = 0x9f;
173 1.15 chopps break;
174 1.6 chopps
175 1.15 chopps default:
176 1.21 thorpej panic("le_zbus_attach: bad manid");
177 1.1 mw }
178 1.6 chopps
179 1.6 chopps /*
180 1.15 chopps * Serial number for board is used as host ID.
181 1.6 chopps */
182 1.15 chopps ser = (u_long)zap->serno;
183 1.23 is sc->sc_enaddr[3] = (ser >> 16) & 0xff;
184 1.23 is sc->sc_enaddr[4] = (ser >> 8) & 0xff;
185 1.23 is sc->sc_enaddr[5] = (ser ) & 0xff;
186 1.1 mw
187 1.21 thorpej am7990_config(sc);
188 1.6 chopps
189 1.21 thorpej lesc->sc_isr.isr_intr = am7990_intr;
190 1.21 thorpej lesc->sc_isr.isr_arg = sc;
191 1.21 thorpej lesc->sc_isr.isr_ipl = 2;
192 1.21 thorpej add_isr(&lesc->sc_isr);
193 1.1 mw }
194