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