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