depca_eisa.c revision 1.6 1 1.6 thorpej /* $NetBSD: depca_eisa.c,v 1.6 2004/08/23 05:50:02 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1 thorpej * must display the following acknowledgement:
20 1.1 thorpej * This product includes software developed by the NetBSD
21 1.1 thorpej * Foundation, Inc. and its contributors.
22 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1 thorpej * from this software without specific prior written permission.
25 1.1 thorpej *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * EISA bus front-end for the Digital DEPCA Ethernet controller.
41 1.1 thorpej */
42 1.2 lukem
43 1.2 lukem #include <sys/cdefs.h>
44 1.6 thorpej __KERNEL_RCSID(0, "$NetBSD: depca_eisa.c,v 1.6 2004/08/23 05:50:02 thorpej Exp $");
45 1.1 thorpej
46 1.1 thorpej #include "opt_inet.h"
47 1.1 thorpej #include "bpfilter.h"
48 1.1 thorpej
49 1.1 thorpej #include <sys/param.h>
50 1.1 thorpej #include <sys/systm.h>
51 1.1 thorpej #include <sys/mbuf.h>
52 1.1 thorpej #include <sys/syslog.h>
53 1.1 thorpej #include <sys/socket.h>
54 1.1 thorpej #include <sys/device.h>
55 1.1 thorpej
56 1.1 thorpej #include <net/if.h>
57 1.1 thorpej #include <net/if_media.h>
58 1.1 thorpej #include <net/if_ether.h>
59 1.1 thorpej
60 1.1 thorpej #ifdef INET
61 1.1 thorpej #include <netinet/in.h>
62 1.1 thorpej #include <netinet/if_inarp.h>
63 1.1 thorpej #endif
64 1.1 thorpej
65 1.1 thorpej #include <machine/bus.h>
66 1.1 thorpej #include <machine/intr.h>
67 1.1 thorpej
68 1.1 thorpej #include <dev/eisa/eisareg.h>
69 1.1 thorpej #include <dev/eisa/eisavar.h>
70 1.1 thorpej #include <dev/eisa/eisadevs.h>
71 1.1 thorpej
72 1.1 thorpej #include <dev/ic/lancereg.h>
73 1.1 thorpej #include <dev/ic/lancevar.h>
74 1.1 thorpej #include <dev/ic/am7990reg.h>
75 1.1 thorpej #include <dev/ic/am7990var.h>
76 1.1 thorpej #include <dev/ic/depcareg.h>
77 1.1 thorpej #include <dev/ic/depcavar.h>
78 1.1 thorpej
79 1.6 thorpej static int depca_eisa_match(struct device *, struct cfdata *, void *);
80 1.6 thorpej static void depca_eisa_attach(struct device *, struct device *, void *);
81 1.1 thorpej
82 1.1 thorpej struct depca_eisa_softc {
83 1.1 thorpej struct depca_softc sc_depca;
84 1.1 thorpej
85 1.1 thorpej eisa_chipset_tag_t sc_ec;
86 1.1 thorpej int sc_irq;
87 1.1 thorpej int sc_ist;
88 1.1 thorpej };
89 1.1 thorpej
90 1.4 thorpej CFATTACH_DECL(depca_eisa, sizeof(struct depca_eisa_softc),
91 1.5 thorpej depca_eisa_match, depca_eisa_attach, NULL, NULL);
92 1.1 thorpej
93 1.6 thorpej static void *depca_eisa_intr_establish(struct depca_softc *,
94 1.6 thorpej struct lance_softc *);
95 1.1 thorpej
96 1.6 thorpej static int
97 1.1 thorpej depca_eisa_match(struct device *parent, struct cfdata *match, void *aux)
98 1.1 thorpej {
99 1.1 thorpej struct eisa_attach_args *ea = aux;
100 1.1 thorpej
101 1.1 thorpej return (strcmp(ea->ea_idstring, "DEC4220") == 0);
102 1.1 thorpej }
103 1.1 thorpej
104 1.1 thorpej #define DEPCA_ECU_FUNC_NETINTR 0
105 1.1 thorpej #define DEPCA_ECU_FUNC_NETBUF 1
106 1.1 thorpej
107 1.6 thorpej static void
108 1.1 thorpej depca_eisa_attach(struct device *parent, struct device *self, void *aux)
109 1.1 thorpej {
110 1.1 thorpej struct depca_softc *sc = (void *) self;
111 1.1 thorpej struct depca_eisa_softc *esc = (void *) self;
112 1.1 thorpej struct eisa_attach_args *ea = aux;
113 1.1 thorpej struct eisa_cfg_mem ecm;
114 1.1 thorpej struct eisa_cfg_irq eci;
115 1.1 thorpej
116 1.1 thorpej printf(": DEC DE422 Ethernet\n");
117 1.1 thorpej
118 1.1 thorpej sc->sc_iot = ea->ea_iot;
119 1.1 thorpej sc->sc_memt = ea->ea_memt;
120 1.1 thorpej
121 1.1 thorpej esc->sc_ec = ea->ea_ec;
122 1.1 thorpej
123 1.1 thorpej sc->sc_intr_establish = depca_eisa_intr_establish;
124 1.1 thorpej
125 1.1 thorpej if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot,
126 1.1 thorpej DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) {
127 1.1 thorpej printf("%s: unable to find network buffer\n",
128 1.1 thorpej sc->sc_dev.dv_xname);
129 1.1 thorpej return;
130 1.1 thorpej }
131 1.1 thorpej
132 1.1 thorpej printf("%s: shared memory at 0x%lx-0x%lx\n", sc->sc_dev.dv_xname,
133 1.1 thorpej ecm.ecm_addr, ecm.ecm_addr + ecm.ecm_size - 1);
134 1.1 thorpej
135 1.1 thorpej sc->sc_memsize = ecm.ecm_size;
136 1.1 thorpej
137 1.1 thorpej if (bus_space_map(sc->sc_iot, EISA_SLOT_ADDR(ea->ea_slot) + 0xc00, 16,
138 1.1 thorpej 0, &sc->sc_ioh) != 0) {
139 1.1 thorpej printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
140 1.1 thorpej return;
141 1.1 thorpej }
142 1.1 thorpej if (bus_space_map(sc->sc_memt, ecm.ecm_addr, sc->sc_memsize,
143 1.1 thorpej 0, &sc->sc_memh) != 0) {
144 1.1 thorpej printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname);
145 1.1 thorpej return;
146 1.1 thorpej }
147 1.1 thorpej
148 1.1 thorpej if (eisa_conf_read_irq(ea->ea_ec, ea->ea_slot,
149 1.1 thorpej DEPCA_ECU_FUNC_NETINTR, 0, &eci) != 0) {
150 1.1 thorpej printf("%s: unable to determine IRQ\n",
151 1.1 thorpej sc->sc_dev.dv_xname);
152 1.1 thorpej return;
153 1.1 thorpej }
154 1.1 thorpej
155 1.1 thorpej esc->sc_irq = eci.eci_irq;
156 1.1 thorpej esc->sc_ist = eci.eci_ist;
157 1.1 thorpej
158 1.1 thorpej depca_attach(sc);
159 1.1 thorpej }
160 1.1 thorpej
161 1.6 thorpej static void *
162 1.1 thorpej depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
163 1.1 thorpej {
164 1.1 thorpej struct depca_eisa_softc *esc = (void *) parent;
165 1.1 thorpej eisa_intr_handle_t ih;
166 1.1 thorpej const char *intrstr;
167 1.1 thorpej void *rv;
168 1.1 thorpej
169 1.1 thorpej if (eisa_intr_map(esc->sc_ec, esc->sc_irq, &ih)) {
170 1.1 thorpej printf("%s: unable to map interrupt (%d)\n",
171 1.1 thorpej parent->sc_dev.dv_xname, esc->sc_irq);
172 1.1 thorpej return (NULL);
173 1.1 thorpej }
174 1.1 thorpej intrstr = eisa_intr_string(esc->sc_ec, ih);
175 1.1 thorpej rv = eisa_intr_establish(esc->sc_ec, ih, esc->sc_ist, IPL_NET,
176 1.1 thorpej (esc->sc_ist == IST_LEVEL) ? am7990_intr : depca_intredge, child);
177 1.1 thorpej if (rv == NULL) {
178 1.1 thorpej printf("%s: unable to establish interrupt",
179 1.1 thorpej parent->sc_dev.dv_xname);
180 1.1 thorpej if (intrstr != NULL)
181 1.1 thorpej printf(" at %s", intrstr);
182 1.1 thorpej printf("\n");
183 1.1 thorpej return (NULL);
184 1.1 thorpej }
185 1.1 thorpej if (intrstr != NULL)
186 1.1 thorpej printf("%s: interrupting at %s\n", parent->sc_dev.dv_xname,
187 1.1 thorpej intrstr);
188 1.1 thorpej
189 1.1 thorpej return (rv);
190 1.1 thorpej }
191