if_le_obio.c revision 1.5 1 /* $NetBSD: if_le_obio.c,v 1.5 1998/08/29 20:49:37 pk Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
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 NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include "opt_inet.h"
41 #include "bpfilter.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/malloc.h>
47 #include <sys/socket.h>
48
49 #include <net/if.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
52
53 #include <machine/autoconf.h>
54 #include <machine/cpu.h>
55
56 #include <dev/ic/lancereg.h>
57 #include <dev/ic/lancevar.h>
58 #include <dev/ic/am7990reg.h>
59 #include <dev/ic/am7990var.h>
60
61 /*
62 * LANCE registers.
63 */
64 #define LEREG1_RDP 0 /* Register Data port */
65 #define LEREG1_RAP 2 /* Register Address port */
66
67 struct le_softc {
68 struct am7990_softc sc_am7990; /* glue to MI code */
69 bus_space_tag_t sc_bustag;
70 bus_dma_tag_t sc_dmatag;
71 bus_space_handle_t sc_reg; /* LANCE registers */
72 };
73
74 #define MEMSIZE 0x4000 /* LANCE memory size */
75
76 int lematch_obio __P((struct device *, struct cfdata *, void *));
77 void leattach_obio __P((struct device *, struct device *, void *));
78
79 /*
80 * Media types supported.
81 */
82 static int lemedia[] = {
83 IFM_ETHER|IFM_10_T,
84 };
85 #define NLEMEDIA (sizeof(lemedia) / sizeof(lemedia[0]))
86
87 struct cfattach le_obio_ca = {
88 sizeof(struct le_softc), lematch_obio, leattach_obio
89 };
90
91 extern struct cfdriver le_cd;
92
93 #if defined(_KERNEL) && !defined(_LKM)
94 #include "opt_ddb.h"
95 #endif
96
97 #ifdef DDB
98 #define integrate
99 #define hide
100 #else
101 #define integrate static __inline
102 #define hide static
103 #endif
104
105 static void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
106 static u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
107
108 static void
109 lewrcsr(sc, port, val)
110 struct lance_softc *sc;
111 u_int16_t port, val;
112 {
113 struct le_softc *lesc = (struct le_softc *)sc;
114
115 bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
116 bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP, val);
117 }
118
119 static u_int16_t
120 lerdcsr(sc, port)
121 struct lance_softc *sc;
122 u_int16_t port;
123 {
124 struct le_softc *lesc = (struct le_softc *)sc;
125
126 bus_space_write_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RAP, port);
127 return (bus_space_read_2(lesc->sc_bustag, lesc->sc_reg, LEREG1_RDP));
128 }
129
130 int
131 lematch_obio(parent, cf, aux)
132 struct device *parent;
133 struct cfdata *cf;
134 void *aux;
135 {
136 union obio_attach_args *uoba = aux;
137 struct obio4_attach_args *oba;
138
139 if (uoba->uoba_isobio4 == 0)
140 return (0);
141
142 oba = &uoba->uoba_oba4;
143 return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
144 2, /* probe size */
145 0, /* offset */
146 0, /* flags */
147 NULL, NULL));
148 }
149
150 void
151 leattach_obio(parent, self, aux)
152 struct device *parent, *self;
153 void *aux;
154 {
155 union obio_attach_args *uoba = aux;
156 struct obio4_attach_args *oba = &uoba->uoba_oba4;
157 struct le_softc *lesc = (struct le_softc *)self;
158 struct lance_softc *sc = &lesc->sc_am7990.lsc;
159 bus_dma_segment_t seg;
160 int rseg;
161 /* XXX the following declarations should be elsewhere */
162 extern void myetheraddr __P((u_char *));
163
164 lesc->sc_bustag = oba->oba_bustag;
165 lesc->sc_dmatag = oba->oba_dmatag;
166
167 if (obio_bus_map(oba->oba_bustag, oba->oba_paddr,
168 0, 2 * sizeof(u_int16_t),
169 0, 0,
170 &lesc->sc_reg) != 0) {
171 printf("%s @ obio: cannot map registers\n", self->dv_xname);
172 return;
173 }
174
175 if (oba->oba_bp != NULL &&
176 strcmp(oba->oba_bp->name, le_cd.cd_name) == 0 &&
177 sc->sc_dev.dv_unit == oba->oba_bp->val[1])
178 oba->oba_bp->dev = &sc->sc_dev;
179
180
181 if (bus_dmamem_alloc(lesc->sc_dmatag, MEMSIZE, NBPG, 0,
182 &seg, 1, &rseg,
183 BUS_DMA_NOWAIT | BUS_DMA_24BIT) != 0) {
184 printf("%s @ obio: DMA memory allocation error\n",
185 self->dv_xname);
186 return;
187 }
188 if (bus_dmamem_map(lesc->sc_dmatag, &seg, rseg, MEMSIZE,
189 (caddr_t *)&sc->sc_mem,
190 BUS_DMA_NOWAIT|BUS_DMA_COHERENT) != 0) {
191 printf("%s @ obio: DMA memory map error\n", self->dv_xname);
192 bus_dmamem_free(lesc->sc_dmatag, &seg, rseg);
193 return;
194 }
195 sc->sc_addr = seg.ds_addr & 0xffffff;
196 sc->sc_memsize = MEMSIZE;
197 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
198
199 sc->sc_supmedia = lemedia;
200 sc->sc_nsupmedia = NLEMEDIA;
201 sc->sc_defaultmedia = lemedia[0];
202
203 myetheraddr(sc->sc_enaddr);
204
205 sc->sc_copytodesc = lance_copytobuf_contig;
206 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
207 sc->sc_copytobuf = lance_copytobuf_contig;
208 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
209 sc->sc_zerobuf = lance_zerobuf_contig;
210
211 sc->sc_rdcsr = lerdcsr;
212 sc->sc_wrcsr = lewrcsr;
213
214 am7990_config(&lesc->sc_am7990);
215
216 /* Install interrupt */
217 (void)bus_intr_establish(lesc->sc_bustag, oba->oba_pri, 0,
218 am7990_intr, sc);
219 }
220