depca_eisa.c revision 1.11 1 1.11 tsutsui /* $NetBSD: depca_eisa.c,v 1.11 2008/04/04 12:25:07 tsutsui 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.11 tsutsui __KERNEL_RCSID(0, "$NetBSD: depca_eisa.c,v 1.11 2008/04/04 12:25:07 tsutsui 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.7 perry #include <netinet/in.h>
62 1.1 thorpej #include <netinet/if_inarp.h>
63 1.1 thorpej #endif
64 1.1 thorpej
65 1.10 ad #include <sys/bus.h>
66 1.10 ad #include <sys/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.11 tsutsui static int depca_eisa_match(device_t, cfdata_t, void *);
80 1.11 tsutsui static void depca_eisa_attach(device_t, device_t, 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.11 tsutsui CFATTACH_DECL_NEW(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.11 tsutsui depca_eisa_match(device_t parent, cfdata_t cf, 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.11 tsutsui depca_eisa_attach(device_t parent, device_t self, void *aux)
109 1.1 thorpej {
110 1.9 thorpej struct depca_eisa_softc *esc = device_private(self);
111 1.11 tsutsui struct depca_softc *sc = &esc->sc_depca;
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.11 tsutsui sc->sc_dev = self;
117 1.11 tsutsui aprint_error(": DEC DE422 Ethernet\n");
118 1.1 thorpej
119 1.1 thorpej sc->sc_iot = ea->ea_iot;
120 1.1 thorpej sc->sc_memt = ea->ea_memt;
121 1.1 thorpej
122 1.1 thorpej esc->sc_ec = ea->ea_ec;
123 1.1 thorpej
124 1.1 thorpej sc->sc_intr_establish = depca_eisa_intr_establish;
125 1.1 thorpej
126 1.1 thorpej if (eisa_conf_read_mem(ea->ea_ec, ea->ea_slot,
127 1.1 thorpej DEPCA_ECU_FUNC_NETBUF, 0, &ecm) != 0) {
128 1.11 tsutsui aprint_error_dev(self, "unable to find network buffer\n");
129 1.1 thorpej return;
130 1.1 thorpej }
131 1.1 thorpej
132 1.11 tsutsui aprint_normal_dev(self, "shared memory at 0x%lx-0x%lx\n",
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.11 tsutsui aprint_error_dev(self, "unable to map i/o space\n");
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.11 tsutsui aprint_error_dev(self, "unable to map memory space\n");
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.11 tsutsui aprint_error_dev(self, "unable to determine IRQ\n");
151 1.1 thorpej return;
152 1.1 thorpej }
153 1.1 thorpej
154 1.1 thorpej esc->sc_irq = eci.eci_irq;
155 1.1 thorpej esc->sc_ist = eci.eci_ist;
156 1.1 thorpej
157 1.1 thorpej depca_attach(sc);
158 1.1 thorpej }
159 1.1 thorpej
160 1.6 thorpej static void *
161 1.1 thorpej depca_eisa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
162 1.1 thorpej {
163 1.11 tsutsui struct depca_eisa_softc *esc = (struct depca_eisa_softc *)parent;
164 1.1 thorpej eisa_intr_handle_t ih;
165 1.1 thorpej const char *intrstr;
166 1.1 thorpej void *rv;
167 1.1 thorpej
168 1.1 thorpej if (eisa_intr_map(esc->sc_ec, esc->sc_irq, &ih)) {
169 1.11 tsutsui aprint_error_dev(parent->sc_dev,
170 1.11 tsutsui "unable to map interrupt (%d)\n", esc->sc_irq);
171 1.1 thorpej return (NULL);
172 1.1 thorpej }
173 1.1 thorpej intrstr = eisa_intr_string(esc->sc_ec, ih);
174 1.1 thorpej rv = eisa_intr_establish(esc->sc_ec, ih, esc->sc_ist, IPL_NET,
175 1.1 thorpej (esc->sc_ist == IST_LEVEL) ? am7990_intr : depca_intredge, child);
176 1.1 thorpej if (rv == NULL) {
177 1.11 tsutsui aprint_error_dev(parent->sc_dev,
178 1.11 tsutsui "unable to establish interrupt");
179 1.1 thorpej if (intrstr != NULL)
180 1.11 tsutsui aprint_error(" at %s", intrstr);
181 1.11 tsutsui aprint_error("\n");
182 1.1 thorpej return (NULL);
183 1.1 thorpej }
184 1.1 thorpej if (intrstr != NULL)
185 1.11 tsutsui aprint_normal_dev(parent->sc_dev, "interrupting at %s\n",
186 1.1 thorpej intrstr);
187 1.1 thorpej
188 1.1 thorpej return (rv);
189 1.1 thorpej }
190