if_le.c revision 1.4 1 1.4 lukem /* $NetBSD: if_le.c,v 1.4 2003/07/15 01:29:21 lukem Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1997, 1999
5 1.1 drochner * Matthias Drochner. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner *
16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 drochner *
27 1.1 drochner */
28 1.4 lukem
29 1.4 lukem #include <sys/cdefs.h>
30 1.4 lukem __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.4 2003/07/15 01:29:21 lukem Exp $");
31 1.1 drochner
32 1.1 drochner #include "opt_inet.h"
33 1.1 drochner
34 1.1 drochner #include <sys/param.h>
35 1.1 drochner #include <sys/systm.h>
36 1.1 drochner #include <sys/socket.h>
37 1.1 drochner #include <sys/device.h>
38 1.1 drochner
39 1.1 drochner #include <net/if.h>
40 1.1 drochner #include <net/if_ether.h>
41 1.1 drochner #include <net/if_media.h>
42 1.1 drochner
43 1.1 drochner #ifdef INET
44 1.1 drochner #include <netinet/in.h>
45 1.1 drochner #include <netinet/if_inarp.h>
46 1.1 drochner #endif
47 1.1 drochner
48 1.1 drochner #include <machine/cpu.h>
49 1.1 drochner #include <machine/pte.h>
50 1.1 drochner
51 1.1 drochner #include <machine/autoconf.h>
52 1.1 drochner
53 1.1 drochner #include <dev/ic/lancereg.h>
54 1.1 drochner #include <dev/ic/lancevar.h>
55 1.1 drochner #include <dev/ic/am79900reg.h>
56 1.1 drochner #include <dev/ic/am79900var.h>
57 1.1 drochner
58 1.1 drochner #include <cesfic/cesfic/isr.h>
59 1.1 drochner
60 1.1 drochner int lematch __P((struct device *, struct cfdata *, void *));
61 1.1 drochner void leattach __P((struct device *, struct device *, void *));
62 1.1 drochner
63 1.3 thorpej CFATTACH_DECL(le, sizeof(struct am79900_softc),
64 1.3 thorpej lematch, leattach, NULL, NULL);
65 1.1 drochner
66 1.1 drochner int leintr __P((void *));
67 1.1 drochner
68 1.1 drochner void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
69 1.1 drochner u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
70 1.1 drochner
71 1.1 drochner static char *lebase, *lemembase;
72 1.1 drochner
73 1.1 drochner void
74 1.1 drochner lewrcsr(sc, port, val)
75 1.1 drochner struct lance_softc *sc;
76 1.1 drochner u_int16_t port, val;
77 1.1 drochner {
78 1.1 drochner *(volatile int *)(lebase + 4) = port;
79 1.1 drochner *(volatile int *)(lebase + 0) = val;
80 1.1 drochner }
81 1.1 drochner
82 1.1 drochner u_int16_t
83 1.1 drochner lerdcsr(sc, port)
84 1.1 drochner struct lance_softc *sc;
85 1.1 drochner u_int16_t port;
86 1.1 drochner {
87 1.1 drochner u_int16_t val;
88 1.1 drochner
89 1.1 drochner *(volatile int *)(lebase + 4) = port;
90 1.1 drochner val = *(volatile int *)(lebase + 0);
91 1.1 drochner return (val);
92 1.1 drochner }
93 1.1 drochner
94 1.1 drochner int
95 1.1 drochner lematch(parent, match, aux)
96 1.1 drochner struct device *parent;
97 1.1 drochner struct cfdata *match;
98 1.1 drochner void *aux;
99 1.1 drochner {
100 1.1 drochner return (1);
101 1.1 drochner }
102 1.1 drochner
103 1.1 drochner /*
104 1.1 drochner * Interface exists: make available by filling in network interface
105 1.1 drochner * record. System will initialize the interface when it is ready
106 1.1 drochner * to accept packets.
107 1.1 drochner */
108 1.1 drochner extern void sic_enable_int __P((int, int, int, int, int));
109 1.1 drochner static char hwa[6] = {0x00,0x80,0xa2,0x00,0x30,0x23};
110 1.1 drochner void
111 1.1 drochner leattach(parent, self, aux)
112 1.1 drochner struct device *parent, *self;
113 1.1 drochner void *aux;
114 1.1 drochner {
115 1.1 drochner int i;
116 1.1 drochner struct lance_softc *sc = (struct lance_softc *)self;
117 1.1 drochner
118 1.1 drochner mainbus_map(0x4c000000, 0x10000, 0, (void **)&lemembase);
119 1.1 drochner mainbus_map(0x48000000, 0x1000, 0, (void **)&lebase);
120 1.1 drochner
121 1.1 drochner sc->sc_mem = lemembase;
122 1.1 drochner sc->sc_conf3 = LE_C3_BSWP;
123 1.1 drochner sc->sc_addr = 0x4c000000;
124 1.1 drochner sc->sc_memsize = 64 * 1024;
125 1.1 drochner
126 1.1 drochner if (cesfic_getetheraddr(sc->sc_enaddr)) {
127 1.1 drochner /* fallback */
128 1.1 drochner for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
129 1.1 drochner sc->sc_enaddr[i] = hwa[i];
130 1.1 drochner }
131 1.1 drochner }
132 1.1 drochner
133 1.1 drochner sc->sc_copytodesc = lance_copytobuf_contig;
134 1.1 drochner sc->sc_copyfromdesc = lance_copyfrombuf_contig;
135 1.1 drochner sc->sc_copytobuf = lance_copytobuf_contig;
136 1.1 drochner sc->sc_copyfrombuf = lance_copyfrombuf_contig;
137 1.1 drochner sc->sc_zerobuf = lance_zerobuf_contig;
138 1.1 drochner
139 1.1 drochner sc->sc_rdcsr = lerdcsr;
140 1.1 drochner sc->sc_wrcsr = lewrcsr;
141 1.1 drochner sc->sc_hwinit = NULL;
142 1.1 drochner
143 1.1 drochner lewrcsr(sc, 4, 0x44);
144 1.1 drochner am79900_config((struct am79900_softc *)sc);
145 1.1 drochner
146 1.1 drochner /* Establish the interrupt handler. */
147 1.1 drochner (void) isrlink(leintr, sc, 3, ISRPRI_NET);
148 1.1 drochner sic_enable_int(17, 0, 1, 3, 0);
149 1.1 drochner }
150 1.1 drochner
151 1.1 drochner int
152 1.1 drochner leintr(arg)
153 1.1 drochner void *arg;
154 1.1 drochner {
155 1.1 drochner struct lance_softc *sc = arg;
156 1.1 drochner u_int16_t isr4;
157 1.1 drochner
158 1.1 drochner isr4 = lerdcsr(sc, 4);
159 1.1 drochner if (isr4 & 0x08) {
160 1.1 drochner lewrcsr(sc, 4, isr4);
161 1.1 drochner return (1);
162 1.1 drochner }
163 1.1 drochner
164 1.1 drochner return (am79900_intr(sc));
165 1.1 drochner }
166